|
| 1 | +name: Deploy static content to GH Pages |
| 2 | + |
| 3 | +on: |
| 4 | + # Runs on pushes targeting the default branch |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - 'stable' |
| 8 | + # Do a dry-run (update, no deploy) for PRs. |
| 9 | + pull_request: |
| 10 | + # Allow running this workflow manually from the Actions tab. |
| 11 | + workflow_dispatch: |
| 12 | + # Allow this workflow to be triggered from outside. |
| 13 | + repository_dispatch: |
| 14 | + types: |
| 15 | + - 'phpcs-release' |
| 16 | + |
| 17 | +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages |
| 18 | +permissions: |
| 19 | + contents: write |
| 20 | + pages: write |
| 21 | + id-token: write |
| 22 | + |
| 23 | +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. |
| 24 | +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. |
| 25 | +concurrency: |
| 26 | + group: "pages" |
| 27 | + cancel-in-progress: false |
| 28 | + |
| 29 | +jobs: |
| 30 | + update: |
| 31 | + name: "Update XSD files" |
| 32 | + |
| 33 | + # Don't run on forks. |
| 34 | + if: github.repository == 'PHPCSStandards/schema.phpcodesniffer.com' |
| 35 | + |
| 36 | + runs-on: ubuntu-latest |
| 37 | + steps: |
| 38 | + # By default use the `stable` branch. |
| 39 | + # For testing changes to the workflow or the scripts, use the PR branch |
| 40 | + # to have access to the latest version of the workflow/scripts. |
| 41 | + - name: Determine branch to use |
| 42 | + id: base_branch |
| 43 | + env: |
| 44 | + REF: ${{ github.ref }} |
| 45 | + run: | |
| 46 | + if [ "${{ github.event_name }}" == "pull_request" ]; then |
| 47 | + echo "BRANCH=$REF" >> "$GITHUB_OUTPUT" |
| 48 | + else |
| 49 | + echo 'BRANCH=stable' >> "$GITHUB_OUTPUT" |
| 50 | + fi |
| 51 | +
|
| 52 | + - name: Checkout code |
| 53 | + uses: actions/checkout@v4 |
| 54 | + with: |
| 55 | + ref: ${{ steps.base_branch.outputs.BRANCH }} |
| 56 | + |
| 57 | + - name: Install PHP |
| 58 | + uses: shivammathur/setup-php@v2 |
| 59 | + with: |
| 60 | + php-version: '8.4' |
| 61 | + ini-values: error_reporting=-1, display_errors=On, log_errors_max_len=0 |
| 62 | + coverage: none |
| 63 | + |
| 64 | + - name: Get a list of the last 50 PHP_CodeSniffer releases |
| 65 | + env: |
| 66 | + GH_TOKEN: ${{ github.token }} |
| 67 | + run: > |
| 68 | + gh release list --repo PHPCSStandards/PHP_CodeSniffer --limit=50 --order desc |
| 69 | + --json tagName,isPrerelease,isLatest,isDraft > releases.json |
| 70 | +
|
| 71 | + - name: Update XSD files |
| 72 | + run: php ./src/update-site.php |
| 73 | + |
| 74 | + - name: Delete releases.json |
| 75 | + run: rm releases.json |
| 76 | + |
| 77 | + - name: "Debug info: check git status" |
| 78 | + run: git status -b -v -u |
| 79 | + |
| 80 | + # Commit all changed files back to the repository |
| 81 | + - name: Commit updated files |
| 82 | + uses: stefanzweifel/git-auto-commit-action@v5 |
| 83 | + with: |
| 84 | + commit_message: "Update XSD files" |
| 85 | + add_options: '-A' |
| 86 | + |
| 87 | + - name: Check GitHub Pages status |
| 88 | + uses: crazy-max/ghaction-github-status@v4 |
| 89 | + with: |
| 90 | + pages_threshold: major_outage |
| 91 | + |
| 92 | + - name: Setup Pages |
| 93 | + uses: actions/configure-pages@v5 |
| 94 | + |
| 95 | + - name: Upload static files as artifact |
| 96 | + uses: actions/upload-pages-artifact@v3 |
| 97 | + with: |
| 98 | + # Upload _site directory only. |
| 99 | + path: _site/ |
| 100 | + |
| 101 | + deploy: |
| 102 | + needs: update |
| 103 | + # Don't run on forks. |
| 104 | + if: github.repository == 'PHPCSStandards/schema.phpcodesniffer.com' && github.event_name != 'pull_request' && needs.update.result == 'success' |
| 105 | + |
| 106 | + name: "Deploy the website" |
| 107 | + runs-on: ubuntu-latest |
| 108 | + |
| 109 | + environment: |
| 110 | + name: github-pages |
| 111 | + url: ${{ steps.deployment.outputs.page_url }} |
| 112 | + |
| 113 | + steps: |
| 114 | + - name: Deploy to GitHub Pages |
| 115 | + id: deployment |
| 116 | + uses: actions/deploy-pages@v4 |
0 commit comments