example-wordpress-ci.yml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. # SPDX-License-Identifier: Apache-2.0
  2. # EXAMPLE ONLY. This file lives under labs/, so GitHub does not run it. Copy it to
  3. # .github/workflows/ in your own repository to use it. It shows the shape of a pipeline for
  4. # a WordPress-as-code repository, and ci_policy_check.py holds it to the reviewer's rules.
  5. #
  6. # git-your-ship-together (GYST) has no PHP or WordPress workflow today (its README was read
  7. # 2026-10-22), so the php job below is local. By this project's rule, a generic PHP gate
  8. # belongs in GYST first and would then be called from here.
  9. name: WordPress site CI
  10. on:
  11. pull_request:
  12. push:
  13. branches: [main]
  14. permissions: {}
  15. jobs:
  16. security:
  17. # Secret scanning, CodeQL for the workflows, dependency review. Pin = commit; comment = version.
  18. 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)
  19. permissions:
  20. contents: read
  21. security-events: write
  22. pull-requests: write
  23. id-token: write
  24. with:
  25. codeql-languages: actions
  26. scripts:
  27. # shellcheck and shfmt over the deploy scripts.
  28. 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)
  29. permissions:
  30. contents: read
  31. id-token: write
  32. php:
  33. # Repository-specific: lint, static analysis, tests and the dependency audit. No secrets, no deploy.
  34. runs-on: ubuntu-latest
  35. permissions:
  36. contents: read
  37. container: php:8.4-cli
  38. steps:
  39. - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
  40. with:
  41. persist-credentials: false
  42. - name: Install Composer from the image's package source (pin it in your own image)
  43. run: php -v
  44. - name: Lint every PHP file
  45. run: find . -name '*.php' -not -path './vendor/*' -print0 | xargs -0 -n1 php -l
  46. # With Composer installed: composer validate --strict; composer install --no-scripts;
  47. # composer audit; vendor/bin/phpstan analyse; vendor/bin/phpcs; vendor/bin/phpunit.
  48. policy:
  49. # The reviewer's rules as a script. Its own job: it needs Python, which the php image lacks.
  50. runs-on: ubuntu-latest
  51. permissions:
  52. contents: read
  53. steps:
  54. - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
  55. with:
  56. persist-credentials: false
  57. - name: Reviewer's rules for this repository
  58. run: python3 -I labs/wordpress-at-scale/ci/ci_policy_check.py --site site --workflow .github/workflows/wordpress-ci.yml
  59. build:
  60. needs: [php, policy]
  61. runs-on: ubuntu-latest
  62. permissions:
  63. contents: read
  64. steps:
  65. - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
  66. with:
  67. persist-credentials: false
  68. # ILLUSTRATION, not a deployable release: the sample site has no composer.lock and uses invented
  69. # packages, so the install line is commented out. In a real repository commit composer.lock and
  70. # run it; without it the archive would hold only source and config files.
  71. - name: Build one release artifact from the lock file
  72. run: |
  73. # composer install --no-dev --prefer-dist --no-scripts --optimize-autoloader
  74. tar -czf release.tar.gz --exclude=.git site
  75. sha256sum release.tar.gz > release.tar.gz.sha256
  76. - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
  77. with:
  78. name: release
  79. path: release.tar.gz*
  80. deploy-staging:
  81. # Only from main. The credential arrives by OIDC or a secrets manager at this step only.
  82. if: github.ref == 'refs/heads/main'
  83. needs: [security, scripts, php, policy, build]
  84. runs-on: ubuntu-latest
  85. environment: staging
  86. permissions:
  87. contents: read
  88. id-token: write
  89. steps:
  90. - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
  91. with:
  92. name: release
  93. - name: Verify the checksum, then deploy as a NEW release directory (not in place)
  94. run: |
  95. sha256sum -c release.tar.gz.sha256
  96. echo "deploy: copy to releases/<id>, run wp-cli database and cache steps, switch 'current'"
  97. - name: Smoke test
  98. run: echo "curl the staging URL for 200 and the expected marker text"
  99. promote-production:
  100. # The environment has required reviewers, so a person approves before this job starts.
  101. if: github.ref == 'refs/heads/main'
  102. needs: [deploy-staging]
  103. runs-on: ubuntu-latest
  104. environment: production
  105. permissions:
  106. contents: read
  107. id-token: write
  108. steps:
  109. - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
  110. with:
  111. name: release
  112. - name: Promote the SAME artifact, then smoke test; on failure switch 'current' back
  113. run: echo "promote: same checksum as staging, switch 'current', smoke test, rollback if it fails"
  114. ci-green:
  115. name: CI green
  116. if: ${{ always() }}
  117. needs: [security, scripts, php, policy, build]
  118. runs-on: ubuntu-latest
  119. permissions: {}
  120. steps:
  121. - name: Fail unless every needed job succeeded
  122. env:
  123. RESULTS: ${{ join(needs.*.result, ' ') }}
  124. run: |
  125. for r in $RESULTS; do
  126. [ "$r" = "success" ] || { echo "a needed job finished as: $r"; exit 1; }
  127. done