Skip to content

Commit 2b832bd

Browse files
committed
Create branches in localazy as part of the release process
1 parent 9e7d3e8 commit 2b832bd

File tree

5 files changed

+98
-41
lines changed

5 files changed

+98
-41
lines changed

.github/workflows/release-branch.yaml

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ jobs:
1111
contents: read
1212

1313
outputs:
14-
version: ${{ steps.next.outputs.version }}
14+
full: ${{ steps.next.outputs.version }}
15+
short: ${{ steps.next.outputs.short }}
1516

1617
steps:
1718
- name: Fail the workflow if this is not the main branch
@@ -26,19 +27,49 @@ jobs:
2627
rustup toolchain install stable
2728
rustup default stable
2829
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-
3330
- name: Compute the new minor RC
3431
id: next
35-
run: echo "version=$(npx --yes [email protected] -i preminor --preid rc "${{ steps.current.outputs.version }}")" >> "$GITHUB_OUTPUT"
32+
run: |
33+
CURRENT_VERSION="$(cargo metadata --format-version 1 | jq -r '.packages[] | select(.name == "mas-cli") | .version')"
34+
NEXT_VERSION="$(npx --yes [email protected] -i preminor --preid rc "${CURRENT_VERSION}")"
35+
# compute the short minor version, e.g. 0.1.0-rc.1 -> 0.1
36+
SHORT_VERSION="$(echo "${NEXT_VERSION}" | cut -d. -f1-2)"
37+
echo "full=${NEXT_VERSION}" >> "$GITHUB_OUTPUT"
38+
echo "short=${SHORT_VERSION}" >> "$GITHUB_OUTPUT"
39+
40+
localazy:
41+
name: Create a new branch in Localazy
42+
runs-on: ubuntu-22.04
43+
needs: [compute-version]
44+
45+
permissions:
46+
contents: read
47+
48+
steps:
49+
- name: Checkout the code
50+
uses: actions/[email protected]
51+
52+
- name: Install Node
53+
uses: actions/[email protected]
54+
with:
55+
node-version: 20
56+
57+
- name: Install Localazy CLI
58+
run: npm install -g @localazy/cli
59+
60+
- name: Create a new branch in Localazy
61+
run: localazy branch -w "$LOCALAZY_WRITE_KEY" create main "$BRANCH"
62+
env:
63+
LOCALAZY_WRITE_KEY: ${{ secrets.LOCALAZY_WRITE_KEY }}
64+
# Localazy doesn't like slashes in branch names, so we just use the short version
65+
# For example, a 0.13.0 release will create a localazy branch named "v0.13" and a git branch named "release/v0.13"
66+
BRANCH: v${{ needs.compute-version.outputs.short }}
3667

3768
tag:
3869
uses: ./.github/workflows/tag.yaml
39-
needs: compute-version
70+
needs: [compute-version]
4071
with:
41-
version: ${{ needs.compute-version.outputs.version }}
72+
version: ${{ needs.compute-version.outputs.full }}
4273
secrets:
4374
BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
4475

