-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (75 loc) · 2.6 KB
/
create-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
name: Create Release
on:
push:
branches:
- main
paths:
- 'package.json'
jobs:
create-release:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Get current version from package.json
id: current-version
uses: martinbeentjes/[email protected]
- name: Get previous version from package.json
id: previous-version
run: |
git checkout HEAD~1
echo "::set-output name=value::$(npm pkg get version | tr -d '"')"
git checkout -
- name: Check if version has changed
id: version-changed
run: |
if [ "${{ steps.current-version.outputs.current-version }}" != "${{ steps.previous-version.outputs.value }}" ]; then
echo "::set-output name=changed::true"
else
echo "::set-output name=changed::false"
fi
- name: Extract major version
if: steps.version-changed.outputs.changed == 'true'
id: major-version
run: echo "::set-output name=value::$(echo ${{ steps.current-version.outputs.current-version}} | cut -d. -f1)"
- name: Create Release
if: steps.version-changed.outputs.changed == 'true'
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.current-version.outputs.current-version}}
release_name: Release v${{ steps.current-version.outputs.current-version}}
draft: false
prerelease: false
- name: Create or Update Major Version Tag
if: steps.version-changed.outputs.changed == 'true'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
try {
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/v${{ steps.major-version.outputs.value }}',
sha: context.sha
});
} catch (error) {
if (error.status === 422) {
await github.rest.git.updateRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'tags/v${{ steps.major-version.outputs.value }}',
sha: context.sha,
force: true
});
} else {
throw error;
}
}