Create release branches as part of the release workflow

This commit is contained in:
Quentin Gliech
2025-01-20 17:50:50 +01:00
parent c63a4d016f
commit 3b167c9777
3 changed files with 177 additions and 33 deletions

76
.github/workflows/release-branch.yaml vendored Normal file
View File

@@ -0,0 +1,76 @@
name: Create a new release branch
on:
workflow_dispatch:
jobs:
compute-version:
name: Compute the next minor RC version
runs-on: ubuntu-22.04
permissions:
contents: read
outputs:
version: ${{ steps.next.outputs.version }}
steps:
- name: Fail the workflow if this is not the main branch
if: ${{ github.ref_name != 'main' }}
run: exit 1
- name: Checkout the code
uses: actions/checkout@v4.2.2
- name: Install Rust toolchain
run: |
rustup toolchain install stable
rustup default stable
- name: Extract the current version
id: current
run: echo "version=$(cargo metadata --format-version 1 | jq -r '.packages[] | select(.name == "mas-cli") | .version')" >> "$GITHUB_OUTPUT"
- name: Compute the new minor RC
id: next
run: echo "version=$(npx --yes semver@7.5.4 -i preminor --preid rc "${{ steps.current.outputs.version }}")" >> "$GITHUB_OUTPUT"
tag:
uses: ./.github/workflows/tag.yaml
needs: compute-version
with:
version: ${{ needs.compute-version.outputs.version }}
secrets:
BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
branch:
name: Create a new release branch
runs-on: ubuntu-22.04
permissions:
contents: write
needs: [tag, compute-version]
steps:
- name: Create a new release branch
uses: actions/github-script@v7.0.1
env:
VERSION: ${{ needs.compute-version.outputs.version }}
SHA: ${{ needs.tag.outputs.sha }}
with:
github-token: ${{ secrets.BOT_GITHUB_TOKEN }}
script: |
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
// Only keep the major and minor version
const [major, minor, ...rest] = process.env.VERSION.split('.');
const branch = `release/${major}.${minor}`;
const ref = `heads/${branch}`;
const sha = process.env.SHA;
await github.rest.git.createRef({
owner,
repo,
ref,
sha,
});
console.log(`Created branch ${branch}`);

79
.github/workflows/release-bump.yaml vendored Normal file
View File

@@ -0,0 +1,79 @@
name: Bump the version on a release branch
on:
workflow_dispatch:
inputs:
rc:
description: "Is it a release candidate?"
type: boolean
default: false
merge-back:
description: "Should we merge back the release branch to main?"
type: boolean
default: true
jobs:
compute-version:
name: Compute the next version
runs-on: ubuntu-22.04
permissions:
contents: read
outputs:
version: ${{ steps.next.outputs.version }}
steps:
- name: Make sure this is a release branch
run: |
if [[ ! "${{ github.ref_name }}" =~ ^release/ ]; then
echo "This workflow must be run on a release branch"
exit 1
fi
- name: Checkout the code
uses: actions/checkout@v4.2.2
- name: Install Rust toolchain
run: |
rustup toolchain install stable
rustup default stable
- name: Extract the current version
id: current
run: echo "version=$(cargo metadata --format-version 1 | jq -r '.packages[] | select(.name == "mas-cli") | .version')" >> "$GITHUB_OUTPUT"
- name: Compute the new minor RC
id: next
env:
BUMP: ${{ github.event.inputs.rc && 'prerelease' || 'patch' }}
VERSION: ${{ steps.current.outputs.version }}
run: echo "version=$(npx --yes semver@7.5.4 -i "$BUMP"" --preid rc "$VERSION")" >> "$GITHUB_OUTPUT"
tag:
uses: ./.github/workflows/tag.yaml
needs: compute-version
with:
version: ${{ needs.compute-version.outputs.version }}
force: true
secrets:
BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
merge-back:
name: Open a pull request to merge the release branch back to main
runs-on: ubuntu-22.04
permissions:
contents: write
pull-requests: write
needs: [tag, compute-version]
if: github.event.inputs.merge-back
steps:
- name: Open a pull request to merge the release branch back to main
run: |
gh pr create \
--title "Release branch ${{ needs.compute-version.outputs.version }}" \
--body "This pull request was automatically created by the release workflow. It merges the release branch back to main." \
--base main \
--head "${{ github.ref_name }}" \
--label "T-Task"

