Skip to content

Commit 63ebab5

Browse files
committed
[ci] Enable release-candidates and backport functionality
Signed-off-by: Andrei Kvapil <[email protected]>
1 parent a6b02bf commit 63ebab5

4 files changed

Lines changed: 289 additions & 133 deletions

File tree

‎.github/workflows/backport.yaml‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Automatic Backport
2+
3+
on:
4+
pull_request_target:
5+
types: [closed] # fires when PR is closed (merged)
6+
7+
permissions:
8+
contents: write
9+
pull-requests: write
10+
11+
jobs:
12+
backport:
13+
if: |
14+
github.event.pull_request.merged == true &&
15+
contains(github.event.pull_request.labels.*.name, 'backport')
16+
runs-on: [self-hosted]
17+
18+
steps:
19+
# 1. Decide which maintenance branch should receive the back‑port
20+
- name: Determine target maintenance branch
21+
id: target
22+
uses: actions/github-script@v7
23+
with:
24+
script: |
25+
let rel;
26+
try {
27+
rel = await github.rest.repos.getLatestRelease({
28+
owner: context.repo.owner,
29+
repo: context.repo.repo
30+
});
31+
} catch (e) {
32+
core.setFailed('No existing releases found; cannot determine backport target.');
33+
return;
34+
}
35+
const [maj, min] = rel.data.tag_name.replace(/^v/, '').split('.');
36+
const branch = `release-${maj}.${min}`;
37+
core.setOutput('branch', branch);
38+
console.log(`Latest release ${rel.data.tag_name}; backporting to ${branch}`);
39+
# 2. Checkout (required by backport‑action)
40+
- name: Checkout repository
41+
uses: actions/checkout@v4
42+
43+
# 3. Create the back‑port pull request
44+
- name: Create back‑port PR
45+
uses: korthout/backport-action@v3
46+
with:
47+
github_token: ${{ secrets.GITHUB_TOKEN }}
48+
label_pattern: '' # don't read labels for targets
49+
target_branches: ${{ steps.target.outputs.branch }}

‎.github/workflows/pull-requests-release.yaml‎

