|
1 | 1 | name: hCaptcha CI |
2 | 2 | on: [ push, pull_request ] |
| 3 | + |
| 4 | +# 1. SECURITY: Default to read-only permissions for the workflow |
| 5 | +permissions: |
| 6 | + actions: read |
| 7 | + contents: read |
| 8 | + |
3 | 9 | concurrency: |
4 | | - group: ${{ github.ref }} |
| 10 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
5 | 11 | cancel-in-progress: true |
6 | 12 |
|
7 | 13 | jobs: |
|
25 | 31 | WP_ADMIN_PASSWORD: admin |
26 | 32 | |
27 | 33 |
|
| 34 | + if: | |
| 35 | + github.event_name == 'push' || |
| 36 | + (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true) |
| 37 | +
|
28 | 38 | runs-on: ${{ matrix.os }} |
29 | 39 |
|
30 | 40 | name: PHP ${{ matrix.php-version }} on ${{ matrix.os }} |
|
35 | 45 | with: |
36 | 46 | path: ${{ env.wp-plugin-directory }} |
37 | 47 |
|
38 | | - - name: Update changelog |
39 | | - if: ${{ matrix.php-version == '8.4' }} |
40 | | - working-directory: ${{ env.wp-plugin-directory }} |
41 | | - run: .github/scripts/update-changelog.sh |
| 48 | + # MOVED: The "Update changelog" step has been moved to the specific job below |
| 49 | + # to prevent giving 'contents: write' permissions to this testing job. |
42 | 50 |
|
43 | 51 | - name: Setup PHP |
44 | 52 | uses: hCaptcha/setup-php@42a9487ddd45db247decea2acf7de871a8178226 |
|
67 | 75 | yarn lint |
68 | 76 |
|
69 | 77 | - name: Install WP CLI |
| 78 | + # Security: 1. Ensure wp-cli integrity via checksum. |
70 | 79 | run: | |
71 | | - curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar |
| 80 | + WPCLI_VERSION=2.12.0 |
| 81 | + curl -fsSL -o wp-cli.phar "https://github.com/wp-cli/wp-cli/releases/download/v${WPCLI_VERSION}/wp-cli-${WPCLI_VERSION}.phar" |
| 82 | + curl -fsSL -o wp-cli.phar.sha256 "https://github.com/wp-cli/wp-cli/releases/download/v${WPCLI_VERSION}/wp-cli-${WPCLI_VERSION}.phar.sha256" |
| 83 | + echo "$(cat wp-cli.phar.sha256) wp-cli.phar" | sha256sum -c - |
72 | 84 | chmod +x wp-cli.phar |
73 | 85 | mkdir -p wp-cli |
74 | 86 | sudo mv wp-cli.phar wp-cli/wp |
@@ -115,3 +127,30 @@ jobs: |
115 | 127 | if: ${{ matrix.php-version == '8.4' }} |
116 | 128 | working-directory: ${{ env.wp-plugin-directory }} |
117 | 129 | run: yarn jest |
| 130 | + |
| 131 | + update_changelog: |
| 132 | + name: Update Changelog |
| 133 | + runs-on: ubuntu-latest |
| 134 | + |
| 135 | + # 2. SECURITY: Only run on PUSH, never on Pull Requests |
| 136 | + if: github.event_name == 'push' |
| 137 | + needs: cs_and_tests |
| 138 | + |
| 139 | + # 3. SECURITY: Grant write permission ONLY to this job |
| 140 | + permissions: |
| 141 | + contents: write |
| 142 | + |
| 143 | + env: |
| 144 | + wp-plugin-directory: wordpress/wp-content/plugins/hcaptcha-wordpress-plugin |
| 145 | + |
| 146 | + steps: |
| 147 | + - name: Checkout code |
| 148 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 149 | + with: |
| 150 | + path: ${{ env.wp-plugin-directory }} |
| 151 | + # Check out the branch ref to ensure we can push back to it |
| 152 | + ref: ${{ github.ref }} |
| 153 | + |
| 154 | + - name: Update changelog |
| 155 | + working-directory: ${{ env.wp-plugin-directory }} |
| 156 | + run: .github/scripts/update-changelog.sh |
0 commit comments