Skip to content

Commit b29dafb

Browse files
authored
FIX (DevOps): @W-16151756@: create-release-branch now uses interim branch for bookkeeping. (#1531)
1 parent c3e639b commit b29dafb

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

.github/workflows/create-release-branch.yml

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ jobs:
6060
with:
6161
node-version: 'lts/*' # Always use Node LTS for building dependencies.
6262
- run: yarn
63-
# Increment the version as desired.
64-
- name: Increment version
63+
# Increment the version as desired locally, without actually commiting anything.
64+
- name: Locally increment version
6565
run: |
6666
# A workflow dispatch event lets the user specify what release type they want.
6767
if [[ "${{ github.event_name }}" = "workflow_dispatch" ]]; then
@@ -72,22 +72,25 @@ jobs:
7272
fi
7373
# Increment the version as needed.
7474
npm --no-git-tag-version version $RELEASE_TYPE
75-
# Create the new branch as a direct copy of `dev` and push it to GitHub so the API can
76-
# interact with it later.
77-
- id: create-branch
75+
# The branch protection rule for `release-x.y.z` branches prevents pushing commits directly. To work around this,
76+
# we create an interim branch that we _can_ push commits to, and we'll do our version bookkeeping in that branch
77+
# instead.
78+
- id: create-interim-branch
79+
name: Create interim branch
7880
run: |
7981
NEW_VERSION=$(jq -r ".version" package.json)
80-
git checkout -b release-$NEW_VERSION
81-
# Push the branch immediately without committing anything.
82-
git push --set-upstream origin release-$NEW_VERSION
83-
# Output the branch name so we can use it in later jobs.
84-
echo "branch_name=release-$NEW_VERSION" >> "$GITHUB_OUTPUT"
85-
# Update our dependencies.
82+
INTERIM_BRANCH_NAME=${NEW_VERSION}-interim
83+
# Create and check out the interim branch.
84+
git checkout -b $INTERIM_BRANCH_NAME
85+
# Immediately push the interim branch with no changes, so GraphQL can push to it later.
86+
git push --set-upstream origin $INTERIM_BRANCH_NAME
87+
# Update dependencies.
8688
- run: |
8789
yarn upgrade
8890
node tools/UpdateRetireJsVulns.js
8991
# Use the GraphQL API to create a signed commit with the various changes.
90-
- run: |
92+
- name: Commit to interim branch
93+
run: |
9194
# GraphQL needs to know what branch to push to.
9295
BRANCH=$(git rev-parse --abbrev-ref HEAD)
9396
# GraphQL needs a message for the commit.
@@ -130,6 +133,19 @@ jobs:
130133
}
131134
}
132135
}'
136+
# Now that we've done our bookkeeping commits on the interim branch, use it as the base for the real release branch.
137+
- name: Create release branch
138+
id: create-branch
139+
run: |
140+
# The commit happened on the remote end, not ours, so we need to clean the directory and pull.
141+
git checkout -- .
142+
git pull
143+
# Now we can create the actual release branch.
144+
NEW_VERSION=$(jq -r ".version" package.json)
145+
git checkout -b release-$NEW_VERSION
146+
git push --set-upstream origin release-$NEW_VERSION
147+
# Output the branch name so we can use it in later jobs.
148+
echo "branch_name=release-$NEW_VERSION" >> "$GITHUB_OUTPUT"
133149
# Run all the various tests against the newly created branch.
134150
test-release-branch:
135151
needs: create-release-branch

0 commit comments

Comments
 (0)