@@ -54,23 +85,20 @@ jobs:
5485
- name: Create a new release branch
5586
uses: actions/[email protected]
5687
env:
57-
VERSION: ${{ needs.compute-version.outputs.version }}
88+
BRANCH: release/v${{ needs.compute-version.outputs.short }}
5889
SHA: ${{ needs.tag.outputs.sha }}
5990
with:
6091
github-token: ${{ secrets.BOT_GITHUB_TOKEN }}
6192
script: |
6293
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}`;
94+
const branch = process.env.BRANCH;
6995
const sha = process.env.SHA;
96+
const ref = `heads/${branch}`;
97+
7098
await github.rest.git.createRef({
7199
owner,
72100
repo,
73101
ref,
74102
sha,
75103
});
76-
console.log(`Created branch ${branch}`);
104+
console.log(`Created branch ${branch} from ${sha}`);

.github/workflows/release-bump.yaml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@ jobs:
2323
version: ${{ steps.next.outputs.version }}
2424

2525
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
26+
- name: Fail the workflow if not on a release branch
27+
if: ${{ !startsWith(github.ref_name, 'release/v') }}
28+
run: exit 1
3229

3330
- name: Checkout the code
3431
uses: actions/[email protected]
@@ -51,10 +48,9 @@ jobs:
5148

5249
tag:
5350
uses: ./.github/workflows/tag.yaml
54-
needs: compute-version
51+
needs: [compute-version]
5552
with:
5653
version: ${{ needs.compute-version.outputs.version }}
57-
force: true
5854
secrets:
5955
BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
6056

@@ -63,17 +59,18 @@ jobs:
6359
runs-on: ubuntu-22.04
6460

6561
permissions:
66-
contents: write
6762
pull-requests: write
6863

6964
needs: [tag, compute-version]
7065
if: github.event.inputs.merge-back
7166
steps:
7267
- name: Open a pull request to merge the release branch back to main
68+
env:
69+
VERSION: ${{ needs.compute-version.outputs.version }}
7370
run: |
7471
gh pr create \
75-
--title "Release branch ${{ needs.compute-version.outputs.version }}" \
72+
--title "Release branch $VERSION" \
7673
--body "This pull request was automatically created by the release workflow. It merges the release branch back to main." \
7774
--base main \
78-
--head "${{ github.ref_name }}" \
75+
--head "$GITHUB_REF_NAME" \
7976
--label "T-Task"

.github/workflows/tag.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ jobs:
3333
rustup default stable
3434
3535
- name: Set the crates version
36+
env:
37+
VERSION: ${{ inputs.version }}
3638
run: |
37-
sed -i "s/^package.version = .*/package.version = \"${{ inputs.version }}\"/" Cargo.toml
38-
sed -i "/path = \".\/crates\//s/version = \".*\"/version = \"=${{ inputs.version }}\"/" Cargo.toml
39+
sed -i "s/^package.version = .*/package.version = \"$VERSION\"/" Cargo.toml
40+
sed -i "/path = \".\/crates\//s/version = \".*\"/version = \"=$VERSION\"/" Cargo.toml
3941
4042
- name: Run `cargo metadata` to make sure the lockfile is up to date
4143
run: cargo metadata --format-version 1

.github/workflows/translations-download.yaml

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
name: Download translation files from Localazy
22
on:
33
workflow_dispatch:
4-
secrets:
5-
BOT_GITHUB_TOKEN:
6-
required: true
74

85
jobs:
96
download:
@@ -12,14 +9,31 @@ jobs:
129
contents: write
1310

1411
steps:
12+
- name: Fail the workflow if not on the main branch or a release branch
13+
if: ${{ !(startsWith(github.ref_name, 'release/v') || github.ref_name == 'main') }}
14+
run: exit 1
15+
1516
- name: Checkout the code
1617
uses: actions/[email protected]
1718

18-
- name: Download translation files
19-
uses: localazy/[email protected]
19+
- name: Install Node
20+
uses: actions/[email protected]
21+
with:
22+
node-version: 20
23+
24+
- name: Install Localazy CLI
25+
run: npm install -g @localazy/cli
2026

21-
- name: "Fix the owner of the downloaded files"
22-
run: "sudo chown runner:docker translations/*.json frontend/locales/*.json"
27+
- name: Compute the Localazy branch name
28+
id: branch
29+
# This will strip the "release/" prefix if present, keeping 'main' as-is
30+
run: echo "name=${GITHUB_REF_NAME#release/}" >> "$GITHUB_OUTPUT"
31+
32+
- name: Download translations from Localazy
33+
run: localazy download -w "$LOCALAZY_WRITE_KEY" -b "$BRANCH"
34+
env:
35+
LOCALAZY_WRITE_KEY: ${{ secrets.LOCALAZY_WRITE_KEY }}
36+
BRANCH: ${{ steps.branch.outputs.name }}
2337

2438
- name: Create Pull Request
2539
id: cpr
@@ -28,9 +42,9 @@ jobs:
2842
sign-commits: true
2943
token: ${{ secrets.BOT_GITHUB_TOKEN }}
3044
branch-token: ${{ secrets.GITHUB_TOKEN }}
31-
branch: actions/localazy-download
45+
branch: actions/localazy-download/${{ steps.branch.outputs.name }}
3246
delete-branch: true
33-
title: Translations updates
47+
title: Translations updates for ${{ steps.branch.outputs.name }}
3448
labels: |
3549
T-Task
3650
A-I18n

.github/workflows/translations-upload.yaml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ on:
33
push:
44
branches:
55
- main
6+
- release/v**
67

78
jobs:
89
upload:
@@ -14,7 +15,22 @@ jobs:
1415
- name: Checkout the code
1516
uses: actions/[email protected]
1617

17-
- name: Upload
18-
uses: localazy/upload@v1
18+
- name: Install Node
19+
uses: actions/[email protected]
1920
with:
20-
write_key: ${{ secrets.LOCALAZY_WRITE_KEY }}
21+
node-version: 20
22+
23+
- name: Install Localazy CLI
24+
run: npm install -g @localazy/cli
25+
26+
- name: Compute the Localazy branch name
27+
id: branch
28+
run: |
29+
# This will strip the "release/" prefix if present, keeping 'main' as-is
30+
echo "name=${GITHUB_REF_NAME#release/}" >> "$GITHUB_OUTPUT"
31+
32+
- name: Upload translations to Localazy
33+
run: localazy upload -w "$LOCALAZY_WRITE_KEY" -b "$BRANCH"
34+
env:
35+
LOCALAZY_WRITE_KEY: ${{ secrets.LOCALAZY_WRITE_KEY }}
36+
BRANCH: ${{ steps.branch.outputs.name }}

0 commit comments

Comments
 (0)