-
Notifications
You must be signed in to change notification settings - Fork 9
140 lines (119 loc) · 4.92 KB
/
autorelease.yml
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Automatically Create a Release when PR is merged to main with one of the following
# labels: "patch", "minor", "major", "alpha", "beta", "rc".
name: Auto Release
# Controls when the action will run.
on:
# Triggers the workflow only when merging pull request to the main branch.
pull_request:
types: [closed]
branches: [master]
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
permissions:
contents: write
deployments: write
pull-requests: read
packages: write
# Only run on merged PRs with an appropriate label.
if: |
github.event.pull_request.merged &&
(
contains(github.event.pull_request.labels.*.name, 'patch') ||
contains(github.event.pull_request.labels.*.name, 'minor') ||
contains(github.event.pull_request.labels.*.name, 'major') ||
contains(github.event.pull_request.labels.*.name, 'alpha') ||
contains(github.event.pull_request.labels.*.name, 'beta') ||
contains(github.event.pull_request.labels.*.name, 'rc')
)
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
with:
ref: ${{ github.base_ref }}
fetch-depth: 0
- name: Setup node
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
# Uses 'npm ci' instead of 'npm install'. See https://docs.npmjs.com/cli/v7/commands/npm-ci
- name: Install dependencies
run: npm ci
- name: Set Git user
run: |
git config --global user.email "[email protected]"
git config --global user.name "Github Action"
# Run 'npm run package' and commit dist folder if there are any changes.
- name: npm run package
run: |
npm run publish
if [ $(git status | grep "core\/dist\/") ]
then
git add core/dist
git commit -m 'Packaging build'
git push origin master
fi
# Increment version based on label
- name: Patch Release tag
if: ${{ contains( github.event.pull_request.labels.*.name, 'patch') }}
run: npm version patch
- name: Minor Release tag
if: ${{ contains( github.event.pull_request.labels.*.name, 'minor') }}
run: npm version minor
- name: Major Release tag
if: ${{ contains( github.event.pull_request.labels.*.name, 'major') }}
run: npm version major
- name: Alpha Release tag
if: ${{ contains( github.event.pull_request.labels.*.name, 'alpha') }}
run: |
npm version prerelease --preid alpha
echo "PRERELEASE=true" >> $GITHUB_ENV
- name: Beta Release tag
if: ${{ contains( github.event.pull_request.labels.*.name, 'beta') }}
run: |
npm version prerelease --preid beta
echo "PRERELEASE=true" >> $GITHUB_ENV
- name: RC Release tag
if: ${{ contains( github.event.pull_request.labels.*.name, 'rc') }}
run: |
npm version prerelease --preid rc
echo "PRERELEASE=true" >> $GITHUB_ENV
# Push commits back to origin repo.
- name: Push Changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.base_ref }}
tags: true
- name: Set enviroment variables for release notes.
run: |
echo "RELEASE_TAG=$(git tag --sort=-taggerdate | head -1)" >> $GITHUB_ENV
echo "PREVIOUS_TAG=$(git tag --sort=-taggerdate | sed -n '2 p')" >> $GITHUB_ENV
- name: Create Release Notes
id: release_notes
run: |
# Scrape release notes for this release from the full changelog.
release_notes=$(./node_modules/.bin/auto-changelog --stdout | awk "/\[$RELEASE_TAG\]/{flag=1; next} /\[$PREVIOUS_TAG\]/{flag=0} flag")
# Escape whitespace characters to ensure that multiline content outputs correctly.
release_notes="${release_notes//'%'/'%25'}"
release_notes="${release_notes//$'\n'/'%0A'}"
release_notes="${release_notes//$'\r'/'%0D'}"
# Expose the release notes as an output variable.
echo "::set-output name=release_notes::$release_notes"
- name: Update Github Release with changelog notes.
uses: meeDamian/[email protected]
with:
token: ${{ secrets.ADMIN_GITHUB_TOKEN }}
tag: ${{ env.RELEASE_TAG }}
body: ${{steps.release_notes.outputs.release_notes}}
allow_override: true
prerelease: ${{ env.PRERELEASE }}
# Publish updated package to NPM.
- name: Publish to NPM
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
access: 'public'