-
Notifications
You must be signed in to change notification settings - Fork 4
173 lines (152 loc) · 5.11 KB
/
release.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
name: Create new release
on:
pull_request:
branches:
- main
types: [closed]
workflow_dispatch:
inputs:
semver:
description: "Semver version"
required: true
default: "minor"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20.x"
- uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- run: npm install -g @angular/[email protected]
- run: npm ci
- run: npm run build
- name: Upload dist artifacts
uses: actions/upload-artifact@v4
with:
name: lib-dist-artifacts
retention-days: 1
path: |
dist
create:
name: Create PR for new release
if: github.event.inputs.semver
runs-on: ubuntu-latest
needs:
- build
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: "20.x"
- name: install dependencies
run: npm ci
- name: setup git config
run: |
# setup the username and email. I tend to use 'GitHub Actions Bot' with no email by default
git config user.name "GitHub Actions Bot"
git config user.email "<[email protected]>"
- name: update version and changelog
working-directory: "projects/ngx-konva"
run: |
npm version ${{ github.event.inputs.semver }} --no-git-tag-version
- name: update version and changelog
run: |
npm version ${{ github.event.inputs.semver }} --no-git-tag-version
- name: Get new version from package.json
working-directory: "projects/ngx-konva"
run: |
pkg_version=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]')
echo "PACKAGE_VERSION=$pkg_version" >> $GITHUB_ENV
echo $PACKAGE_VERSION
- name: Create pull request
id: pr-create
uses: actions/github-script@v7
with:
github-token: ${{ github.token }}
script: |
const res = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "refs/tags/tagname",
head: "release_${{ env.PACKAGE_VERSION }}",
base: "main",
title: "Release: [v${{ env.PACKAGE_VERSION }}]",
body: `PR created by Github Actions bot in order to release new version **v${{ env.PACKAGE_VERSION }}**.`
})
return res.data.number;
- name: Request and assign review
uses: actions/github-script@v7
with:
github-token: ${{ github.token }}
script: |
await github.rest.pulls.requestReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: ${{ steps.pr-create.outputs.result }},
reviewers: ['${{ github.actor }}']
});
await github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ steps.pr-create.outputs.result }},
assignees: ['${{ github.actor }}']
});
publish:
name: Tagging and publish new release
runs-on: ubuntu-latest
if: (github.event.pull_request.merged == true) && (startsWith(github.event.pull_request.title, 'Release:'))
needs:
- build
steps:
- run: |
echo ${{ github.event.pull_request.title}}
echo "TAG=$(echo '${{ github.event.pull_request.title}}' | awk -F '[][]' '{print $2}')" >> $GITHUB_ENV
- name: Checkout
if: "${{ env.TAG }}"
uses: actions/checkout@v4
- name: Download dist artifacts
uses: actions/download-artifact@v4
with:
name: lib-dist-artifacts
path: dist/
- name: Tagging
if: "${{ env.TAG }}"
run: |
git tag ${{ env.TAG }}
git push origin --tags
- name: Create and publish release on tag
if: "${{ env.TAG }}"
uses: actions/github-script@v7
with:
github-token: ${{ github.token }}
script: |
github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: "${{ env.TAG }}",
target_commitish: "${{ github.sha}}",
name: "${{ env.TAG }}"
})
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"
always-auth: "true"
- name: NPM package publish
if: "${{ env.TAG }}"
working-directory: "dist/ngx-konva"
run: |
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}