View File

@@ -1,31 +1,28 @@
name: Trigger a release
name: Tag a new version
on:
workflow_dispatch:
workflow_call:
inputs:
version:
required: true
type: string
outputs:
sha:
description: "The SHA of the commit made which bumps the version"
value: ${{ jobs.tag.outputs.sha }}
secrets:
BOT_GITHUB_TOKEN:
required: true
inputs:
bump:
type: choice
description: "What semver bump to use for the release"
required: true
options:
- "prerelease"
- "premajor"
- "preminor"
- "major"
- "minor"
- "patch"
default: "minor"
jobs:
set-version:
name: Bump version and push a tag
tag:
name: Tag a new version
runs-on: ubuntu-22.04
permissions:
contents: write
outputs:
sha: ${{ fromJSON(steps.commit.outputs.result).commit }}
steps:
- name: Checkout the code
uses: actions/checkout@v4.2.2
@@ -35,31 +32,23 @@ jobs:
rustup toolchain install stable
rustup default stable
- name: Extract the current version
id: current
run: echo "version=$(cargo metadata --format-version 1 | jq -r '.packages[] | select(.name == "mas-cli") | .version')" >> "$GITHUB_OUTPUT"
- name: Compute the new version
id: next
run: echo "version=$(npx --yes semver@7.5.4 -i "${{ github.event.inputs.bump }}" --preid rc "${{ steps.current.outputs.version }}")" >> "$GITHUB_OUTPUT"
- name: Set the crates version
run: |
sed -i "s/^package.version = .*/package.version = \"${{ steps.next.outputs.version }}\"/" Cargo.toml
sed -i "/path = \".\/crates\//s/version = \".*\"/version = \"=${{ steps.next.outputs.version }}\"/" Cargo.toml
sed -i "s/^package.version = .*/package.version = \"${{ inputs.version }}\"/" Cargo.toml
sed -i "/path = \".\/crates\//s/version = \".*\"/version = \"=${{ inputs.version }}\"/" Cargo.toml
- name: Run `cargo metadata` to make sure the lockfile is up to date
run: cargo metadata --format-version 1
- name: Set the tools/syn2mas version
working-directory: tools/syn2mas
run: npm version "${{ steps.next.outputs.version }}" --no-git-tag-version
run: npm version "${{ inputs.version }}" --no-git-tag-version
- name: Commit and tag using the GitHub API
uses: actions/github-script@v7.0.1
id: commit
env:
VERSION: ${{ steps.next.outputs.version }}
VERSION: ${{ inputs.version }}
with:
# Commit & tag with the actions token, so that they get signed
# This returns the commit sha and the tag object sha
@@ -127,7 +116,7 @@ jobs:
- name: Update the refs
uses: actions/github-script@v7.0.1
env:
VERSION: ${{ steps.next.outputs.version }}
VERSION: ${{ inputs.version }}
TAG_SHA: ${{ fromJSON(steps.commit.outputs.result).tag }}
COMMIT_SHA: ${{ fromJSON(steps.commit.outputs.result).commit }}
with:
@@ -137,14 +126,14 @@ jobs:
const [owner, repo] = process.env.GITHUB_REPOSITORY.split("/");
const version = process.env.VERSION;
const commit = process.env.COMMIT_SHA;
const tag = process.env.TAG_SHA;
const tagSha = process.env.TAG_SHA;
const branch = process.env.GITHUB_REF_NAME;
const tag = await github.rest.git.createRef({
owner,
repo,
ref: `tags/v${version}`,
sha: tag,
sha: tagSha,
});
console.log("Created tag ref:", tag.data.url);