Skip to content

Commit 64516be

Browse files
Merge pull request #159 from Countly/dep-update
Bug fixes
2 parents 83d1494 + 793466a commit 64516be

39 files changed

Lines changed: 3632 additions & 550 deletions

‎.github/dependabot.yml‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,26 @@ version: 2
22
updates:
33
- package-ecosystem: npm
44
directory: "/"
5+
target-branch: staging
56
schedule:
67
interval: monthly
78
open-pull-requests-limit: 10
89
versioning-strategy: increase-if-necessary
10+
groups:
11+
dev-dependencies:
12+
dependency-type: development
13+
update-types: [ "minor", "patch" ]
14+
ignore:
15+
# mocha 12 needs Node 20.19+ while CI still tests Node 18, and eslint 9+ needs a new config format
16+
- dependency-name: "mocha"
17+
update-types: [ "version-update:semver-major" ]
18+
- dependency-name: "eslint"
19+
update-types: [ "version-update:semver-major" ]
20+
- package-ecosystem: github-actions
21+
directory: "/"
22+
target-branch: staging
23+
schedule:
24+
interval: monthly
25+
groups:
26+
github-actions:
27+
patterns: [ "*" ]

‎.github/scripts/check_release.js‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* Release check run by CI before publishing: the version in package.json, the SDK_VERSION constants in lib and the
3+
* first CHANGELOG heading must all name the same version. With "--notes" it prints that version's CHANGELOG section
4+
* instead, which becomes the GitHub release notes.
5+
* usage: node .github/scripts/check_release.js [--notes]
6+
*/
7+
var fs = require("fs");
8+
var path = require("path");
9+
10+
var root = path.resolve(__dirname, "../..");
11+
12+
/**
13+
* Reads a file of the repository
14+
* @param {String} file - path relative to the repository root
15+
* @returns {String} file content
16+
*/
17+
function read(file) {
18+
return fs.readFileSync(path.join(root, file), "utf8");
19+
}
20+
21+
/**
22+
* Splits the CHANGELOG into its "## " sections
23+
* @returns {Array<{heading: String, body: String}>} sections in file order
24+
*/
25+
function changelogSections() {
26+
return read("CHANGELOG.md").split(/^## /m).slice(1).map((section) => {
27+
var lines = section.split("\n");
28+
return { heading: lines[0].trim(), body: lines.slice(1).join("\n").trim() };
29+
});
30+
}
31+
32+
var { version } = JSON.parse(read("package.json"));
33+
var sections = changelogSections();
34+
35+
if (process.argv.indexOf("--notes") !== -1) {
36+
process.stdout.write(`${sections.length ? sections[0].body : ""}\n`);
37+
}
38+
else {
39+
var problems = [];
40+
var heading = sections.length ? sections[0].heading : "(none)";
41+
if (heading !== version) {
42+
problems.push(`the first CHANGELOG heading is "${heading}", rename it to "${version}"`);
43+
}
44+
["lib/countly.js", "lib/countly-bulk.js"].forEach((file) => {
45+
var match = /SDK_VERSION = "([^"]+)"/.exec(read(file));
46+
var found = match ? match[1] : "(none)";
47+
if (found !== version) {
48+
problems.push(`${file} has SDK_VERSION "${found}", set it to "${version}"`);
49+
}
50+
});
51+
if (problems.length) {
52+
process.stderr.write(`Release check failed for ${version}:\n- ${problems.join("\n- ")}\n`);
53+
process.exitCode = 1;
54+
}
55+
else {
56+
process.stdout.write(`Release check passed for ${version}\n`);
57+
}
58+
}

‎.github/workflows/codeql-analysis.yml‎

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,18 @@ jobs:
3939

4040
steps:
4141
- name: Checkout repository
42-
uses: actions/checkout@v4
42+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
4343

