Skip to content

Commit 19ce71b

Browse files
committed
internal release workflow
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
1 parent cf2bccf commit 19ce71b

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

.github/workflows/.release.yml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# This internal workflow creates a semver signed git tag.
2+
name: .release
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+
version:
16+
description: "Semver version (e.g. v1.2.3)"
17+
required: true
18+
type: string
19+
ref:
20+
description: "Optional Git ref to tag (defaults to main HEAD)"
21+
required: false
22+
type: string
23+
default: refs/heads/main
24+
25+
env:
26+
GITSIGN_VERSION: v0.14.0
27+
28+
jobs:
29+
prepare:
30+
runs-on: ubuntu-latest
31+
steps:
32+
-
33+
name: Show inputs
34+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
35+
env:
36+
INPUT_VERSION: ${{ inputs.version }}
37+
INPUT_REF: ${{ inputs.ref }}
38+
with:
39+
script: |
40+
core.info(`version: ${core.getInput('version')}`);
41+
core.info(`ref: ${core.getInput('ref')}`);
42+
43+
release:
44+
runs-on: ubuntu-latest
45+
environment: release-prod
46+
needs:
47+
- prepare
48+
permissions:
49+
contents: write # required to push the tag
50+
id-token: write # required for keyless gitsign
51+
steps:
52+
-
53+
name: Install npm deps
54+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
55+
with:
56+
script: |
57+
await core.group(`Install npm deps`, async () => {
58+
await exec.exec('npm', ['install', 'semver']);
59+
});
60+
-
61+
name: Check version
62+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
63+
env:
64+
INPUT_VERSION: ${{ inputs.version }}
65+
with:
66+
script: |
67+
const semver = require('semver');
68+
const version = core.getInput('version');
69+
if (!semver.valid(version)) {
70+
core.setFailed(`Invalid version: ${version}`);
71+
}
72+
-
73+
name: GitHub auth token from GitHub App
74+
id: write-app
75+
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
76+
with:
77+
app-id: ${{ secrets.GITHUB_BUILDER_REPO_WRITE_APP_ID }}
78+
private-key: ${{ secrets.GITHUB_BUILDER_REPO_WRITE_APP_PRIVATE_KEY }}
79+
owner: docker
80+
repositories: github-builder
81+
-
82+
name: Checkout
83+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
84+
with:
85+
ref: ${{ inputs.ref }}
86+
fetch-depth: 0
87+
token: ${{ steps.write-app.outputs.token }}
88+
-
89+
name: Ensure tag does not exist
90+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
91+
env:
92+
INPUT_VERSION: ${{ inputs.version }}
93+
with:
94+
script: |
95+
const version = core.getInput('version');
96+
await exec.exec('git', ['rev-parse', '-q', '--verify', `refs/tags/${version}`], {
97+
ignoreReturnCode: true
98+
}).then(res => {
99+
if (res.exitCode === 0) {
100+
throw new Error(`Tag ${version} already exists at ${res.stdout.trim()}`);
101+
}
102+
});
103+
-
104+
name: Install Gitsign
105+
run: |
106+
set -x
107+
go install github.com/sigstore/gitsign@${GITSIGN_VERSION}
108+
gitsign --version
109+
-
110+
name: Configure Git for Gitsign
111+
run: |
112+
set -x
113+
git config user.name "${GITHUB_ACTOR}"
114+
git config user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com"
115+
git config gpg.format x509
116+
git config gpg.x509.program gitsign
117+
git config tag.gpgsign true
118+
git config gitsign.connectorID https://github.com/login/oauth
119+
git config gitsign.tokenProvider github-actions
120+
-
121+
name: Create signed tag
122+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
123+
env:
124+
INPUT_VERSION: ${{ inputs.version }}
125+
with:
126+
script: |
127+
const version = core.getInput('version');
128+
await exec.exec('git', ['tag', '-a', version, '-m', version]);
129+
await exec.exec('git', ['tag', '-v', version]);
130+
-
131+
name: Push tag
132+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
133+
env:
134+
INPUT_VERSION: ${{ inputs.version }}
135+
with:
136+
script: |
137+
const version = core.getInput('version');
138+
await exec.exec('git', ['push', 'origin', `refs/tags/${version}`]);

0 commit comments

Comments
 (0)