Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add smoke-test for various node version and package managers #670

Merged
merged 21 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 88 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ jobs:
docker tag ${{ matrix.docker }} builder
docker run --volume ${{ github.workspace }}:/app --workdir /app --privileged builder sh -c "${{ matrix.docker_cmd }}"

- name: Upload artifacts
- name: Upload build
uses: actions/upload-artifact@v4
with:
path: ./build
Expand Down Expand Up @@ -189,7 +189,8 @@ jobs:
pnpm install -g electron@latest
xvfb-run --auto-servernum pnpm run test.electron.main
continue-on-error: true
merge-build:

Package:
runs-on: ubuntu-latest
needs: Build
steps:
Expand All @@ -199,3 +200,88 @@ jobs:
name: build
pattern: build-*
delete-merged: true

- uses: actions/checkout@v4

- name: Place build
uses: actions/download-artifact@v4
with:
name: build
path: ./build

- name: Install Node
uses: actions/setup-node@v4
with:
node-version-file: "./.nvmrc"

- name: Install Pnpm
uses: pnpm/action-setup@v4
with:
version: 9

- name: Pack Zeromq
run: |
pnpm install
pnpm pack

- name: Upload Pack
uses: actions/upload-artifact@v4
with:
path: ./*.tgz
name: pack
overwrite: true

SmokeTest:
runs-on: ${{ matrix.os }}
needs: Package
strategy:
fail-fast: false
matrix:
os:
- ubuntu-24.04
- windows-2022
- macos-13
node-version:
- 10
- 22

include:
- os: macos-14
node-version: 22
steps:
- name: Install Node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Install Yarn 1
if: matrix.node-version == 10
run: |
npm i -g yarn@^1

- name: Install Yarn Latest
if: matrix.node-version == 22
run: |
npm i -g yarn@latest

- name: Install Pnpm 5
if: matrix.node-version == 10
uses: pnpm/action-setup@v4
with:
version: 5

- name: Install Pnpm 9
if: matrix.node-version == 22
uses: pnpm/action-setup@v4
with:
version: 9

- uses: actions/checkout@v4

- name: Download Pack
uses: actions/download-artifact@v4
with:
name: pack

- name: Smoke Test
run: bash ./script/smoke-test.bash
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ tsconfig.*.tsbuildinfo
!/lib/load-addon.js
!/lib/load-addon.js.map

compile_commands.json
compile_commands.json

/smoke-test-*
/*.tgz
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
22.10.0
16 changes: 15 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
{
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"mochaExplorer.parallel": true,
"mochaExplorer.globImplementation": "vscode",
"mochaExplorer.nodeArgv": ["--expose-gc"],
"mochaExplorer.nodeArgv": [
"--expose-gc"
],
"mochaExplorer.debuggerConfig": "JS-Attach",
"files.exclude": {
"**/.DS_Store": true,
Expand Down
3 changes: 2 additions & 1 deletion lib/load-addon.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/load-addon.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
],
"scripts": {
"install": "node ./script/install.js",
"prepare": "pnpm run build.js",
"clean": "shx rm -rf ./build ./prebuilds && run-p clean.lib clean.temp",
"clean.lib": "shx rm -rf ./lib/",
"clean.release": "shx rm -rf ./build/Release",
Expand All @@ -99,19 +98,22 @@
"build": "run-p build.js build.native",
"build.debug": "run-s build.js build.native.debug",
"test": "run-s clean.temp build && mocha",
"test.smoke": "bash ./script/smoke-test.bash",
"test.skip_gc_tests": "run-s clean.temp build.debug && cross-env SKIP_GC_TESTS=true mocha",
"test.electron.main": "run-s clean.temp build && electron-mocha",
"format": "run-s format.prettier format.clang-format",
"format.prettier": "prettier --write .",
"format.prettier": "prettier -l --cache --cache-location ./.cache/prettier --write .",
"format.clang-format": "clang-format -i -style=file ./src/*.cc ./src/*.h ./src/util/*.h",
"test.electron.renderer": "run-s build && electron-mocha --renderer",
"lint-test.eslint": "eslint ./**/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml} --no-error-on-unmatched-pattern --cache --cache-location ./.cache/eslint/",
"lint.eslint": "pnpm run lint-test.eslint --fix",
"lint.tsc": "tsc --noEmit -p ./src/tsconfig.json",
"lint.tsc-test": "tsc --noEmit -p ./test/tsconfig.json",
"lint.clang-tidy": "git ls-files --exclude-standard | grep -E '\\.(cpp|hpp|c|cc|cxx|hxx|h|ixx)$' | xargs -n 1 -P $(nproc) clang-tidy",
"lint": "run-p format lint.eslint format",
"lint": "run-p lint.tsc-test lint.tsc lint.eslint format",
"lint-test": "run-s lint-test.eslint",
"bench": "node --expose-gc test/bench",
"prepublishOnly": "pnpm run build.js",
"prepare": "pnpm run build.js",
"bump": "pnpx npm-check-updates -u -x typescript,eslint,chai && pnpx typesync && pnpm update"
},
"cmake-ts": {
Expand Down
39 changes: 39 additions & 0 deletions script/smoke-test.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/bash
set -ev
set -o pipefail

root="${PWD}"

echo "Pack zeromq.js if needed"
version=$(node -e 'console.log(require("./package.json").version)')
pack_name="zeromq-${version}.tgz"
test -f "./${pack_name}" || npm pack

package_managers=(npm pnpm yarn)

for pm in "${package_managers[@]}"; do
dir="../zeromq-smoke-test-${pm}"

echo "Init Smoke Test Project ${pm}"
rm -rf "${dir}"
mkdir "${dir}"
cp "./${pack_name}" "${dir}"
cd "${dir}"
npm init -y
npm pkg set dependencies.zeromq="file:./${pack_name}" || (jq ".dependencies.zeromq = \"file:./${pack_name}\"" package.json >temp.json && mv temp.json package.json)

echo "Install with ${pm}"
if [[ "${pm}" == "yarn" ]]; then
yarn install --ignore-engines
else
${pm} install
fi

echo "Require zeromq"
node -e "console.log(require('zeromq'))"

cd "${root}"
rm -rf "../zeromq-smoke-test-${pm}"
done

rm -f "${pack_name}"
3 changes: 2 additions & 1 deletion src/load-addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ function findAddon(): any | undefined {
return addon
}

module.exports = findAddon()
const addon = findAddon()
export default addon
4 changes: 2 additions & 2 deletions src/module.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

#include <array>

#include "./module.h"

#include <array>

#include "./context.h"
#include "./observer.h"
#include "./outgoing_msg.h"
Expand Down
3 changes: 2 additions & 1 deletion src/native.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable @typescript-eslint/no-var-requires */

/* Declare all native C++ classes and methods in this file. */
module.exports = require("./load-addon")
import addon from "./load-addon"
module.exports = addon

/**
* The version of the ØMQ library the bindings were built with. Formatted as
Expand Down
1 change: 1 addition & 0 deletions src/outgoing_msg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "./outgoing_msg.h"

#include <functional>

#include "./module.h"
#include "util/error.h"

Expand Down
4 changes: 2 additions & 2 deletions src/poller.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class Poller {
/* Initialize the poller with the given file descriptor. FD should be
ZMQ style edge-triggered, with READABLE state indicating that ANY
event may be present on the corresponding ZMQ socket. */
int32_t Initialize(
Napi::Env env, uv_os_sock_t& file_descriptor, std::function<void()> finalizer = nullptr) {
int32_t Initialize(Napi::Env env, uv_os_sock_t& file_descriptor,
std::function<void()> finalizer = nullptr) {
auto* loop = UvLoop(env);

poll->data = this;
Expand Down
10 changes: 9 additions & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"extends": "../tsconfig.json",
"include": ["**/*.ts"]
"include": ["**/*.ts"],
"compilerOptions": {
"skipLibCheck": true,
"lib": [
"ES2020",
// only used in tests
"ES2021.WeakRef"
]
}
}
6 changes: 1 addition & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
"incremental": true,
"sourceMap": true,
"esModuleInterop": true,
"lib": [
"ES2020",
// only used in tests
"ES2021.WeakRef"
]
"lib": ["ES2020"]
}
}
Loading