-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (95 loc) · 3.32 KB
/
github-release.yml
File metadata and controls
111 lines (95 loc) · 3.32 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
107
108
109
110
111
name: Publish GitHub Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
workflow_dispatch:
inputs:
tag:
description: 'Release tag to publish, for example v0.3.2'
required: true
type: string
permissions:
contents: write
concurrency:
group: github-release-${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref_name }}
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout release tag
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref }}
- name: Resolve release metadata
id: release
shell: bash
run: |
set -euo pipefail
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
tag="${{ inputs.tag }}"
else
tag="${GITHUB_REF_NAME}"
fi
if [[ ! "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Release tag must match vX.Y.Z, received: $tag" >&2
exit 1
fi
version="${tag#v}"
notes_path="docs/plan/releases/release_notes_${tag}.md"
if [[ ! -f "$notes_path" ]]; then
echo "Missing release notes: $notes_path" >&2
exit 1
fi
package_version="$(node -p "require('./package.json').version")"
if [[ "$package_version" != "$version" ]]; then
echo "package.json version ($package_version) must match tag version ($version)" >&2
exit 1
fi
echo "tag=$tag" >> "$GITHUB_OUTPUT"
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "notes_path=$notes_path" >> "$GITHUB_OUTPUT"
- name: Run release policy checks
run: npm run release:check
- name: Create or update GitHub Release
uses: actions/github-script@v7
env:
RELEASE_TAG: ${{ steps.release.outputs.tag }}
RELEASE_VERSION: ${{ steps.release.outputs.version }}
RELEASE_NOTES_PATH: ${{ steps.release.outputs.notes_path }}
with:
script: |
const fs = require('fs');
const { owner, repo } = context.repo;
const tag_name = process.env.RELEASE_TAG;
const name = `Recall ${tag_name}`;
const body = fs.readFileSync(process.env.RELEASE_NOTES_PATH, 'utf8');
try {
const existing = await github.rest.repos.getReleaseByTag({ owner, repo, tag: tag_name });
await github.rest.repos.updateRelease({
owner,
repo,
release_id: existing.data.id,
tag_name,
name,
body,
draft: false,
prerelease: false,
});
core.info(`Updated GitHub Release ${tag_name}`);
} catch (error) {
if (error.status !== 404) throw error;
await github.rest.repos.createRelease({
owner,
repo,
tag_name,
name,
body,
draft: false,
prerelease: false,
generate_release_notes: false,
});
core.info(`Created GitHub Release ${tag_name}`);
}