-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (68 loc) · 2.37 KB
/
github-release.yml
File metadata and controls
78 lines (68 loc) · 2.37 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
# Given a version, finds a merged release pr with release version in the title and uses pr body to generate release notes
# NOTE: We expected the merged pr title to be `chore: Release ${version}` or `Release ${version}` e.g. `chore: Release 5.2.15` or `Release 5.2.15`
name: Create GitHub Release
on:
workflow_call:
inputs:
version:
required: true
type: string
description: Version to release
secrets:
# In case we want to trigger other workflows like ones that uses pushed tags
GH_PUSH_TOKEN:
required: false
description: GitHub token with push permissions
permissions:
contents: write
jobs:
create_release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Create release notes
uses: actions/github-script@v8
id: release_notes
env:
VERSION: ${{ inputs.version }}
with:
script: |
const version = process.env.VERSION;
let releaseNotes = '';
const prs = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed',
sort: 'updated',
direction: 'desc',
per_page: 50
});
const releasePr = prs.data.find(pr =>
pr.merged_at && pr.title.replace(/^chore:\s*/i, '').startsWith(`Release ${version}`)
);
if (releasePr) {
releaseNotes = releasePr.body.split('<!--')[0].trim();
}
core.setOutput('notes', releaseNotes);
- name: Create GitHub Release
uses: actions/github-script@v8
env:
RELEASE_NOTES: ${{ steps.release_notes.outputs.notes }}
with:
github-token: ${{ secrets.GH_PUSH_TOKEN || github.token }}
script: |
const notes = process.env.RELEASE_NOTES;
const version = '${{ inputs.version }}';
const isPrerelease = /alpha|beta/i.test(version);
await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: version,
name: version,
body: notes,
draft: false,
prerelease: isPrerelease
});