Skip to content

Commit 3b2370a

Browse files
committed
add release.yml, update node.js.yml
1 parent 9899152 commit 3b2370a

2 files changed

Lines changed: 102 additions & 14 deletions

File tree

.github/workflows/node.js.yml

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,41 @@
1-
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3-
41
name: Node.js CI
52

63
on:
74
push:
8-
branches: [ master ]
5+
branches: [master, main]
96
pull_request:
10-
branches: [ master ]
117
types: [opened, synchronize, reopened]
128

139
permissions:
1410
contents: read
1511

1612
jobs:
1713
build:
18-
1914
runs-on: ubuntu-latest
2015

2116
strategy:
2217
matrix:
23-
node-version: [22, 24]
18+
node-version: ${{ fromJson(needs.get-lts.outputs.lts) }}
2419

2520
steps:
26-
- uses: actions/checkout@v6
27-
- name: Use Node.js ${{ matrix.node-version }}
28-
uses: actions/setup-node@v6
29-
with:
30-
node-version: ${{ matrix.node-version }}
31-
- run: npm ci
32-
- run: npm test
21+
- uses: actions/checkout@v6
22+
- name: Use Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v6
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
- run: npm ci
27+
- run: npm test
28+
29+
get-lts:
30+
runs-on: ubuntu-latest
31+
permissions:
32+
contents: read
33+
steps:
34+
- id: get
35+
uses: msimerson/node-lts-versions@v1
36+
outputs:
37+
active: ${{ steps.get.outputs.active }}
38+
maintenance: ${{ steps.get.outputs.maintenance }}
39+
lts: ${{ steps.get.outputs.lts }}
40+
current: ${{ steps.get.outputs.current }}
41+
min: ${{ steps.get.outputs.min }}

.github/workflows/release.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: release
2+
3+
on:
4+
push:
5+
branches: [master, main]
6+
paths:
7+
- package.json
8+
9+
jobs:
10+
version:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
outputs:
15+
changed: ${{ steps.check.outputs.changed }}
16+
version: ${{ steps.check.outputs.version }}
17+
steps:
18+
- uses: actions/checkout@v6
19+
with:
20+
fetch-depth: 2 # last 2 commits
21+
- name: check version change
22+
id: check
23+
run: |
24+
PREV_VERSION=$(git show HEAD^:package.json | jq -r .version)
25+
CURR_VERSION=$(jq -r .version package.json)
26+
echo "Previous: $PREV_VERSION"
27+
echo "Current: $CURR_VERSION"
28+
if [ "$PREV_VERSION" != "$CURR_VERSION" ]; then
29+
echo "changed=true" >> $GITHUB_OUTPUT
30+
else
31+
echo "changed=false" >> $GITHUB_OUTPUT
32+
fi
33+
echo "version=$CURR_VERSION" >> $GITHUB_OUTPUT
34+
35+
build:
36+
needs: version
37+
if: needs.version.outputs.changed == 'true'
38+
runs-on: ubuntu-latest
39+
permissions:
40+
contents: read
41+
steps:
42+
- uses: actions/setup-node@v6
43+
with:
44+
node-version: "24"
45+
- uses: actions/checkout@v6
46+
- run: npm ci || npm install
47+
- run: npm test
48+
49+
create-release:
50+
needs: [build, version]
51+
runs-on: ubuntu-latest
52+
permissions:
53+
contents: write # needed to create tags and releases
54+
steps:
55+
- uses: actions/checkout@v6
56+
with:
57+
fetch-depth: 0 # fetch all tags
58+
- id: tag-check
59+
run: |
60+
TAG="v${{ needs.version.outputs.version }}"
61+
if git rev-parse "$TAG" >/dev/null 2>&1; then
62+
echo "exists=true" >> $GITHUB_OUTPUT
63+
else
64+
echo "exists=false" >> $GITHUB_OUTPUT
65+
fi
66+
- name: Create Git tag and push
67+
if: steps.tag-check.outputs.exists == 'false'
68+
run: |
69+
git config user.name "github-actions"
70+
git config user.email "github-actions@github.com"
71+
git tag v${{ needs.version.outputs.version }}
72+
git push origin v${{ needs.version.outputs.version }}
73+
- name: Create GitHub Release
74+
if: steps.tag-check.outputs.exists == 'false'
75+
uses: softprops/action-gh-release@v2
76+
with:
77+
tag_name: v${{ needs.version.outputs.version }}
78+
name: ${{ needs.version.outputs.version }}
79+
generate_release_notes: false

0 commit comments

Comments
 (0)