Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions .github/workflows/release-branch.yaml
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
Comment on lines +25 to +28
Copy link
Contributor

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 of mas-cli/Cargo.toml? :-), or some toml2json | jq?

Copy link
Member Author

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 :)


- 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}`);
76 changes: 76 additions & 0 deletions .github/workflows/release-bump.yaml
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"
Copy link
Contributor

Choose a reason for hiding this comment

The 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"
57 changes: 24 additions & 33 deletions .github/workflows/release.yaml → .github/workflows/tag.yaml
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]
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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);

Expand Down
32 changes: 23 additions & 9 deletions .github/workflows/translations-download.yaml
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:
Expand All @@ -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
Expand All @@ -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
Expand Down
22 changes: 19 additions & 3 deletions .github/workflows/translations-upload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- main
- release/v**

jobs:
upload:
Expand All @@ -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 }}
Loading