Skip to content

Commit 0815535

Browse files
committed
internal promote workflow
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent d8b8c1b commit 0815535

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

.github/workflows/.promote.yml

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# This internal workflow promotes a semver tag to a major release (e.g. v1.2.3 -> v1)
2+
name: .promote
3+
4+
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
5+
permissions:
6+
contents: read
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
on:
13+
workflow_dispatch:
14+
inputs:
15+
tag:
16+
description: "Existing semver tag to promote (e.g. v1.2.3)"
17+
required: true
18+
type: string
19+
20+
jobs:
21+
prepare:
22+
runs-on: ubuntu-latest
23+
steps:
24+
-
25+
name: Show inputs
26+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
27+
env:
28+
INPUT_TAG: ${{ inputs.tag }}
29+
with:
30+
script: |
31+
core.info(`tag: ${core.getInput('tag')}`);
32+
33+
promote:
34+
runs-on: ubuntu-latest
35+
environment: release-prod
36+
needs:
37+
- prepare
38+
permissions:
39+
contents: write # required to push the tag
40+
steps:
41+
-
42+
name: Install npm deps
43+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
44+
with:
45+
script: |
46+
await core.group(`Install npm deps`, async () => {
47+
await exec.exec('npm', ['install', 'semver']);
48+
});
49+
-
50+
name: Check tag
51+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
52+
env:
53+
INPUT_TAG: ${{ inputs.tag }}
54+
with:
55+
script: |
56+
const semver = require('semver');
57+
const tag = core.getInput('tag');
58+
if (!semver.valid(tag)) {
59+
core.setFailed(`Invalid tag: ${tag}`);
60+
}
61+
const major = `v${semver.major(tag)}`;
62+
core.info(`MAJOR_TAG=${major}`);
63+
core.exportVariable('MAJOR_TAG', major);
64+
-
65+
name: GitHub auth token from GitHub App
66+
id: write-app
67+
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
68+
with:
69+
app-id: ${{ secrets.GITHUB_BUILDER_REPO_WRITE_APP_ID }}
70+
private-key: ${{ secrets.GITHUB_BUILDER_REPO_WRITE_APP_PRIVATE_KEY }}
71+
owner: docker
72+
repositories: github-builder
73+
-
74+
name: Checkout
75+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
76+
with:
77+
fetch-depth: 0
78+
token: ${{ steps.write-app.outputs.token }}
79+
-
80+
name: Configure Git
81+
run: |
82+
set -x
83+
git config user.name "${GITHUB_ACTOR}"
84+
git config user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com"
85+
-
86+
name: Resolve target tag -> commit
87+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
88+
env:
89+
INPUT_TAG: ${{ inputs.tag }}
90+
with:
91+
script: |
92+
const tag = core.getInput('tag');
93+
await exec.exec('git', ['rev-parse', '-q', '--verify', `refs/tags/${tag}`], {
94+
ignoreReturnCode: true
95+
}).then(res => {
96+
if (res.exitCode !== 0) {
97+
throw new Error(`Tag ${tag} does not exist`);
98+
}
99+
});
100+
await exec.exec('git', ['rev-list', '-n', '1', `refs/tags/${tag}`]).then(res => {
101+
const sha = res.stdout.trim();
102+
core.info(`Tag ${tag} resolves to commit ${sha}`);
103+
core.exportVariable('COMMIT_SHA', sha);
104+
});
105+
-
106+
name: Move major tag to target commit and push
107+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
108+
env:
109+
INPUT_TAG: ${{ inputs.tag }}
110+
INPUT_MAJOR-TAG: ${{ env.MAJOR_TAG }}
111+
INPUT_COMMIT-SHA: ${{ env.COMMIT_SHA }}
112+
with:
113+
script: |
114+
const tag = core.getInput('tag');
115+
const majorTag = core.getInput('major-tag');
116+
const commitSha = core.getInput('commit-sha');
117+
await exec.exec('git', ['tag', '-a', '-f', majorTag, '-m', tag, commitSha]);
118+
await exec.exec('git', ['tag', '-v', majorTag]);
119+
await exec.exec('git', ['push', 'origin', `refs/tags/${majorTag}`, '--force']); // force push is required to move the tag

0 commit comments

Comments
 (0)