-
Notifications
You must be signed in to change notification settings - Fork 1
68 lines (60 loc) · 1.79 KB
/
node.js.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
name: Create Release
on:
push:
branches: ["main"]
paths:
- 'package.json'
pull_request:
branches: ["main"]
paths:
- 'package.json'
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get Version from package.json
id: package_version
run: |
VERSION=$(node -p "require('./package.json').version")
echo "VERSION=v${VERSION}" >> $GITHUB_ENV
- name: Check if tag exists
id: check_tag
run: |
if git rev-parse "${{ env.VERSION }}" >/dev/null 2>&1; then
echo "Tag already exists, skipping release"
echo "TAG_EXISTS=true" >> $GITHUB_ENV
else
echo "TAG_EXISTS=false" >> $GITHUB_ENV
fi
- name: Get Changelog
if: env.TAG_EXISTS == 'false'
id: changelog
run: |
PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$PREV_TAG" ]; then
CHANGELOG=$(git log --pretty=format:'- %s')
else
CHANGELOG=$(git log --pretty=format:'- %s' ${PREV_TAG}..HEAD)
fi
echo "CHANGELOG<<EOF" >> $GITHUB_ENV
echo "$CHANGELOG" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Create Git Tag
if: env.TAG_EXISTS == 'false'
run: |
git tag ${{ env.VERSION }}
git push origin ${{ env.VERSION }}
- name: Create GitHub Release
if: env.TAG_EXISTS == 'false'
uses: softprops/[email protected]
with:
tag_name: ${{ env.VERSION }}
body: |
## Changelog
${{ env.CHANGELOG }}
prerelease: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}