Skip to content

Commit 9e7d3e8

Browse files
committed
Create release branches as part of the release workflow
1 parent 605a6dd commit 9e7d3e8

File tree

3 files changed

+177
-33
lines changed

3 files changed

+177
-33
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Create a new release branch
2+
on:
3+
workflow_dispatch:
4+
5+
jobs:
6+
compute-version:
7+
name: Compute the next minor RC version
8+
runs-on: ubuntu-22.04
9+
10+
permissions:
11+
contents: read
12+
13+
outputs:
14+
version: ${{ steps.next.outputs.version }}
15+
16+
steps:
17+
- name: Fail the workflow if this is not the main branch
18+
if: ${{ github.ref_name != 'main' }}
19+
run: exit 1
20+
21+
- name: Checkout the code
22+
uses: actions/[email protected]
23+
24+
- name: Install Rust toolchain
25+
run: |
26+
rustup toolchain install stable
27+
rustup default stable
28+
29+
- name: Extract the current version
30+
id: current
31+
run: echo "version=$(cargo metadata --format-version 1 | jq -r '.packages[] | select(.name == "mas-cli") | .version')" >> "$GITHUB_OUTPUT"
32+
33+
- name: Compute the new minor RC
34+
id: next
35+
run: echo "version=$(npx --yes [email protected] -i preminor --preid rc "${{ steps.current.outputs.version }}")" >> "$GITHUB_OUTPUT"
36+
37+
tag:
38+
uses: ./.github/workflows/tag.yaml
39+
needs: compute-version
40+
with:
41+
version: ${{ needs.compute-version.outputs.version }}
42+
secrets:
43+
BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
44+
45+
branch:
46+
name: Create a new release branch
47+
runs-on: ubuntu-22.04
48+
49+
permissions:
50+
contents: write
51+
52+
needs: [tag, compute-version]
53+
steps:
54+
- name: Create a new release branch
55+
uses: actions/[email protected]
56+
env:
57+
VERSION: ${{ needs.compute-version.outputs.version }}
58+
SHA: ${{ needs.tag.outputs.sha }}
59+
with:
60+
github-token: ${{ secrets.BOT_GITHUB_TOKEN }}
61+
script: |
62+
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
63+
64+
// Only keep the major and minor version
65+
const [major, minor, ...rest] = process.env.VERSION.split('.');
66+
const branch = `release/${major}.${minor}`;
67+
68+
const ref = `heads/${branch}`;
69+
const sha = process.env.SHA;
70+
await github.rest.git.createRef({
71+
owner,
72+
repo,
73+
ref,
74+
sha,
75+
});
76+
console.log(`Created branch ${branch}`);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Bump the version on a release branch
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
rc:
6+
description: "Is it a release candidate?"
7+
type: boolean
8+
default: false
9+
merge-back:
10+
description: "Should we merge back the release branch to main?"
11+
type: boolean
12+
default: true
13+
14+
jobs:
15+
compute-version:
16+
name: Compute the next version
17+
runs-on: ubuntu-22.04
18+
19+
permissions:
20+
contents: read
21+
22+
outputs:
23+
version: ${{ steps.next.outputs.version }}
24+
25+
steps:
26+
- name: Make sure this is a release branch
27+
run: |
28+
if [[ ! "${{ github.ref_name }}" =~ ^release/ ]; then
29+
echo "This workflow must be run on a release branch"
30+
exit 1
31+
fi
32+
33+
- name: Checkout the code
34+
uses: actions/[email protected]
35+
36+
- name: Install Rust toolchain
37+
run: |
38+
rustup toolchain install stable
39+
rustup default stable
40+
41+
- name: Extract the current version
42+
id: current
43+
run: echo "version=$(cargo metadata --format-version 1 | jq -r '.packages[] | select(.name == "mas-cli") | .version')" >> "$GITHUB_OUTPUT"
44+
45+
- name: Compute the new minor RC
46+
id: next
47+
env:
48+
BUMP: ${{ github.event.inputs.rc && 'prerelease' || 'patch' }}
49+
VERSION: ${{ steps.current.outputs.version }}
50+
run: echo "version=$(npx --yes [email protected] -i "$BUMP"" --preid rc "$VERSION")" >> "$GITHUB_OUTPUT"
51+
52+
tag:
53+
uses: ./.github/workflows/tag.yaml
54+
needs: compute-version
55+
with:
56+
version: ${{ needs.compute-version.outputs.version }}
57+
force: true
58+
secrets:
59+
BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
60+
61+
merge-back:
62+
name: Open a pull request to merge the release branch back to main
63+
runs-on: ubuntu-22.04
64+
65+
permissions:
66+
contents: write
67+
pull-requests: write
68+
69+
needs: [tag, compute-version]
70+
if: github.event.inputs.merge-back
71+
steps:
72+
- name: Open a pull request to merge the release branch back to main
73+
run: |
74+
gh pr create \
75+
--title "Release branch ${{ needs.compute-version.outputs.version }}" \
76+
--body "This pull request was automatically created by the release workflow. It merges the release branch back to main." \
77+
--base main \
78+
--head "${{ github.ref_name }}" \
79+
--label "T-Task"

