-
Notifications
You must be signed in to change notification settings - Fork 1
72 lines (63 loc) · 2.07 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
69
70
71
72
name: Build and Release Source Code
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
release:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- name: Get Latest Release Version
id: get_version
run: |
LATEST_TAG=$(git ls-remote --tags origin | grep -o 'refs/tags/v[0-9]*\.[0-9]*\.[0-9]*$' | sed 's/refs\/tags\///' | sort -V | tail -n 1)
if [[ -z "$LATEST_TAG" ]]; then
TAG_NAME="v1.0.0" # Start from v1.0.0 if no tags found
else
if [[ $LATEST_TAG =~ v([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
MAJOR=${BASH_REMATCH[1]}
MINOR=${BASH_REMATCH[2]}
PATCH=${BASH_REMATCH[3]}
PATCH=$((PATCH + 1)) # Increment patch version
TAG_NAME="v${MAJOR}.${MINOR}.${PATCH}"
else
TAG_NAME="v1.0.1" # Fallback if no valid tag found
fi
fi
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
- name: Create Git Tag
run: |
git tag ${{ env.TAG_NAME }}
git push origin ${{ env.TAG_NAME }} || echo "Tag already exists, skipping push."
- name: Get Changelog
id: changelog
run: |
CHANGELOG=$(git log --pretty=format:'- %s' $(git describe --tags --abbrev=0)..HEAD)
echo "CHANGELOG=$CHANGELOG" >> $GITHUB_ENV
- name: Create GitHub Release
uses: softprops/[email protected]
with:
tag_name: ${{ env.TAG_NAME }}
body: |
## Changelog
${{ env.CHANGELOG }}
prerelease: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}