-
Notifications
You must be signed in to change notification settings - Fork 2
77 lines (77 loc) · 2.69 KB
/
release.yml
File metadata and controls
77 lines (77 loc) · 2.69 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
name: Release Package
on:
# trigger release on push to main branch
push:
branches:
- main
# allow triggering of manual releases off branches for hot fixes
workflow_dispatch:
inputs:
dryrun:
description: 'Dry Run (create release draft)'
required: false
default: true
type: boolean
jobs:
get-version:
name: Get package.json "version"
runs-on: ubuntu-latest
# map the job outputs to step outputs
outputs:
version: ${{ steps.parse-step.outputs.version }}
steps:
- uses: actions/checkout@v2
- name: Parse Version From package.json
id: parse-step
run: |
regex='"version" *: *"([0-9]+\.[0-9]+\.[0-9]+)"'
[[ `cat package.json` =~ $regex ]] && echo "::set-output name=version::${BASH_REMATCH[1]}"
check-version-changelog:
name: Check Version & CHANGELOG
runs-on: ubuntu-latest
needs: get-version
steps:
- uses: actions/checkout@v2
- name: Verify the "version" in package.json hasn't already been released
run: |
git fetch --prune --unshallow --tags
tag_match=`git tag -l v${{ needs.get-version.outputs.version }}`
[[ -z "$tag_match" ]]
- name: Check CHANGELOG.md has notes for the package.json "version"
run: |
grep "## *\[${{ needs.get-version.outputs.version }}\]" CHANGELOG.md
create-release:
name: Create Github Release
runs-on: ubuntu-latest
needs: [get-version, check-version-changelog]
steps:
- uses: actions/checkout@v2
# script to scrape changelog. it is in-line instead of referencing a
# file so it'l work calls from external repositories
- name: Scrape CHANGELOG
shell: python
run: |
import re
regex = re.compile('^## *\[[0-9]+.[0-9]+.[0-9]+\]')
with open('CHANGELOG.md') as f:
output_f = open('RELEASE_NOTES', 'w')
line = f.readline()
read = False
while line:
if regex.match(line):
if read: break
read = True
if read: output_f.write(line)
line = f.readline()
output_f.close()
- name: Tag & Create Github Release
# retrieve version and release notes
# Use Github CLI to tag and create the release
run: |
VERSION=${{ needs.get-version.outputs.version }}
RELEASE_NOTES=`cat RELEASE_NOTES`
rm RELEASE_NOTES
gh release create "v$VERSION" -t "v$VERSION" -n "$RELEASE_NOTES" $DRYRUN
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DRYRUN: "${{ inputs.dryrun && '-d' || '' }}"