example-wordpress-ci.yml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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@5c1a813d8ad21adf845d221c59d17ce9406d5e53 # v1.41.0
  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@5c1a813d8ad21adf845d221c59d17ce9406d5e53 # v1.41.0
  29. permissions:
  30. contents: read
  31. pull-requests: read
  32. id-token: write
  33. php:
  34. # Repository-specific: lint, static analysis, tests and the dependency audit. No secrets, no deploy.
  35. runs-on: ubuntu-latest
  36. permissions:
  37. contents: read
  38. container: php:8.4-cli
  39. steps:
  40. - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
  41. with:
  42. persist-credentials: false
  43. - name: Install Composer from the image's package source (pin it in your own image)
  44. run: php -v
  45. - name: Lint every PHP file
  46. run: find . -name '*.php' -not -path './vendor/*' -print0 | xargs -0 -n1 php -l
  47. # With Composer installed: composer validate --strict; composer install --no-scripts;
  48. # composer audit; vendor/bin/phpstan analyse; vendor/bin/phpcs; vendor/bin/phpunit.
  49. policy:
  50. # The reviewer's rules as a script. Its own job: it needs Python, which the php image lacks.
  51. runs-on: ubuntu-latest
  52. permissions:
  53. contents: read
  54. steps:
  55. - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
  56. with:
  57. persist-credentials: false
  58. - name: Reviewer's rules for this repository
  59. run: python3 -I labs/wordpress-at-scale/ci/ci_policy_check.py --site site --workflow .github/workflows/wordpress-ci.yml
  60. build:
  61. needs: [php, policy]
  62. runs-on: ubuntu-latest
  63. permissions:
  64. contents: read
  65. steps:
  66. - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
  67. with:
  68. persist-credentials: false
  69. # ILLUSTRATION, not a deployable release: the sample site has no composer.lock and uses invented
  70. # packages, so the install line is commented out. In a real repository commit composer.lock and
  71. # run it; without it the archive would hold only source and config files.
  72. - name: Build one release artifact from the lock file
  73. run: |
  74. # composer install --no-dev --prefer-dist --no-scripts --optimize-autoloader
  75. tar -czf release.tar.gz --exclude=.git site
  76. sha256sum release.tar.gz > release.tar.gz.sha256
  77. - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
  78. with:
  79. name: release
  80. path: release.tar.gz*
  81. deploy-staging:
  82. # Only from main. The credential arrives by OIDC or a secrets manager at this step only.
  83. if: github.ref == 'refs/heads/main'
  84. needs: [security, scripts, php, policy, build]
  85. runs-on: ubuntu-latest
  86. environment: staging
  87. permissions:
  88. contents: read
  89. id-token: write
  90. steps:
  91. - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
  92. with:
  93. name: release
  94. - name: Verify the checksum, then deploy as a NEW release directory (not in place)
  95. run: |
  96. sha256sum -c release.tar.gz.sha256
  97. echo "deploy: copy to releases/<id>, run wp-cli database and cache steps, switch 'current'"
  98. - name: Smoke test
  99. run: echo "curl the staging URL for 200 and the expected marker text"
  100. promote-production:
  101. # The environment has required reviewers, so a person approves before this job starts.
  102. if: github.ref == 'refs/heads/main'
  103. needs: [deploy-staging]
  104. runs-on: ubuntu-latest
  105. environment: production
  106. permissions:
  107. contents: read
  108. id-token: write
  109. steps:
  110. - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
  111. with:
  112. name: release
  113. - name: Promote the SAME artifact, then smoke test; on failure switch 'current' back
  114. run: |
  115. echo "promote: same checksum as staging, switch 'current', smoke test, rollback if it fails"
  116. ci-green:
  117. name: CI green
  118. if: ${{ always() }}
  119. needs: [security, scripts, php, policy, build]
  120. runs-on: ubuntu-latest
  121. permissions: {}
  122. steps:
  123. - name: Fail unless every needed job succeeded
  124. env:
  125. RESULTS: ${{ join(needs.*.result, ' ') }}
  126. run: |
  127. for r in $RESULTS; do
  128. [ "$r" = "success" ] || { echo "a needed job finished as: $r"; exit 1; }
  129. done