-
Notifications
You must be signed in to change notification settings - Fork 57
Create release branches as part of the release workflow #3817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+246
−45
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
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: | ||
full: ${{ steps.next.outputs.version }} | ||
short: ${{ steps.next.outputs.short }} | ||
|
||
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/[email protected] | ||
|
||
- name: Install Rust toolchain | ||
run: | | ||
rustup toolchain install stable | ||
rustup default stable | ||
|
||
- name: Compute the new minor RC | ||
id: next | ||
run: | | ||
CURRENT_VERSION="$(cargo metadata --format-version 1 | jq -r '.packages[] | select(.name == "mas-cli") | .version')" | ||
NEXT_VERSION="$(npx --yes [email protected] -i preminor --preid rc "${CURRENT_VERSION}")" | ||
# compute the short minor version, e.g. 0.1.0-rc.1 -> 0.1 | ||
SHORT_VERSION="$(echo "${NEXT_VERSION}" | cut -d. -f1-2)" | ||
echo "full=${NEXT_VERSION}" >> "$GITHUB_OUTPUT" | ||
echo "short=${SHORT_VERSION}" >> "$GITHUB_OUTPUT" | ||
|
||
localazy: | ||
name: Create a new branch in Localazy | ||
runs-on: ubuntu-22.04 | ||
needs: [compute-version] | ||
|
||
permissions: | ||
contents: read | ||
|
||
steps: | ||
- name: Checkout the code | ||
uses: actions/[email protected] | ||
|
||
- name: Install Node | ||
uses: actions/[email protected] | ||
with: | ||
node-version: 20 | ||
|
||
- name: Install Localazy CLI | ||
run: npm install -g @localazy/cli | ||
|
||
- name: Create a new branch in Localazy | ||
run: localazy branch -w "$LOCALAZY_WRITE_KEY" create main "$BRANCH" | ||
env: | ||
LOCALAZY_WRITE_KEY: ${{ secrets.LOCALAZY_WRITE_KEY }} | ||
# Localazy doesn't like slashes in branch names, so we just use the short version | ||
# For example, a 0.13.0 release will create a localazy branch named "v0.13" and a git branch named "release/v0.13" | ||
BRANCH: v${{ needs.compute-version.outputs.short }} | ||
|
||
tag: | ||
uses: ./.github/workflows/tag.yaml | ||
needs: [compute-version] | ||
with: | ||
version: ${{ needs.compute-version.outputs.full }} | ||
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, localazy] | ||
steps: | ||
- name: Create a new release branch | ||
uses: actions/[email protected] | ||
env: | ||
BRANCH: release/v${{ needs.compute-version.outputs.short }} | ||
SHA: ${{ needs.tag.outputs.sha }} | ||
with: | ||
github-token: ${{ secrets.BOT_GITHUB_TOKEN }} | ||
script: | | ||
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/'); | ||
const branch = process.env.BRANCH; | ||
const sha = process.env.SHA; | ||
const ref = `heads/${branch}`; | ||
|
||
await github.rest.git.createRef({ | ||
owner, | ||
repo, | ||
ref, | ||
sha, | ||
}); | ||
console.log(`Created branch ${branch} from ${sha}`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
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: Fail the workflow if not on a release branch | ||
if: ${{ !startsWith(github.ref_name, 'release/v') }} | ||
run: exit 1 | ||
|
||
- name: Checkout the code | ||
uses: actions/[email protected] | ||
|
||
- 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (ditto) |
||
|
||
- 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 [email protected] -i "$BUMP"" --preid rc "$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 }} | ||
|
||
merge-back: | ||
name: Open a pull request to merge the release branch back to main | ||
runs-on: ubuntu-22.04 | ||
|
||
permissions: | ||
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 | ||
env: | ||
VERSION: ${{ needs.compute-version.outputs.version }} | ||
run: | | ||
gh pr create \ | ||
--title "Release branch $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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/[email protected] | ||
|
@@ -35,31 +32,25 @@ 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 [email protected] -i "${{ github.event.inputs.bump }}" --preid rc "${{ steps.current.outputs.version }}")" >> "$GITHUB_OUTPUT" | ||
|
||
- name: Set the crates version | ||
env: | ||
VERSION: ${{ inputs.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 = \"$VERSION\"/" Cargo.toml | ||
sed -i "/path = \".\/crates\//s/version = \".*\"/version = \"=$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/[email protected] | ||
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 +118,7 @@ jobs: | |
- name: Update the refs | ||
uses: actions/[email protected] | ||
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 +128,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); | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
name: Download translation files from Localazy | ||
on: | ||
workflow_dispatch: | ||
secrets: | ||
BOT_GITHUB_TOKEN: | ||
required: true | ||
|
||
jobs: | ||
download: | ||
|
@@ -12,14 +9,31 @@ jobs: | |
contents: write | ||
|
||
steps: | ||
- name: Fail the workflow if not on the main branch or a release branch | ||
if: ${{ !(startsWith(github.ref_name, 'release/v') || github.ref_name == 'main') }} | ||
run: exit 1 | ||
|
||
- name: Checkout the code | ||
uses: actions/[email protected] | ||
|
||
- name: Download translation files | ||
uses: localazy/[email protected] | ||
- name: Install Node | ||
uses: actions/[email protected] | ||
with: | ||
node-version: 20 | ||
|
||
- name: Install Localazy CLI | ||
run: npm install -g @localazy/cli | ||
|
||
- name: "Fix the owner of the downloaded files" | ||
run: "sudo chown runner:docker translations/*.json frontend/locales/*.json" | ||
- name: Compute the Localazy branch name | ||
id: branch | ||
# This will strip the "release/" prefix if present, keeping 'main' as-is | ||
run: echo "name=${GITHUB_REF_NAME#release/}" >> "$GITHUB_OUTPUT" | ||
|
||
- name: Download translations from Localazy | ||
run: localazy download -w "$LOCALAZY_WRITE_KEY" -b "$BRANCH" | ||
env: | ||
LOCALAZY_WRITE_KEY: ${{ secrets.LOCALAZY_WRITE_KEY }} | ||
BRANCH: ${{ steps.branch.outputs.name }} | ||
|
||
- name: Create Pull Request | ||
id: cpr | ||
|
@@ -28,9 +42,9 @@ jobs: | |
sign-commits: true | ||
token: ${{ secrets.BOT_GITHUB_TOKEN }} | ||
branch-token: ${{ secrets.GITHUB_TOKEN }} | ||
branch: actions/localazy-download | ||
branch: actions/localazy-download/${{ steps.branch.outputs.name }} | ||
delete-branch: true | ||
title: Translations updates | ||
title: Translations updates for ${{ steps.branch.outputs.name }} | ||
labels: | | ||
T-Task | ||
A-I18n | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ on: | |
push: | ||
branches: | ||
- main | ||
- release/v** | ||
|
||
jobs: | ||
upload: | ||
|
@@ -14,7 +15,22 @@ jobs: | |
- name: Checkout the code | ||
uses: actions/[email protected] | ||
|
||
- name: Upload | ||
uses: localazy/upload@v1 | ||
- name: Install Node | ||
uses: actions/[email protected] | ||
with: | ||
write_key: ${{ secrets.LOCALAZY_WRITE_KEY }} | ||
node-version: 20 | ||
|
||
- name: Install Localazy CLI | ||
run: npm install -g @localazy/cli | ||
|
||
- name: Compute the Localazy branch name | ||
id: branch | ||
run: | | ||
# This will strip the "release/" prefix if present, keeping 'main' as-is | ||
echo "name=${GITHUB_REF_NAME#release/}" >> "$GITHUB_OUTPUT" | ||
|
||
- name: Upload translations to Localazy | ||
run: localazy upload -w "$LOCALAZY_WRITE_KEY" -b "$BRANCH" | ||
env: | ||
LOCALAZY_WRITE_KEY: ${{ secrets.LOCALAZY_WRITE_KEY }} | ||
BRANCH: ${{ steps.branch.outputs.name }} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is idiomatic for GHA but it feels suboptimal that we have to install Rust imperatively/slowly, particularly for just ... running
cargo metadata
.When I used to self-host Drone/Woodpecker CI, this would have been done by running the command on a Rust container image that already had it installed.
Separately but also along the same lines: how intensive is
cargo metadata
— does it need to fetch all dependency crates? That would seem suboptimal just for reading a version.Maybe there's a TOML version of
jq
that we could use to just pull it out ofmas-cli/Cargo.toml
? :-), or sometoml2json | jq
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair, although the current release process took about 30s, including the rustup install, so I'm not too concerned about this slowing down the release :)