-
Notifications
You must be signed in to change notification settings - Fork 40
Publish only from approved release PRs #1384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
44b93f3
cee7af2
e451705
675aa3b
f3fe037
447975d
22aad86
1c5297a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,164 @@ | ||
| name: Sync readme/assets to WordPress.org | ||
| name: Sync approved readme/assets PR to WordPress.org | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| paths: | ||
| - readme.txt | ||
| pull_request_target: | ||
| branches: [master] | ||
| types: [closed] | ||
| workflow_dispatch: | ||
| inputs: | ||
| pull_request_number: | ||
| description: Merged readme/assets PR number to retry. | ||
| required: true | ||
| type: number | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: read | ||
|
|
||
| concurrency: | ||
| group: popup-maker-publication | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| authorize: | ||
| name: Authorize approved readme/assets PR | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| should_sync: ${{ steps.authorize.outputs.should_sync }} | ||
| merge_sha: ${{ steps.authorize.outputs.merge_sha }} | ||
| pull_request_number: ${{ steps.authorize.outputs.pull_request_number }} | ||
|
|
||
| steps: | ||
| - name: Verify merged PR, approval, and exact file scope | ||
| id: authorize | ||
| uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8 | ||
| with: | ||
| script: | | ||
| const owner = context.repo.owner; | ||
| const repo = context.repo.repo; | ||
| const number = context.eventName === 'workflow_dispatch' | ||
| ? Number('${{ inputs.pull_request_number }}') | ||
| : context.payload.pull_request.number; | ||
| const { data: pull } = await github.rest.pulls.get({ owner, repo, pull_number: number }); | ||
|
|
||
| core.setOutput('should_sync', 'false'); | ||
| core.setOutput('pull_request_number', String(number)); | ||
|
|
||
| if (!pull.merged || pull.base.ref !== 'master') { | ||
| core.info('PR is not merged into master; nothing will be synced.'); | ||
| return; | ||
| } | ||
| if (pull.head.repo?.full_name !== `${owner}/${repo}`) { | ||
| core.setFailed('Publication PRs must come from this repository.'); | ||
| return; | ||
| } | ||
|
|
||
| const reviews = await github.paginate(github.rest.pulls.listReviews, { | ||
| owner, | ||
| repo, | ||
| pull_number: number, | ||
| per_page: 100, | ||
| }); | ||
| const latestByReviewer = new Map(); | ||
| for (const review of reviews) { | ||
| if ( | ||
| review.user?.login && | ||
| ['APPROVED', 'CHANGES_REQUESTED', 'DISMISSED'].includes(review.state) | ||
| ) { | ||
| latestByReviewer.set(review.user.login, review.state); | ||
| } | ||
| } | ||
| const approvedReviewers = [...latestByReviewer.entries()] | ||
| .filter(([, state]) => state === 'APPROVED') | ||
| .map(([login]) => login); | ||
| let authorizedApproval = false; | ||
| for (const username of approvedReviewers) { | ||
| const { data: permission } = await github.rest.repos.getCollaboratorPermissionLevel({ | ||
| owner, | ||
| repo, | ||
| username, | ||
| }); | ||
| if (['admin', 'maintain', 'write'].includes(permission.permission)) { | ||
| authorizedApproval = true; | ||
| break; | ||
| } | ||
| } | ||
| if (!authorizedApproval && pull.merged_by?.login) { | ||
| const { data: mergerPermission } = await github.rest.repos.getCollaboratorPermissionLevel({ | ||
| owner, | ||
| repo, | ||
| username: pull.merged_by.login, | ||
| }); | ||
| authorizedApproval = ['admin', 'maintain', 'write'].includes( | ||
| mergerPermission.permission | ||
| ); | ||
| } | ||
| if (!authorizedApproval) { | ||
| core.setFailed('The PR was not approved or merged by an authorized maintainer.'); | ||
| return; | ||
| } | ||
|
|
||
| const files = await github.paginate(github.rest.pulls.listFiles, { | ||
| owner, | ||
| repo, | ||
| pull_number: number, | ||
| per_page: 100, | ||
| }); | ||
| const isAllowedPath = (filename) => | ||
| filename === 'readme.txt' || filename.startsWith('.wordpress-org/'); | ||
| const removesReadme = files.some((file) => | ||
| (file.filename === 'readme.txt' && file.status === 'removed') || | ||
| (file.status === 'renamed' && file.previous_filename === 'readme.txt') | ||
| ); | ||
| const allowed = files.length > 0 && !removesReadme && files.every((file) => | ||
| isAllowedPath(file.filename) && | ||
| (file.status !== 'renamed' || isAllowedPath(file.previous_filename || '')) | ||
| ); | ||
| if (!allowed) { | ||
| core.info('PR is not readme/assets-only; the narrow SVN sync will not run.'); | ||
| return; | ||
| } | ||
|
|
||
| core.setOutput('merge_sha', pull.merge_commit_sha); | ||
| core.setOutput('should_sync', 'true'); | ||
|
|
||
| update: | ||
| name: Update WordPress.org readme & assets | ||
| name: Update WordPress.org readme and assets | ||
| needs: authorize | ||
| if: needs.authorize.outputs.should_sync == 'true' | ||
| runs-on: ubuntu-latest | ||
| # Only run against the protected master branch. A manual dispatch on any | ||
| # other ref must not be able to sync unreviewed content — or a malicious | ||
| # branch copy of this workflow — using the WordPress.org SVN credentials. | ||
| if: github.ref == 'refs/heads/master' | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - name: Checkout approved merge | ||
| uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 | ||
| with: | ||
| ref: master | ||
| ref: ${{ needs.authorize.outputs.merge_sha }} | ||
|
Comment on lines
+132
to
+135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
A manual retry always checks out the selected PR's historical merge SHA without verifying that its Useful? React with 👍 / 👎.
coderabbitai[bot] marked this conversation as resolved.
|
||
| fetch-depth: 0 | ||
| persist-credentials: false | ||
|
|
||
| - name: Refuse stale readme or assets | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| run: | | ||
| git fetch --no-tags origin master | ||
| if ! git diff --quiet HEAD FETCH_HEAD -- readme.txt .wordpress-org; then | ||
| echo 'A newer readme or asset change exists on master. Refusing to publish stale files.' | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Reject symlinked publication files | ||
| run: | | ||
| if [ ! -f readme.txt ]; then | ||
| echo 'readme.txt is required for a WordPress.org update.' | ||
| exit 1 | ||
| fi | ||
| if [ -L readme.txt ] || | ||
| [ -L .wordpress-org ] || | ||
| { [ -d .wordpress-org ] && find .wordpress-org -type l -print -quit | grep -q .; }; then | ||
| echo 'Symlinks are not allowed in publication files.' | ||
| exit 1 | ||
| fi | ||
|
|
||
| - uses: 10up/action-wordpress-plugin-asset-update@stable | ||
| - name: Sync readme and assets | ||
| uses: 10up/action-wordpress-plugin-asset-update@2480306f6f693672726d08b5917ea114cb2825f7 # stable | ||
| env: | ||
| SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }} | ||
| SVN_USERNAME: ${{ secrets.SVN_USERNAME }} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A same-repository PR that changes only
readme.txtis authorized solely by file scope, so it can changeStable tagto a future, nonexistent, or older SVN version and this workflow will publish that value without checking it againstpopup-maker.phporpackage.json. In that scenario WordPress.org can advertise the wrong release or stop serving the intended current version; require the stable tag to remain unchanged for readme/assets-only PRs, or verify it still matches the current released version before enabling the sync.Useful? React with 👍 / 👎.