4444
# Initializes the CodeQL tools for scanning.
4545
- name: Initialize CodeQL
46-
uses: github/codeql-action/init@v3
46+
uses: github/codeql-action/init@6f2ac81f5cd81fe351a197ba0b00d91d03cd2aee # v4.39.0
4747
with:
4848
languages: ${{ matrix.language }}
49+
build-mode: none
4950
# If you wish to specify custom queries, you can do so here or in a config file.
5051
# By default, queries listed here will override any specified in a config file.
5152
# Prefix the list here with "+" to use these queries and those in the config file.
5253
# queries: ./path/to/local/query, your-org/your-repo/queries@main
5354

54-
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
55-
# If this step fails, then you should remove it and run the build manually (see below)
56-
- name: Autobuild
57-
uses: github/codeql-action/autobuild@v3
58-
59-
# ℹ️ Command-line programs to run using the OS shell.
60-
# 📚 https://git.io/JvXDl
61-
62-
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
63-
# and modify them (or add more) to build your code if your project
64-
# uses a compiled language
65-
66-
#- run: |
67-
# make bootstrap
68-
# make release
69-
7055
- name: Perform CodeQL Analysis
71-
uses: github/codeql-action/analyze@v3
56+
uses: github/codeql-action/analyze@6f2ac81f5cd81fe351a197ba0b00d91d03cd2aee # v4.39.0

‎.github/workflows/node.js.yml‎

Lines changed: 150 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,76 @@ on:
99
pull_request:
1010
branches: [ master, staging ]
1111

12+
permissions:
13+
contents: read
14+
1215
concurrency:
1316
group: ${{ github.workflow }}-${{ github.ref }}
14-
cancel-in-progress: true
17+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
1518

1619
jobs:
1720
build:
18-
19-
runs-on: ubuntu-latest
21+
runs-on: ${{ matrix.os }}
2022
strategy:
21-
matrix:
22-
# mocha 11 requires Node 18.18+, 24 is the active LTS
23-
node: [18, 20, 22, 24]
23+
fail-fast: false
24+
matrix:
25+
# the test suite needs Node 18.18+ (mocha 11), the compat job covers the older supported versions
26+
os: [ ubuntu-latest ]
27+
node: [ 18, 20, 22, 24, 26 ]
28+
include:
29+
- os: windows-latest
30+
node: 24
2431
steps:
25-
- uses: actions/checkout@v4
32+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
2633
- name: Use Node.js ${{ matrix.node }}
27-
uses: actions/setup-node@v4
34+
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
2835
with:
2936
node-version: ${{ matrix.node }}
3037
cache: 'npm'
3138
- run: npm ci
32-
- run: npm test
39+
- name: Lint and test
40+
if: matrix.os == 'ubuntu-latest' && matrix.node != 24
41+
run: npm test
42+
- name: Lint and test with coverage
43+
if: matrix.os == 'ubuntu-latest' && matrix.node == 24
44+
run: npm run coverage
45+
- name: Upload the coverage report
46+
if: matrix.os == 'ubuntu-latest' && matrix.node == 24
47+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
48+
with:
49+
name: coverage-report
50+
path: coverage/
51+
# lint runs on Linux only, as Windows checkouts can have CRLF line endings that the lint rules reject
52+
- name: Test
53+
if: matrix.os == 'windows-latest'
54+
run: npm test --ignore-scripts
55+
56+
compat:
57+
runs-on: ubuntu-latest
58+
timeout-minutes: 5
59+
strategy:
60+
fail-fast: false
61+
matrix:
62+
node: [ 10, 12, 14, 16 ]
63+
steps:
64+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
65+
- name: Use Node.js ${{ matrix.node }}
66+
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
67+
with:
68+
node-version: ${{ matrix.node }}
69+
# the SDK has no dependencies, so the check runs without installing packages
70+
- run: node test/compat/compat_check.js
3371

