forked from lsongdev/node-dns
-
Notifications
You must be signed in to change notification settings - Fork 0
94 lines (89 loc) · 2.65 KB
/
Copy pathrelease.yml
File metadata and controls
94 lines (89 loc) · 2.65 KB
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
name: release
on:
push:
branches: [master, main]
paths:
- package.json
jobs:
version:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
changed: ${{ steps.check.outputs.changed }}
version: ${{ steps.check.outputs.version }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 2 # last 2 commits
- name: check version change
id: check
run: |
PREV_VERSION=$(git show HEAD^:package.json | jq -r .version)
CURR_VERSION=$(jq -r .version package.json)
echo "Previous: $PREV_VERSION"
echo "Current: $CURR_VERSION"
if [ "$PREV_VERSION" != "$CURR_VERSION" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "changed=false" >> $GITHUB_OUTPUT
fi
echo "version=$CURR_VERSION" >> $GITHUB_OUTPUT
build:
needs: version
if: needs.version.outputs.changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/setup-node@v6
with:
node-version: "24"
- uses: actions/checkout@v6
- run: npm ci
- run: npm test
release:
needs: [build, version]
runs-on: ubuntu-latest
permissions:
contents: write # needed to create tags and releases
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0 # fetch all tags
- id: tag-check
run: |
TAG="v${{ needs.version.outputs.version }}"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Create Git tag and push
if: steps.tag-check.outputs.exists == 'false'
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git tag v${{ needs.version.outputs.version }}
git push origin v${{ needs.version.outputs.version }}
- name: Create GitHub Release
if: steps.tag-check.outputs.exists == 'false'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.version.outputs.version }}
name: ${{ needs.version.outputs.version }}
generate_release_notes: false
publish:
needs: release
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: "24"
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish --provenance