-
Notifications
You must be signed in to change notification settings - Fork 2
79 lines (79 loc) · 3.18 KB
/
pull-request.yml
File metadata and controls
79 lines (79 loc) · 3.18 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
name: Pull Request
on:
# trigger on pull request to main
pull_request:
branches:
- main
# allow triggering manually for debugging & testing workflow
workflow_dispatch:
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
check-version-incremented:
# checks that one of the MAJOR.MINOR.PATCH versions is updated by 1, all trailing versions must be 0
name: Check version incremented
runs-on: ubuntu-latest
needs: get-version
steps:
- uses: actions/checkout@v2
with:
# check out the branch PR is merging into
ref: ${{ github.base_ref }}
- name: Fetch version From package.json from base branch
run: |
regex='"version" *: *"([0-9]+\.[0-9]+\.[0-9]+)"'
[[ `cat package.json` =~ $regex ]] && echo "OLD_VERSION=${BASH_REMATCH[1]}" >> $GITHUB_ENV
# script to validate version chnage. it is in-line instead of referencing a
# file so it'l work calls from external repositories
- name: Compare pull request version change against base branch version
run: |
VERSION=${{ needs.get-version.outputs.version }}
echo "Checking version change from $OLD_VERSION to $VERSION"
IFS='.'
read -a OLD <<< "$OLD_VERSION"
read -a NEW <<< "$VERSION"
error () { echo $1; exit 1; }
if [ ${NEW[0]} -eq ${OLD[0]} ] ; then
if [ ${NEW[1]} -eq ${OLD[1]} ] ; then
if [ $(( ${NEW[2]} - ${OLD[2]} )) -ne 1 ]; then
error "PATCH version must increment by 1"
fi
elif [ $(( ${NEW[1]} - ${OLD[1]} )) -eq 1 ] ; then
if [ ${NEW[2]} -ne 0 ] ; then
error "PATCH version must be set to 0"
fi
else
error "MINOR version incremented incorrectly from ${OLD[1]} to ${NEW[1]}"
fi
elif [ $(( ${NEW[0]} - ${OLD[0]} )) -eq 1 ] ; then
if [[ ${NEW[1]} -ne 0 || ${NEW[2]} -ne 0 ]] ; then
error "MINOR and PATCH version must be set to 0"
fi
else
error "MAJOR version incremented incorrectly from ${OLD[0]} to ${NEW[0]}"
fi