Skip to content

Commit d22adee

Browse files
authored
Merge pull request #230 from woocommerce/fix/release-build-error-handling
Improve release build error handling and auto-merge the release PR
2 parents b0e6241 + 73ff487 commit d22adee

5 files changed

Lines changed: 42 additions & 7 deletions

File tree

.github/scripts/create-pr-for-release.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default async ( {
2525
- [ ] The changelog is correct.
2626
## Next steps
2727
1. Approve this PR to allow [the next workflow creates a new release](${ workflowBaseUrl }/${ createReleaseWorkflow }).
28-
1. Merge this PR after the new release is successfully created and [the version tags are updated](${ workflowBaseUrl }/${ releaseWorkflow }).
28+
1. After the new release is successfully created, [the release workflow](${ workflowBaseUrl }/${ releaseWorkflow }) will update the version tags and merge this PR automatically.
2929
---
3030
${ heading }
3131
${ content }`;

.github/scripts/github-actions-create-and-commit-build.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
2+
set -euo pipefail
23

34
# The value of TAG_NAME and the content composited from it are described in terms of
45
# the official release build. When creating a test build, a branch name is passed in,
@@ -8,6 +9,16 @@ REPO_URL=$1
89
TAG_NAME=$2
910
SOURCE_SHA=$(git rev-parse HEAD)
1011

12+
TMP_BRANCH="tmp-gha-release-build"
13+
TMP_BRANCH_PUSHED=false
14+
15+
cleanup() {
16+
if [ "$TMP_BRANCH_PUSHED" = true ]; then
17+
git push -d origin "$TMP_BRANCH" 2>/dev/null || true
18+
fi
19+
}
20+
trap cleanup EXIT
21+
1122
# To build all actions:
1223

1324
pushd ./packages/github-actions
@@ -63,7 +74,13 @@ git add README.md
6374
## 7. Complete the build for release or test.
6475
git commit -q --amend -C HEAD
6576

66-
# The temporary `tmp-gha-release-build` branch is only for pushing to the remote repo.
77+
# The temporary branch is only for pushing to the remote repo.
6778
# Tagging it with a version tag will be proceeded with a separate step.
68-
git push origin HEAD:refs/heads/tmp-gha-release-build
69-
git push -d origin tmp-gha-release-build
79+
git push origin "HEAD:refs/heads/$TMP_BRANCH"
80+
TMP_BRANCH_PUSHED=true
81+
82+
# Deleting the temporary branch is cleanup, so a failure here should not fail an
83+
# otherwise successful release. Leave it best-effort and let the EXIT trap retry.
84+
if git push -d origin "$TMP_BRANCH"; then
85+
TMP_BRANCH_PUSHED=false
86+
fi

.github/workflows/github-actions-release.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,21 @@ jobs:
108108
repo-token: ${{ secrets.GITHUB_TOKEN }}
109109
sha: ${{ steps.commit-build.outputs.sha }}
110110
release: ${{ needs.Setup.outputs.release }}
111+
112+
MergeReleasePR:
113+
name: Merge Release PR
114+
if: ${{ github.event_name == 'workflow_run' }}
115+
needs: UpdateTags
116+
runs-on: ubuntu-latest
117+
permissions:
118+
contents: write
119+
pull-requests: write
120+
steps:
121+
- name: Merge the release PR
122+
env:
123+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
124+
run: |
125+
gh pr merge "${{ github.event.workflow_run.head_branch }}" \
126+
--repo "${{ github.repository }}" \
127+
--merge \
128+
--delete-branch

packages/github-actions/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,12 @@ Branch off from the old version, set the merge base for fixing PR to be the same
165165
1. :technologist: If it's all good, approve the release PR to proceed with the next workflow.
166166
1. :octocat: Once the release PR is approved, a workflow will create a new release with a new version tag.
167167
- Workflow [GitHub Actions - Create Release](https://github.com/woocommerce/grow/actions/workflows/github-actions-create-release.yml)
168-
1. :octocat: After publishing the new release, a workflow will continue to create and commit the release build. And then update the references of the corresponding major and minor version tags onto the new release.
168+
1. :octocat: After publishing the new release, a workflow will continue to create and commit the release build, update the references of the corresponding major and minor version tags onto the new release, and merge the release PR.
169169
- Workflow [GitHub Actions - Release](https://github.com/woocommerce/grow/actions/workflows/github-actions-release.yml)
170170
- When the new release version is `actions-v2.4.8`, it should update the references of `actions-v2` and `actions-v2.4` onto `actions-v2.4.8`.
171171
- When the new release version is `actions-v2.5.0`, it should update the reference of `actions-v2` and create `actions-v2.5` tag onto `actions-v2.5.0`.
172172
- When the new release version is `actions-v3.0.0`, it should create `actions-v3` and `actions-v3.0` tags onto `actions-v3.0.0`.
173-
1. :technologist: Check if both release workflows are run successfully.
174-
1. :technologist: Merge the release PR.
173+
1. :technologist: Check if the release workflow has run successfully.
175174

176175
### Testing the release process
177176

packages/github-actions/build-php-actions.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
2+
set -euo pipefail
23

34
# Loop through all directories, building the package for each one if it has composer.json.
45
for d in $(find ./actions -mindepth 1 -maxdepth 1 -type d) ; do

0 commit comments

Comments
 (0)