3472
deploy:
3573
runs-on: ubuntu-latest
36-
needs: build
74+
needs: [ build, compat ]
3775
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
76+
permissions:
77+
contents: write
3878
steps:
39-
- uses: actions/checkout@v4
79+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
4080
- name: Use Node.js 24.x
41-
uses: actions/setup-node@v4
81+
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
4282
with:
4383
node-version: 24.x
4484
cache: 'npm'
@@ -48,3 +88,101 @@ jobs:
4888
env:
4989
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5090
run: bash generateDocs.sh
91+
92+
version:
93+
runs-on: ubuntu-latest
94+
needs: [ build, compat ]
95+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
96+
outputs:
97+
version: ${{ steps.version.outputs.version }}
98+
new: ${{ steps.version.outputs.new }}
99+
steps:
100+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
101+
- name: Use Node.js 24
102+
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
103+
with:
104+
node-version: 24
105+
package-manager-cache: false
106+
- name: Check whether this version is on npm already
107+
id: version
108+
run: |
109+
VERSION=$(node -p "require('./package.json').version")
110+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
111+
STATUS=0
112+
PUBLISHED=$(npm view "countly-sdk-nodejs@$VERSION" version 2> npm-view-error.txt) || STATUS=$?
113+
if [ "$STATUS" -eq 0 ] && [ "$PUBLISHED" = "$VERSION" ]; then
114+
echo "new=false" >> "$GITHUB_OUTPUT"
115+
echo "::notice::$VERSION is on npm already, nothing to release"
116+
elif [ "$STATUS" -eq 0 ] || grep -q E404 npm-view-error.txt; then
117+
echo "new=true" >> "$GITHUB_OUTPUT"
118+
else
119+
cat npm-view-error.txt
120+
echo "::error::Could not check whether $VERSION is on npm"
121+
exit 1
122+
fi
123+
- name: Check that package.json, the code and the CHANGELOG name the same version
124+
if: steps.version.outputs.new == 'true'
125+
run: node .github/scripts/check_release.js
126+
127+
release:
128+
runs-on: ubuntu-latest
129+
needs: version
130+
if: needs.version.outputs.new == 'true'
131+
# the npm environment holds the approval step, and npm's trusted publisher setting names it
132+
environment: npm
133+
permissions:
134+
contents: write
135+
id-token: write
136+
outputs:
137+
created: ${{ steps.release.outputs.created }}
138+
url: ${{ steps.release.outputs.url }}
139+
notes: ${{ steps.release.outputs.notes }}
140+
steps:
141+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
142+
- name: Use Node.js 24
143+
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
144+
with:
145+
node-version: 24
146+
registry-url: https://registry.npmjs.org
147+
package-manager-cache: false
148+
- name: Publish to npm
149+
env:
150+
VERSION: ${{ needs.version.outputs.version }}
151+
run: |
152+
if [ "$(npm view "countly-sdk-nodejs@$VERSION" version 2> /dev/null)" = "$VERSION" ]; then
153+
echo "::notice::$VERSION is on npm already, publishing is skipped"
154+
else
155+
npm publish
156+
fi
157+
- name: Create the GitHub release
158+
id: release
159+
env:
160+
GH_TOKEN: ${{ github.token }}
161+
VERSION: ${{ needs.version.outputs.version }}
162+
run: |
163+
node .github/scripts/check_release.js --notes > release-notes.md
164+
if gh release view "$VERSION" > /dev/null 2>&1; then
165+
echo "::notice::The GitHub release $VERSION exists already, so it is not created again and no notice is sent"
166+
echo "created=false" >> "$GITHUB_OUTPUT"
167+
else
168+
gh release create "$VERSION" --title "Countly NodeJS SDK $VERSION" --notes-file release-notes.md --target "$GITHUB_SHA"
169+
echo "created=true" >> "$GITHUB_OUTPUT"
170+
fi
171+
URL=$(gh release view "$VERSION" --json url --jq .url)
172+
echo "url=$URL" >> "$GITHUB_OUTPUT"
173+
{
174+
echo "notes<<RELEASE_NOTES_END"
175+
cat release-notes.md
176+
echo "RELEASE_NOTES_END"
177+
} >> "$GITHUB_OUTPUT"
178+
179+
# a release created with the workflow token does not start other workflows, so the notice is called directly
180+
notify:
181+
needs: [ version, release ]
182+
if: needs.release.outputs.created == 'true'
183+
uses: ./.github/workflows/release_notice.yml
184+
with:
185+
tag_name: ${{ needs.version.outputs.version }}
186+
html_url: ${{ needs.release.outputs.url }}
187+
body: ${{ needs.release.outputs.notes }}
188+
secrets: inherit

