diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2cf399f41..649393ae8 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -34,16 +34,34 @@ on: - '**' # Allow manually triggering the workflow. workflow_dispatch: + # Allow the release workflows to deploy the tag they just pushed. A push made with the + # built-in Actions token raises no events, so a release workflow cannot rely on its own + # tag push to trigger this workflow. + workflow_call: + inputs: + ref: + description: 'Git ref to build and deploy. Pass the tag name for a release.' + required: true + type: string + is-release: + description: 'Deploy `ref` as a release: take the version from the ref name, sync to the dist default branch and tag it there.' + required: false + default: false + type: boolean # Cancels all previous workflow runs for the same branch that have not yet completed. concurrency: - # The concurrency group contains the workflow name and the branch name. - group: ${{ github.workflow }}-${{ github.ref }} + # The concurrency group contains the workflow name and the deployed ref. + group: ${{ github.workflow }}-${{ inputs.ref || github.ref }} cancel-in-progress: true env: DIST_ORG: 'Yoast-dist' DIST_DEFAULT_BRANCH: 'main' + # A `workflow_call` gets the ref to deploy and the release flag from the calling + # workflow; `push` and `workflow_dispatch` derive both from the triggering ref. + DEPLOY_REF_NAME: ${{ inputs.ref || github.ref_name }} + IS_RELEASE: ${{ inputs.is-release || github.ref_type == 'tag' }} jobs: prepare: @@ -53,12 +71,32 @@ jobs: runs-on: ubuntu-latest + outputs: + SHA: ${{ steps.set_metadata.outputs.SHA }} + COMMIT_MSG: ${{ steps.set_metadata.outputs.COMMIT_MSG }} + COMMIT_TIME: ${{ steps.set_metadata.outputs.COMMIT_TIME }} + steps: - name: Checkout code uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: + ref: ${{ inputs.ref || github.ref }} persist-credentials: false + - name: "Set variables: commit metadata" + id: set_metadata + # The `push` payload carries the commit that triggered the run, but the + # `workflow_dispatch` and `workflow_call` payloads do not, so read the metadata + # from the checked-out ref instead. + run: | + { + echo "SHA=$(git rev-parse HEAD)" + echo "COMMIT_TIME=$(git log -1 --format=%cI)" + echo "COMMIT_MSG<> "$GITHUB_OUTPUT" + - name: Install PHP uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2 with: @@ -92,14 +130,12 @@ jobs: - name: Yarn install run: yarn install - - name: "Grunt: set package version (tags only)" - if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }} - env: - REF_NAME: ${{ github.ref_name }} - run: grunt set-version -new-version="$REF_NAME" + - name: "Grunt: set package version (releases only)" + if: ${{ env.IS_RELEASE == 'true' }} + run: grunt set-version -new-version="$DEPLOY_REF_NAME" - - name: "Grunt: update package version (tags only)" - if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }} + - name: "Grunt: update package version (releases only)" + if: ${{ env.IS_RELEASE == 'true' }} run: grunt update-version - name: "Grunt: create artifact" @@ -138,25 +174,26 @@ jobs: - name: "Set variable: short sha" id: set_sha env: - SHA: ${{ github.sha }} + SHA: ${{ needs.prepare.outputs.SHA }} run: | shortsha=$(echo "$SHA" | cut -b 1-6) echo "SHORTSHA=$shortsha" >> "$GITHUB_OUTPUT" - name: "Set variables: target branch, commit title" id: set_vars - env: - REF_NAME: ${{ github.ref_name }} run: | - if [[ "${{ github.event_name }}" == 'push' && "${{ github.ref_type }}" == 'branch' && "$REF_NAME" != "${{ env.DIST_DEFAULT_BRANCH }}" ]]; then - echo "BRANCH=$REF_NAME" >> "$GITHUB_OUTPUT" - echo "TITLE=Syncing branch $REF_NAME (sha: ${{ steps.set_sha.outputs.SHORTSHA }})" >> "$GITHUB_OUTPUT" - elif [[ "${{ github.event_name }}" == 'workflow_dispatch' && "$REF_NAME" != "${{ env.DIST_DEFAULT_BRANCH }}" ]]; then - echo "BRANCH=$REF_NAME" >> "$GITHUB_OUTPUT" - echo "TITLE=Manual deploy for $REF_NAME (sha: ${{ steps.set_sha.outputs.SHORTSHA }})" >> "$GITHUB_OUTPUT" - else # = Pushed tag. + # A release goes to the dist default branch and gets tagged there; any other ref + # syncs to a same-named branch. A run on the dist default branch itself takes the + # release path, as it did before. + if [[ "$IS_RELEASE" == 'true' || "$DEPLOY_REF_NAME" == "${{ env.DIST_DEFAULT_BRANCH }}" ]]; then echo "BRANCH=${{ env.DIST_DEFAULT_BRANCH }}" >> "$GITHUB_OUTPUT" - echo "TITLE=Release $REF_NAME" >> "$GITHUB_OUTPUT" + echo "TITLE=Release $DEPLOY_REF_NAME" >> "$GITHUB_OUTPUT" + elif [[ "${{ github.event_name }}" == 'push' && "${{ github.ref_type }}" == 'branch' ]]; then + echo "BRANCH=$DEPLOY_REF_NAME" >> "$GITHUB_OUTPUT" + echo "TITLE=Syncing branch $DEPLOY_REF_NAME (sha: ${{ steps.set_sha.outputs.SHORTSHA }})" >> "$GITHUB_OUTPUT" + else + echo "BRANCH=$DEPLOY_REF_NAME" >> "$GITHUB_OUTPUT" + echo "TITLE=Manual deploy for $DEPLOY_REF_NAME (sha: ${{ steps.set_sha.outputs.SHORTSHA }})" >> "$GITHUB_OUTPUT" fi - name: Checkout Yoast Dist repo @@ -215,12 +252,12 @@ jobs: run: git add -A - name: "Commit the files (branch)" - if: ${{ github.event_name != 'push' || github.ref_type != 'tag' }} + if: ${{ env.IS_RELEASE != 'true' }} env: - COMMITTER: ${{ github.event.head_commit.committer.username }} - COMMIT_MSG: ${{ github.event.head_commit.message }} - COMMIT_URL: ${{ github.event.head_commit.url }} - COMMIT_TIME: ${{ github.event.head_commit.timestamp }} + COMMITTER: ${{ github.event.head_commit.committer.username || github.actor }} + COMMIT_MSG: ${{ github.event.head_commit.message || needs.prepare.outputs.COMMIT_MSG }} + COMMIT_URL: ${{ github.event.head_commit.url || format('{0}/{1}/commit/{2}', github.server_url, github.repository, needs.prepare.outputs.SHA) }} + COMMIT_TIME: ${{ github.event.head_commit.timestamp || needs.prepare.outputs.COMMIT_TIME }} run: | git commit --allow-empty -m "${{ steps.set_vars.outputs.TITLE }}" \ -m "Synced up to commit hash: $COMMIT_URL" \ @@ -232,12 +269,12 @@ jobs: -m "$COMMIT_MSG" - name: "Commit the files (release)" - if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }} + if: ${{ env.IS_RELEASE == 'true' }} env: - COMMITTER: ${{ github.event.head_commit.committer.username }} - COMMIT_MSG: ${{ github.event.head_commit.message }} - COMMIT_URL: ${{ github.event.head_commit.url }} - COMMIT_TIME: ${{ github.event.head_commit.timestamp }} + COMMITTER: ${{ github.event.head_commit.committer.username || github.actor }} + COMMIT_MSG: ${{ github.event.head_commit.message || needs.prepare.outputs.COMMIT_MSG }} + COMMIT_URL: ${{ github.event.head_commit.url || format('{0}/{1}/commit/{2}', github.server_url, github.repository, needs.prepare.outputs.SHA) }} + COMMIT_TIME: ${{ github.event.head_commit.timestamp || needs.prepare.outputs.COMMIT_TIME }} run: | git commit -m "${{ steps.set_vars.outputs.TITLE }}" \ -m "Commit hash for tag: $COMMIT_URL" \ @@ -249,10 +286,8 @@ jobs: -m "$COMMIT_MSG" - name: "Tag the commit (releases only)" - if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }} - env: - REF_NAME: ${{ github.ref_name }} - run: git tag "$REF_NAME" "$(git rev-parse HEAD)" + if: ${{ env.IS_RELEASE == 'true' }} + run: git tag "$DEPLOY_REF_NAME" "$(git rev-parse HEAD)" - name: Push to target branch run: git push -u origin ${{ steps.set_vars.outputs.BRANCH }} --tags -v diff --git a/.github/workflows/release-rc.yml b/.github/workflows/release-rc.yml index 88f258173..ab351a171 100644 --- a/.github/workflows/release-rc.yml +++ b/.github/workflows/release-rc.yml @@ -21,10 +21,15 @@ name: Release RC # Finally merges the release branch back into trunk so the version bump and # changelog regen land there too. # +# A follow-up job calls .github/workflows/deploy.yml, which builds the RC tag and +# pushes the artifact to Yoast-dist/duplicate-post. A push made with the built-in +# Actions token raises no events, so the tag push cannot trigger that workflow by +# itself. +# # Pass `dry-run=true` to rehearse the pipeline without any remote side effect: -# every `git push`, the SVN deploy, the GitHub pre-release, and the merge-back -# push are skipped. The built zip is uploaded as a workflow artifact so you -# can inspect it. Overrides `deploy-to-svn-trunk`. +# every `git push`, the SVN deploy, the GitHub pre-release, the dist deploy, and +# the merge-back push are skipped. The built zip is uploaded as a workflow +# artifact so you can inspect it. Overrides `deploy-to-svn-trunk`. ############################################################################## on: @@ -45,7 +50,7 @@ on: default: false type: boolean dry-run: - description: 'Dry-run: do all in-tree work (changelog regen, version bump, local commit/merge/tag, artifact build) but skip every remote side-effect (no git push, no SVN, no GH pre-release). The built zip is uploaded as a workflow artifact for inspection. Overrides `deploy-to-svn-trunk`.' + description: 'Dry-run: do all in-tree work (changelog regen, version bump, local commit/merge/tag, artifact build) but skip every remote side-effect (no git push, no SVN, no GH pre-release, no dist deploy). The built zip is uploaded as a workflow artifact for inspection. Overrides `deploy-to-svn-trunk`.' required: false default: false type: boolean @@ -65,6 +70,9 @@ jobs: contents: write pull-requests: read + outputs: + RC_VERSION: ${{ steps.rc.outputs.RC_VERSION }} + env: RELEASE_BRANCH: "release/${{ inputs.version }}" @@ -96,6 +104,7 @@ jobs: git config user.email "$ACTOR@users.noreply.github.com" - name: Determine next RC number + id: rc env: VERSION: ${{ inputs.version }} run: | @@ -106,6 +115,7 @@ jobs: RC_VERSION="${VERSION}-RC${NEXT}" echo "RC_VERSION=${RC_VERSION}" >> "$GITHUB_ENV" echo "RC_NUM=${NEXT}" >> "$GITHUB_ENV" + echo "RC_VERSION=${RC_VERSION}" >> "$GITHUB_OUTPUT" echo "Previous RC: ${LAST:-none}. Next RC: ${RC_VERSION}" - name: Create or check out release branch @@ -482,6 +492,7 @@ jobs: fi echo "* \`gh release create ${RC_VERSION} --prerelease\` with \`${ZIP}\` attached and the QA changelog below" echo "* \`git push origin trunk\` (after merging \`${RELEASE_BRANCH}\` back)" + echo "* Build tag \`${RC_VERSION}\` and push the artifact to Yoast-dist/duplicate-post" echo "" echo "The built plugin is available as the \`duplicate-post-${RC_VERSION}\` workflow artifact above (download yields \`${ZIP}\` containing the \`duplicate-post/\` folder)." echo "" @@ -489,3 +500,14 @@ jobs: echo "" cat qa-changelog.md } >> "$GITHUB_STEP_SUMMARY" + + deploy-to-dist: + name: "Deploy to dist" + needs: release-rc + # A dry run pushes no tag, so there is nothing to deploy. + if: ${{ inputs.dry-run != true }} + uses: ./.github/workflows/deploy.yml + with: + ref: ${{ needs.release-rc.outputs.RC_VERSION }} + is-release: true + secrets: inherit diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ac6fff8cf..661868112 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,8 +9,6 @@ name: Release # 2. Bumps the version (package.json, plugin header, DUPLICATE_POST_CURRENT_VERSION, Stable tag) # on the source branch: release/x.y when an RC was cut, otherwise trunk. # 3. Merges the source branch into main (--no-ff), tags and pushes from main. -# (The tag push also triggers .github/workflows/deploy.yml, which builds -# and pushes the artifact to Yoast-dist/duplicate-post.) # 4. Builds the artifact locally and deploys it to wordpress.org SVN via the # 10up action (uses WPORG_SVN_USERNAME / WPORG_SVN_PASSWORD secrets). # 5. Creates a GitHub release with the changelog.md section as notes and @@ -19,10 +17,14 @@ name: Release # next version. # 7. Merges main back into trunk. # 8. Emits a Slack message body in the job summary for manual posting. +# 9. Calls .github/workflows/deploy.yml from a follow-up job, which builds the +# tag and pushes the artifact to Yoast-dist/duplicate-post. A push made with +# the built-in Actions token raises no events, so the tag push in step 3 +# cannot trigger that workflow by itself. # # Pass `dry-run=true` to rehearse the pipeline without any remote side effect: -# every `git push`, the SVN deploy, the GitHub release, and the milestone API -# calls are skipped. The built zip is still uploaded as a workflow artifact +# every `git push`, the SVN deploy, the GitHub release, the dist deploy, and the +# milestone API calls are skipped. The built zip is still uploaded as a workflow artifact # (named duplicate-post-${VERSION}, containing the duplicate-post/ folder) # so you can inspect it. ############################################################################## @@ -39,7 +41,7 @@ on: required: false type: string dry-run: - description: 'Dry-run: do all in-tree work (version bump, local commit/merge/tag, artifact build) but skip every remote side-effect (no git push, no SVN, no GH release, no milestone changes). The built zip is uploaded as a workflow artifact for inspection.' + description: 'Dry-run: do all in-tree work (version bump, local commit/merge/tag, artifact build) but skip every remote side-effect (no git push, no SVN, no GH release, no dist deploy, no milestone changes). The built zip is uploaded as a workflow artifact for inspection.' required: false default: false type: boolean @@ -376,6 +378,7 @@ jobs: echo "* \`gh release create ${VERSION}\` with \`${ZIP_NAME}\` attached and the release notes below" echo "* Close milestone \`${VERSION}\` and open milestone \`${NEXT_VERSION}\`" echo "* \`git push origin trunk\` (after merging \`main\` back)" + echo "* Build tag \`${VERSION}\` and push the artifact to Yoast-dist/duplicate-post" echo "" echo "The built plugin is available as the \`duplicate-post-${VERSION}\` workflow artifact above (download yields \`duplicate-post-${VERSION}.zip\` containing the \`duplicate-post/\` folder)." echo "" @@ -383,3 +386,14 @@ jobs: echo "" cat release-notes.md } >> "$GITHUB_STEP_SUMMARY" + + deploy-to-dist: + name: "Deploy to dist" + needs: release + # A dry run pushes no tag, so there is nothing to deploy. + if: ${{ inputs.dry-run != true }} + uses: ./.github/workflows/deploy.yml + with: + ref: ${{ inputs.version }} + is-release: true + secrets: inherit