Lines changed: 71 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -39,58 +39,100 @@ jobs:
3939
runs-on: [self-hosted]
4040
permissions:
4141
contents: write
42-
42+
4343
if: |
4444
github.event.pull_request.merged == true &&
4545
contains(github.event.pull_request.labels.*.name, 'release')
46-
46+
4747
steps:
48+
# Extract tag from branch name (branch = release-X.Y.Z*)
4849
- name: Extract tag from branch name
4950
id: get_tag
5051
uses: actions/github-script@v7
5152
with:
5253
script: |
5354
const branch = context.payload.pull_request.head.ref;
54-
const match = branch.match(/^release-(\d+\.\d+\.\d+(?:[-\w\.]+)?)$/);
55-
56-
if (!match) {
57-
core.setFailed(`Branch '${branch}' does not match expected format 'release-X.Y.Z[-suffix]'`);
58-
} else {
59-
const tag = `v${match[1]}`;
60-
core.setOutput('tag', tag);
61-
console.log(`✅ Extracted tag: ${tag}`);
55+
const m = branch.match(/^release-(\d+\.\d+\.\d+(?:[-\w\.]+)?)$/);
56+
if (!m) {
57+
core.setFailed(`Branch '${branch}' does not match 'release-X.Y.Z[-suffix]'`);
58+
return;
6259
}
63-
60+
const tag = `v${m[1]}`;
61+
core.setOutput('tag', tag);
62+
console.log(`✅ Tag to publish: ${tag}`);
63+
64+
# Checkout repo & create / push annotated tag
6465
- name: Checkout repo
6566
uses: actions/checkout@v4
6667
with:
6768
fetch-depth: 0
68-
69-
- name: Create tag on merged commit
69+
70+
- name: Create tag on merge commit
7071
run: |
71-
git tag ${{ steps.get_tag.outputs.tag }} ${{ github.sha }} --force
72-
git push origin ${{ steps.get_tag.outputs.tag }} --force
73-
72+
git tag -f ${{ steps.get_tag.outputs.tag }} ${{ github.sha }}
73+
git push -f origin ${{ steps.get_tag.outputs.tag }}
74+
75+
# Get the latest published release
76+
- name: Get the latest published release
77+
id: latest_release
78+
uses: actions/github-script@v7
79+
with:
80+
script: |
81+
try {
82+
const rel = await github.rest.repos.getLatestRelease({
83+
owner: context.repo.owner,
84+
repo: context.repo.repo
85+
});
86+
core.setOutput('tag', rel.data.tag_name);
87+
} catch (_) {
88+
core.setOutput('tag', '');
89+
}
90+
91+
# Compare current tag vs latest using semver-utils
92+
- name: Semver compare
93+
id: semver
94+
uses: madhead/[email protected]
95+
with:
96+
version: ${{ steps.get_tag.outputs.tag }}
97+
compare-to: ${{ steps.latest_release.outputs.tag }}
98+
99+
# Derive flags: prerelease? make_latest?
100+
- name: Calculate publish flags
101+
id: flags
102+
uses: actions/github-script@v7
103+
with:
104+
script: |
105+
const tag = '${{ steps.get_tag.outputs.tag }}'; // v0.31.5-rc1
106+
const m = tag.match(/^v(\d+\.\d+\.\d+)(-rc\d+)?$/);
107+
if (!m) {
108+
core.setFailed(`❌ tag '${tag}' must match 'vX.Y.Z' or 'vX.Y.Z-rcN'`);
109+
return;
110+
}
111+
const version = m[1] + (m[2] ?? ''); // 0.31.5‑rc1
112+
const isRc = Boolean(m[2]);
113+
core.setOutput('is_rc', isRc);
114+
const outdated = '${{ steps.semver.outputs.comparison-result }}' === '<';
115+
core.setOutput('make_latest', isRc || outdated ? 'false' : 'legacy');
116+
117+
# Publish draft release with correct flags
74118
- name: Publish draft release
75119
uses: actions/github-script@v7
76120
with:
77121
script: |
78122
const tag = '${{ steps.get_tag.outputs.tag }}';
79123
const releases = await github.rest.repos.listReleases({
80124
owner: context.repo.owner,
81-
repo: context.repo.repo
125+
repo: context.repo.repo
82126
});
83-
84-
const release = releases.data.find(r => r.tag_name === tag && r.draft);
85-
if (!release) {
86-
throw new Error(`Draft release with tag ${tag} not found`);
87-
}
88-
127+
const draft = releases.data.find(r => r.tag_name === tag && r.draft);
128+
if (!draft) throw new Error(`Draft release for ${tag} not found`);
89129
await github.rest.repos.updateRelease({
90-
owner: context.repo.owner,
91-
repo: context.repo.repo,
92-
release_id: release.id,
93-
draft: false
130+
owner: context.repo.owner,
131+
repo: context.repo.repo,
132+
release_id: draft.id,
133+
draft: false,
134+
prerelease: ${{ steps.flags.outputs.is_rc }},
135+
make_latest: '${{ steps.flags.outputs.make_latest }}'
94136
});
95-
96-
console.log(`✅ Published release for ${tag}`);
137+
138+
console.log(`🚀 Published release for ${tag}`);

‎.github/workflows/pull-requests.yaml‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,20 @@ jobs:
1212
contents: read
1313
packages: write
1414

15+
# ─────────────────────────────────────────────────────────────
16+
# Run automatically for internal PRs (same repo).
17+
# For external PRs (forks) require the "ok‑to‑test" label.
18+
# Never run when the PR carries the "release" label.
19+
# ─────────────────────────────────────────────────────────────
1520
if: |
16-
contains(github.event.pull_request.labels.*.name, 'ok-to-test') &&
17-
!contains(github.event.pull_request.labels.*.name, 'release')
21+
!contains(github.event.pull_request.labels.*.name, 'release') &&
22+
(
23+
github.event.pull_request.head.repo.full_name == github.repository ||
24+
(
25+
github.event.pull_request.head.repo.full_name != github.repository &&
26+
contains(github.event.pull_request.labels.*.name, 'ok-to-test')
27+
)
28+
)
1829
1930
steps:
2031
- name: Checkout code
@@ -30,10 +41,8 @@ jobs:
3041
password: ${{ secrets.GITHUB_TOKEN }}
3142
registry: ghcr.io
3243

33-
- name: make build
34-
run: |
35-
make build
44+
- name: Build
45+
run: make build
3646

37-
- name: make test
38-
run: |
39-
make test
47+
- name: Test
48+
run: make test

0 commit comments

Comments
 (0)