Skip to content

Commit 5e8cd28

Browse files
authored
Merge pull request #3954 from element-hq/ref-merge/cb559012b7b4abd4232d3d2bb3b9f76779e114d5
Merge back release branch to main
2 parents 08fc64e + 911aecb commit 5e8cd28

File tree

24 files changed

+892
-152
lines changed

24 files changed

+892
-152
lines changed

.github/workflows/build.yaml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ on:
1010

1111
# Only run for pull requests if relevant files were changed
1212
pull_request:
13-
branches: [main]
13+
branches:
14+
- main
15+
- 'release/**'
1416
paths:
1517
- Dockerfile
1618
- docker-bake.hcl
@@ -31,10 +33,37 @@ env:
3133
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
3234

3335
jobs:
36+
compute-version:
37+
name: Compute version using git describe
38+
runs-on: ubuntu-24.04
39+
outputs:
40+
describe: ${{ steps.git.outputs.describe }}
41+
timestamp: ${{ steps.git.outputs.timestamp }}
42+
steps:
43+
- name: Checkout the code
44+
uses: actions/checkout@v4.2.2
45+
with:
46+
# Need a full clone so that `git describe` reports the right version
47+
fetch-depth: 0
48+
49+
- name: Compute version and timestamp out of git history
50+
id: git
51+
run: |
52+
echo "describe=$(git describe --tags --match 'v*.*.*' --always)" >> $GITHUB_OUTPUT
53+
echo "timestamp=$(git log -1 --format=%ct)" >> $GITHUB_OUTPUT
54+
55+
3456
build-binaries:
3557
name: Build binaries
3658
runs-on: ubuntu-22.04
3759

60+
needs:
61+
- compute-version
62+
63+
env:
64+
VERGEN_GIT_DESCRIBE: ${{ needs.compute-version.outputs.describe }}
65+
SOURCE_DATE_EPOCH: ${{ needs.compute-version.outputs.timestamp }}
66+
3867
permissions:
3968
contents: read
4069

@@ -136,6 +165,13 @@ jobs:
136165
packages: write
137166
id-token: write
138167

168+
needs:
169+
- compute-version
170+
171+
env:
172+
VERGEN_GIT_DESCRIBE: ${{ needs.compute-version.outputs.describe }}
173+
SOURCE_DATE_EPOCH: ${{ needs.compute-version.outputs.timestamp }}
174+
139175
steps:
140176
- name: Docker meta
141177
id: meta

.github/workflows/merge-back.yaml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Merge back a reference to main
2+
on:
3+
workflow_call:
4+
inputs:
5+
sha:
6+
required: true
7+
type: string
8+
secrets:
9+
BOT_GITHUB_TOKEN:
10+
required: true
11+
12+
jobs:
13+
merge-back:
14+
name: Merge back the reference to main
15+
runs-on: ubuntu-22.04
16+
17+
steps:
18+
- name: Push branch and open a PR
19+
uses: actions/github-script@v7.0.1
20+
env:
21+
SHA: ${{ inputs.sha }}
22+
with:
23+
github-token: ${{ secrets.BOT_GITHUB_TOKEN }}
24+
script: |
25+
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
26+
const sha = process.env.SHA;
27+
const branch = `ref-merge/${sha}`;
28+
const ref = `heads/${branch}`;
29+
30+
await github.rest.git.createRef({
31+
owner,
32+
repo,
33+
ref,
34+
sha,
35+
});
36+
console.log(`Created branch ${branch} to ${sha}`);
37+
38+
// Create a PR to merge the branch back to main
39+
const pr = await github.rest.pulls.create({
40+
owner,
41+
repo,
42+
head: branch,
43+
base: 'main',
44+
title: `Automatic merge back to main`,
45+
body: `This pull request was automatically created by the release workflow. It merges the release branch back to main.`,
46+
maintainer_can_modify: true,
47+
});
48+
console.log(`Created pull request #${pr.data.number} to merge the release branch back to main`);
49+
console.log(`PR URL: ${pr.data.html_url}`);
50+
51+
// Add the `T-Task` label to the PR
52+
await github.rest.issues.addLabels({
53+
owner,
54+
repo,
55+
issue_number: pr.data.number,
56+
labels: ['T-Task'],
57+
});
58+
59+
// Enable auto-merge on the PR
60+
await github.graphql(
61+
`
62+
mutation AutoMerge($id: ID!) {
63+
enablePullRequestAutoMerge(input: {
64+
pullRequestId: $id,
65+
mergeMethod: MERGE,
66+
}) {
67+
clientMutationId
68+
}
69+
}
70+
`,
71+
{ id: pr.data.node_id },
72+
);

.github/workflows/release-branch.yaml

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ jobs:
7373
secrets:
7474
BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
7575

76+
merge-back:
77+
uses: ./.github/workflows/merge-back.yaml
78+
needs: [tag]
79+
with:
80+
sha: ${{ needs.tag.outputs.sha }}
81+
secrets:
82+
BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
83+
7684
branch:
7785
name: Create a new release branch
7886
runs-on: ubuntu-22.04
@@ -103,20 +111,3 @@ jobs:
103111
sha,
104112
});
105113
console.log(`Created branch ${branch} from ${sha}`);
106-
107-
- name: Checkout the code
108-
uses: actions/checkout@v4.2.2
109-
with:
110-
ref: "release/v${{ needs.compute-version.outputs.short }}"
111-
112-
- name: Open a pull request to merge the branch into main
113-
env:
114-
VERSION: ${{ needs.compute-version.outputs.short }}
115-
GH_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
116-
run: |
117-
gh pr create \
118-
--title "Release branch $VERSION" \
119-
--body "This pull request was automatically created by the release workflow. It merges the release branch back to main." \
120-
--base main \
121-
--head "release/v$VERSION" \
122-
--label "T-Task"

.github/workflows/release-bump.yaml

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- name: Compute the new minor RC
4343
id: next
4444
env:
45-
BUMP: ${{ github.event.inputs.rc && 'prerelease' || 'patch' }}
45+
BUMP: ${{ inputs.rc && 'prerelease' || 'patch' }}
4646
VERSION: ${{ steps.current.outputs.version }}
4747
run: echo "version=$(npx --yes semver@7.5.4 -i "$BUMP" --preid rc "$VERSION")" >> "$GITHUB_OUTPUT"
4848

@@ -54,6 +54,15 @@ jobs:
5454
secrets:
5555
BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
5656

57+
merge-back:
58+
uses: ./.github/workflows/merge-back.yaml
59+
needs: [tag]
60+
if: inputs.merge-back
61+
with:
62+
sha: ${{ needs.tag.outputs.sha }}
63+
secrets:
64+
BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
65+
5766
update-branch:
5867
name: Update the release branch
5968
runs-on: ubuntu-22.04
@@ -83,21 +92,3 @@ jobs:
8392
sha,
8493
});
8594
console.log(`Updated branch ${branch} to ${sha}`);
86-
87-
- name: Checkout the code
88-
uses: actions/checkout@v4.2.2
89-
with:
90-
ref: "${{ github.ref_name }}"
91-
92-
- name: Open a pull request to merge the release branch back to main
93-
if: github.event.inputs.merge-back
94-
env:
95-
VERSION: ${{ needs.compute-version.outputs.version }}
96-
GH_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
97-
run: |
98-
gh pr create \
99-
--title "Release branch $VERSION" \
100-
--body "This pull request was automatically created by the release workflow. It merges the release branch back to main." \
101-
--base main \
102-
--head "$GITHUB_REF_NAME" \
103-
--label "T-Task"

0 commit comments

Comments
 (0)