Skip to content

Commit 1f03241

Browse files
authored
feat: Add tag creation workflow (#24)
This tag is used to control which commit a rollout of required workflows points at.
1 parent b2ff932 commit 1f03241

2 files changed

Lines changed: 105 additions & 0 deletions

File tree

.github/minty.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: 'minty.abcxyz.dev/v2'
2+
3+
rule:
4+
if: |-
5+
assertion.iss == issuers.github &&
6+
assertion.repository_owner_id == '198259824' &&
7+
assertion.repository_id == '1238099503'
8+
9+
scope:
10+
create-tag:
11+
rule:
12+
if: |-
13+
assertion.ref == 'refs/heads/main' &&
14+
assertion.event_name == 'workflow_dispatch'
15+
repositories:
16+
- 'workflows'
17+
permissions:
18+
contents: 'write'

.github/workflows/create_tag.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: 'Create Tag'
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag_name:
7+
description: 'The name of the tag to create (e.g., v1.0.0)'
8+
required: true
9+
type: 'string'
10+
tag_commit:
11+
description: 'The commit SHA, branch, or tag to place the tag on'
12+
required: true
13+
type: 'string'
14+
15+
permissions:
16+
contents: 'read'
17+
id-token: 'write'
18+
19+
jobs:
20+
create-tag:
21+
runs-on: 'ubuntu-latest'
22+
steps:
23+
- id: 'auth'
24+
name: 'Authenticate to Google Cloud'
25+
uses: 'google-github-actions/auth@6fc4af4b145ae7821d527454aa9bd537d1f2dc5f' # ratchet:google-github-actions/auth@v2
26+
with:
27+
create_credentials_file: false
28+
export_environment_variables: false
29+
workload_identity_provider: '${{ vars.TOKEN_MINTER_WIF_PROVIDER }}'
30+
service_account: '${{ vars.TOKEN_MINTER_WIF_SERVICE_ACCOUNT }}'
31+
token_format: 'id_token'
32+
id_token_audience: '${{ vars.TOKEN_MINTER_SERVICE_AUDIENCE }}'
33+
id_token_include_email: true
34+
35+
- name: 'Mint Token'
36+
id: 'mint-token'
37+
uses: 'abcxyz/github-token-minter/.github/actions/minty@6ec95c40b5f558c0848997fcb27ccb06e31e7172' # ratchet:abcxyz/github-token-minter/.github/actions/minty@main
38+
with:
39+
id_token: '${{ steps.auth.outputs.id_token }}'
40+
service_url: '${{ vars.TOKEN_MINTER_SERVICE_URL }}'
41+
requested_permissions: |-
42+
{
43+
"scope": "create-tag",
44+
"repositories": ["${{ github.event.repository.name }}"],
45+
"permissions": {
46+
"contents": "write"
47+
}
48+
}
49+
50+
- name: 'Create Tag'
51+
uses: 'actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea' # ratchet:actions/github-script@v7
52+
env:
53+
TAG_NAME: '${{ inputs.tag_name }}'
54+
TAG_COMMIT: '${{ inputs.tag_commit }}'
55+
with:
56+
github-token: '${{ steps.mint-token.outputs.token }}'
57+
script: |
58+
const tagName = process.env.TAG_NAME;
59+
const tagCommit = process.env.TAG_COMMIT;
60+
61+
// Resolve the commitish to a full SHA
62+
let resolvedSha;
63+
try {
64+
const commit = await github.rest.repos.getCommit({
65+
owner: context.repo.owner,
66+
repo: context.repo.repo,
67+
ref: tagCommit,
68+
});
69+
resolvedSha = commit.data.sha;
70+
core.info(`Resolved "${tagCommit}" to SHA: ${resolvedSha}`);
71+
} catch (err) {
72+
core.setFailed(`Failed to resolve commitish "${tagCommit}": ${err.message}`);
73+
return;
74+
}
75+
76+
// Create the tag reference
77+
try {
78+
await github.rest.git.createRef({
79+
owner: context.repo.owner,
80+
repo: context.repo.repo,
81+
ref: `refs/tags/${tagName}`,
82+
sha: resolvedSha,
83+
});
84+
core.info(`Successfully created tag ${tagName} on commit ${resolvedSha}`);
85+
} catch (err) {
86+
core.setFailed(`Failed to create tag ${tagName}: ${err.message}`);
87+
}

0 commit comments

Comments
 (0)