forked from google-github-actions/.github
-
Notifications
You must be signed in to change notification settings - Fork 0
106 lines (97 loc) · 3.41 KB
/
release.yml
File metadata and controls
106 lines (97 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
name: 'Release'
on:
workflow_call:
secrets:
ACTIONS_BOT_TOKEN:
required: true
permissions:
attestations: 'write'
contents: 'write'
packages: 'write'
defaults:
run:
shell: 'bash'
jobs:
create-release:
if: |-
${{ startsWith(github.event.head_commit.message, 'Release: v') }}
runs-on: 'ubuntu-latest'
outputs:
created: '${{ steps.create-release.outputs.created || false }}'
tag: '${{ steps.create-release.outputs.tag }}'
version: '${{ steps.create-release.outputs.version }}'
steps:
- name: 'Create release'
id: 'create-release'
uses: 'abcxyz/actions/.github/actions/create-release@main' # ratchet:exclude
with:
github_token: '${{ secrets.ACTIONS_BOT_TOKEN }}'
expected_email: '72759630+google-github-actions-bot@users.noreply.github.com'
publish-release:
runs-on: 'ubuntu-latest'
needs:
- 'create-release'
steps:
- name: 'Publish release'
env:
GH_TOKEN: '${{ secrets.ACTIONS_BOT_TOKEN }}'
RELEASE_VERSION: 'v${{ needs.create-release.outputs.version }}'
REPO: '${{ github.repository }}'
run: |-
gh release edit "${RELEASE_VERSION}" \
--repo "${REPO}" \
--draft=false
update-floating-tag:
runs-on: 'ubuntu-latest'
needs:
- 'create-release'
steps:
- name: 'Update floating tag'
uses: 'actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea' # ratchet:actions/github-script@v7
env:
RELEASE_VERSION: 'v${{ needs.create-release.outputs.version }}'
REPO: '${{ github.repository }}'
with:
github-token: '${{ secrets.ACTIONS_BOT_TOKEN }}'
script: |-
const tag = process.env.RELEASE_VERSION;
const major = tag.split(".")[0];
const githubActionsRef = `${process.env.REPO}@${major}`
// Try to update the ref first. If that fails, it probably does not
// exist yet, and we should create it.
try {
await github.rest.git.updateRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "tags/" + major,
sha: context.sha,
force: true,
});
core.info(`Updated ${githubActionsRef} to ${context.sha} (${tag})`);
} catch (err) {
core.warning(`Failed to create tag ${major}: ${err}`);
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "refs/tags/" + major,
sha: context.sha,
});
core.info(`Created ${githubActionsRef} at ${context.sha} (${tag})`);
}
cleanup-failed-release:
if: |-
${{ always() && needs.create-release.outputs.created == 'true' && contains(fromJSON('["failure", "cancelled", "skipped"]'), needs.publish-release.result) }}
runs-on: 'ubuntu-latest'
needs:
- 'create-release'
- 'publish-release'
steps:
- name: 'Cleanup failed release'
env:
GH_TOKEN: '${{ secrets.ACTIONS_BOT_TOKEN }}'
RELEASE_VERSION: 'v${{ needs.create-release.outputs.version }}'
REPO: '${{ github.repository }}'
run: |-
gh release delete "${RELEASE_VERSION}" \
--repo "${REPO}" \
--yes