| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- # SPDX-License-Identifier: Apache-2.0
- # EXAMPLE ONLY. This file lives under labs/, so GitHub does not run it. Copy it to
- # .github/workflows/ in your own repository to use it. It shows the shape of a pipeline for
- # a WordPress-as-code repository, and ci_policy_check.py holds it to the reviewer's rules.
- #
- # git-your-ship-together (GYST) has no PHP or WordPress workflow today (its README was read
- # 2026-10-22), so the php job below is local. By this project's rule, a generic PHP gate
- # belongs in GYST first and would then be called from here.
- name: WordPress site CI
- on:
- pull_request:
- push:
- branches: [main]
- permissions: {}
- jobs:
- security:
- # Secret scanning, CodeQL for the workflows, dependency review. Pin = commit; comment = version.
- uses: ChiefGyk3D/git-your-ship-together/.github/workflows/security.yml@9d6825dd4e0e4d524fca3733f416437bbd7851e1 # v1.31.0 # git-your-ship-together main at PR 151 (untagged; next release)
- permissions:
- contents: read
- security-events: write
- pull-requests: write
- id-token: write
- with:
- codeql-languages: actions
- scripts:
- # shellcheck and shfmt over the deploy scripts.
- uses: ChiefGyk3D/git-your-ship-together/.github/workflows/bash-ci.yml@9d6825dd4e0e4d524fca3733f416437bbd7851e1 # v1.31.0 # git-your-ship-together main at PR 151 (untagged; next release)
- permissions:
- contents: read
- id-token: write
- php:
- # Repository-specific: lint, static analysis, tests and the dependency audit. No secrets, no deploy.
- runs-on: ubuntu-latest
- permissions:
- contents: read
- container: php:8.4-cli
- steps:
- - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- with:
- persist-credentials: false
- - name: Install Composer from the image's package source (pin it in your own image)
- run: php -v
- - name: Lint every PHP file
- run: find . -name '*.php' -not -path './vendor/*' -print0 | xargs -0 -n1 php -l
- # With Composer installed: composer validate --strict; composer install --no-scripts;
- # composer audit; vendor/bin/phpstan analyse; vendor/bin/phpcs; vendor/bin/phpunit.
- policy:
- # The reviewer's rules as a script. Its own job: it needs Python, which the php image lacks.
- runs-on: ubuntu-latest
- permissions:
- contents: read
- steps:
- - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- with:
- persist-credentials: false
- - name: Reviewer's rules for this repository
- run: python3 -I labs/wordpress-at-scale/ci/ci_policy_check.py --site site --workflow .github/workflows/wordpress-ci.yml
- build:
- needs: [php, policy]
- runs-on: ubuntu-latest
- permissions:
- contents: read
- steps:
- - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- with:
- persist-credentials: false
- # ILLUSTRATION, not a deployable release: the sample site has no composer.lock and uses invented
- # packages, so the install line is commented out. In a real repository commit composer.lock and
- # run it; without it the archive would hold only source and config files.
- - name: Build one release artifact from the lock file
- run: |
- # composer install --no-dev --prefer-dist --no-scripts --optimize-autoloader
- tar -czf release.tar.gz --exclude=.git site
- sha256sum release.tar.gz > release.tar.gz.sha256
- - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
- with:
- name: release
- path: release.tar.gz*
- deploy-staging:
- # Only from main. The credential arrives by OIDC or a secrets manager at this step only.
- if: github.ref == 'refs/heads/main'
- needs: [security, scripts, php, policy, build]
- runs-on: ubuntu-latest
- environment: staging
- permissions:
- contents: read
- id-token: write
- steps:
- - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
- with:
- name: release
- - name: Verify the checksum, then deploy as a NEW release directory (not in place)
- run: |
- sha256sum -c release.tar.gz.sha256
- echo "deploy: copy to releases/<id>, run wp-cli database and cache steps, switch 'current'"
- - name: Smoke test
- run: echo "curl the staging URL for 200 and the expected marker text"
- promote-production:
- # The environment has required reviewers, so a person approves before this job starts.
- if: github.ref == 'refs/heads/main'
- needs: [deploy-staging]
- runs-on: ubuntu-latest
- environment: production
- permissions:
- contents: read
- id-token: write
- steps:
- - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
- with:
- name: release
- - name: Promote the SAME artifact, then smoke test; on failure switch 'current' back
- run: echo "promote: same checksum as staging, switch 'current', smoke test, rollback if it fails"
- ci-green:
- name: CI green
- if: ${{ always() }}
- needs: [security, scripts, php, policy, build]
- runs-on: ubuntu-latest
- permissions: {}
- steps:
- - name: Fail unless every needed job succeeded
- env:
- RESULTS: ${{ join(needs.*.result, ' ') }}
- run: |
- for r in $RESULTS; do
- [ "$r" = "success" ] || { echo "a needed job finished as: $r"; exit 1; }
- done
|