Repository navigation
181 lines (171 loc) · 6.75 KB
/
Copy pathnode.js.yml
File metadata and controls
181 lines (171 loc) · 6.75 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: [ master, staging ]
pull_request:
branches: [ master, staging ]
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# the test suite needs Node 18.18+ (mocha 11), the compat job covers the older supported versions
os: [ ubuntu-latest ]
node: [ 18, 20, 22, 24, 26 ]
include:
- os: windows-latest
node: 24
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: ${{ matrix.node }}
cache: 'npm'
- run: npm ci
- name: Lint and test
if: matrix.os == 'ubuntu-latest' && matrix.node != 24
run: npm test
- name: Lint and test with coverage
if: matrix.os == 'ubuntu-latest' && matrix.node == 24
run: npm run coverage
- name: Upload the coverage report
if: matrix.os == 'ubuntu-latest' && matrix.node == 24
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: coverage-report
path: coverage/
# lint runs on Linux only, as Windows checkouts can have CRLF line endings that the lint rules reject
- name: Test
if: matrix.os == 'windows-latest'
run: npm test --ignore-scripts
compat:
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
fail-fast: false
matrix:
node: [ 10, 12, 14, 16 ]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: ${{ matrix.node }}
# the SDK has no dependencies, so the check runs without installing packages
- run: node test/compat/compat_check.js
deploy:
runs-on: ubuntu-latest
needs: [ build, compat ]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
permissions:
contents: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Use Node.js 24.x
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24.x
cache: 'npm'
- run: npm ci
- name: Deploy documentation
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bash generateDocs.sh
version:
runs-on: ubuntu-latest
needs: [ build, compat ]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
outputs:
version: ${{ steps.version.outputs.version }}
new: ${{ steps.version.outputs.new }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Use Node.js 24
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
package-manager-cache: false
- name: Check whether this version is on npm already
id: version
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
STATUS=0
PUBLISHED=$(npm view "countly-sdk-nodejs@$VERSION" version 2> npm-view-error.txt) || STATUS=$?
if [ "$STATUS" -eq 0 ] && [ "$PUBLISHED" = "$VERSION" ]; then
echo "new=false" >> "$GITHUB_OUTPUT"
echo "::notice::$VERSION is on npm already, nothing to release"
elif [ "$STATUS" -eq 0 ] || grep -q E404 npm-view-error.txt; then
echo "new=true" >> "$GITHUB_OUTPUT"
else
cat npm-view-error.txt
echo "::error::Could not check whether $VERSION is on npm"
exit 1
fi
- name: Check that package.json, the code and the CHANGELOG name the same version
if: steps.version.outputs.new == 'true'
run: node .github/scripts/check_release.js
stage:
runs-on: ubuntu-latest
needs: version
if: needs.version.outputs.new == 'true'
# a maintainer approves this job through the npm environment, which npm's trusted publisher setting also names
environment: npm
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Use Node.js 24
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
# npm stage needs npm 11.15.0 or newer, which only Node 24.18.0 and newer ship
check-latest: true
registry-url: https://registry.npmjs.org
package-manager-cache: false
- name: Stage the package on npm
env:
VERSION: ${{ needs.version.outputs.version }}
run: |
if [ "$(npm view "countly-sdk-nodejs@$VERSION" version 2> /dev/null)" = "$VERSION" ]; then
echo "::notice::$VERSION is on npm already, staging is skipped"
elif ! npm stage publish; then
echo "::error::Staging $VERSION failed. If $VERSION is already in the Staged Packages tab on npmjs.com, approve or reject it there"
exit 1
fi
# a draft release sends no notice; publishing it after the npm approval starts the Release Notice workflow
draft:
runs-on: ubuntu-latest
needs: [ version, stage ]
permissions:
contents: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Create the draft GitHub release
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.version.outputs.version }}
run: |
if gh release view "$VERSION" > /dev/null 2>&1; then
echo "::notice::The GitHub release $VERSION exists already"
else
node .github/scripts/check_release.js --notes > release-notes.md
gh release create "$VERSION" --draft --title "Countly NodeJS SDK $VERSION" --notes-file release-notes.md --target "$GITHUB_SHA"
fi
URL=$(gh release view "$VERSION" --json url --jq .url)
{
echo "### Next steps for $VERSION"
echo "1. Approve $VERSION in the Staged Packages tab of https://www.npmjs.com/package/countly-sdk-nodejs"
echo "2. Publish the draft release, which sends the release notice: $URL"
} >> "$GITHUB_STEP_SUMMARY"