‎.github/workflows/release_notice.yml‎

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,64 @@ on:
33
release:
44
types: [published]
55
workflow_dispatch:
6+
inputs:
7+
tag_name:
8+
description: "Version to announce, for example 26.1.0"
9+
type: string
10+
required: false
11+
html_url:
12+
description: "Link to the GitHub release"
13+
type: string
14+
required: false
15+
body:
16+
description: "Release notes"
17+
type: string
18+
required: false
19+
workflow_call:
20+
inputs:
21+
tag_name:
22+
type: string
23+
required: true
24+
html_url:
25+
type: string
26+
required: true
27+
body:
28+
type: string
29+
required: false
30+
default: ""
31+
permissions:
32+
contents: read
633
jobs:
734
build:
835
runs-on: ubuntu-latest
936
steps:
10-
# To check the github context
11-
- name: Dump Github context
12-
env:
13-
GITHUB_CONTEXT: ${{ toJSON(github) }}
14-
run: echo "$GITHUB_CONTEXT"
1537
- name: Send custom JSON data to Slack workflow
1638
id: slack
17-
uses: slackapi/slack-github-action@v1.23.0
39+
uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0
1840
with:
41+
webhook: ${{ secrets.SLACK_RELEASE }}
42+
webhook-type: webhook-trigger
43+
# errors, retries and payload-delimiter keep the behaviour of v1: the step fails on an error, posts once and sends every value as text
44+
errors: true
45+
retries: 0
46+
payload-delimiter: "."
1947
# This data can be any valid JSON from a previous step in the GitHub Action
2048
payload: |
2149
{
2250
"repository": "${{ github.repository }}",
23-
"tag_name": "${{ github.event.release.tag_name }}",
51+
"tag_name": "${{ inputs.tag_name || github.event.release.tag_name }}",
2452
"actor": "${{ github.actor }}",
25-
"body": ${{ toJSON(github.event.release.body) }},
26-
"html_url": "${{ github.event.release.html_url }}"
53+
"body": ${{ toJSON(inputs.body || github.event.release.body) }},
54+
"html_url": "${{ inputs.html_url || github.event.release.html_url }}"
2755
}
28-
env:
29-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_RELEASE }}
3056
- name: Send custom JSON data to Discord
31-
uses: sarisia/actions-status-discord@v1.13.0
57+
if: ${{ !cancelled() }}
58+
uses: sarisia/actions-status-discord@eb045afee445dc055c18d3d90bd0f244fd062708 # v1.16.0
3259
with:
3360
webhook: ${{ secrets.DISCORD_WEBHOOK_URL }}
3461
nodetail: true
35-
title: New ${{ github.repository }} version ${{ github.event.release.tag_name }} published by ${{ github.actor }}
62+
title: New ${{ github.repository }} version ${{ inputs.tag_name || github.event.release.tag_name }} published by ${{ github.actor }}
3663
description: |
37-
Release URL: ${{ github.event.release.html_url }}
38-
Click [here](https://github.com/Countly/countly-server/blob/master/CHANGELOG.md) to view the change log.
39-
`${{ github.event.release.body }}`
64+
Release URL: ${{ inputs.html_url || github.event.release.html_url }}
65+
Click [here](https://github.com/${{ github.repository }}/blob/master/CHANGELOG.md) to view the change log.
66+
`${{ inputs.body || github.event.release.body }}`

0 commit comments

Comments
 (0)