.github/workflows/release.yaml renamed to .github/workflows/tag.yaml

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
1-
name: Trigger a release
1+
name: Tag a new version
22
on:
3-
workflow_dispatch:
3+
workflow_call:
4+
inputs:
5+
version:
6+
required: true
7+
type: string
8+
outputs:
9+
sha:
10+
description: "The SHA of the commit made which bumps the version"
11+
value: ${{ jobs.tag.outputs.sha }}
412
secrets:
513
BOT_GITHUB_TOKEN:
614
required: true
7-
inputs:
8-
bump:
9-
type: choice
10-
description: "What semver bump to use for the release"
11-
required: true
12-
options:
13-
- "prerelease"
14-
- "premajor"
15-
- "preminor"
16-
- "major"
17-
- "minor"
18-
- "patch"
19-
default: "minor"
20-
2115

2216
jobs:
23-
set-version:
24-
name: Bump version and push a tag
17+
tag:
18+
name: Tag a new version
2519
runs-on: ubuntu-22.04
2620
permissions:
2721
contents: write
2822

23+
outputs:
24+
sha: ${{ fromJSON(steps.commit.outputs.result).commit }}
25+
2926
steps:
3027
- name: Checkout the code
3128
uses: actions/[email protected]
@@ -35,31 +32,23 @@ jobs:
3532
rustup toolchain install stable
3633
rustup default stable
3734
38-
- name: Extract the current version
39-
id: current
40-
run: echo "version=$(cargo metadata --format-version 1 | jq -r '.packages[] | select(.name == "mas-cli") | .version')" >> "$GITHUB_OUTPUT"
41-
42-
- name: Compute the new version
43-
id: next
44-
run: echo "version=$(npx --yes [email protected] -i "${{ github.event.inputs.bump }}" --preid rc "${{ steps.current.outputs.version }}")" >> "$GITHUB_OUTPUT"
45-
4635
- name: Set the crates version
4736
run: |
48-
sed -i "s/^package.version = .*/package.version = \"${{ steps.next.outputs.version }}\"/" Cargo.toml
49-
sed -i "/path = \".\/crates\//s/version = \".*\"/version = \"=${{ steps.next.outputs.version }}\"/" Cargo.toml
37+
sed -i "s/^package.version = .*/package.version = \"${{ inputs.version }}\"/" Cargo.toml
38+
sed -i "/path = \".\/crates\//s/version = \".*\"/version = \"=${{ inputs.version }}\"/" Cargo.toml
5039
5140
- name: Run `cargo metadata` to make sure the lockfile is up to date
5241
run: cargo metadata --format-version 1
5342

5443
- name: Set the tools/syn2mas version
5544
working-directory: tools/syn2mas
56-
run: npm version "${{ steps.next.outputs.version }}" --no-git-tag-version
45+
run: npm version "${{ inputs.version }}" --no-git-tag-version
5746

5847
- name: Commit and tag using the GitHub API
5948
uses: actions/[email protected]
6049
id: commit
6150
env:
62-
VERSION: ${{ steps.next.outputs.version }}
51+
VERSION: ${{ inputs.version }}
6352
with:
6453
# Commit & tag with the actions token, so that they get signed
6554
# This returns the commit sha and the tag object sha
@@ -127,7 +116,7 @@ jobs:
127116
- name: Update the refs
128117
uses: actions/[email protected]
129118
env:
130-
VERSION: ${{ steps.next.outputs.version }}
119+
VERSION: ${{ inputs.version }}
131120
TAG_SHA: ${{ fromJSON(steps.commit.outputs.result).tag }}
132121
COMMIT_SHA: ${{ fromJSON(steps.commit.outputs.result).commit }}
133122
with:
@@ -137,14 +126,14 @@ jobs:
137126
const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");
138127
const version = process.env.VERSION;
139128
const commit = process.env.COMMIT_SHA;
140-
const tag = process.env.TAG_SHA;
129+
const tagSha = process.env.TAG_SHA;
141130
const branch = process.env.GITHUB_REF_NAME;
142131
143132
const tag = await github.rest.git.createRef({
144133
owner,
145134
repo,
146135
ref: `tags/v${version}`,
147-
sha: tag,
136+
sha: tagSha,
148137
});
149138
console.log("Created tag ref:", tag.data.url);
150139

0 commit comments

Comments
 (0)