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: bring back testing on alpine #47

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 19 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,18 @@ jobs:
- checkout
- npm_install:
os: << parameters.os >>
- when:
condition:
equal: [ "alpine", << parameters.os >> ]
steps:
- prepare:
os: << parameters.os >>
- run:
command: npm run build:test
- test

## WORKFLOWS ##

matrix: &matrix
matrix:
parameters:
os: [ debian, linux, macos, "win/default" ]

workflows:
postject:
jobs:
Expand All @@ -225,8 +228,16 @@ workflows:
parameters:
os: [ linux, macos, "win/default" ]
- build:
<<: *matrix
matrix:
parameters:
os: [ linux, macos, "win/default" ]
- test:
<<: *matrix
matrix:
parameters:
os: [ macos, "win/default" ]
requires: [ build-<< matrix.os >> ]

- test:
matrix:
parameters:
os: [ alpine, debian ]
requires: [ build-linux ]
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"main": "dist/api.js",
"scripts": {
"build": "zx ./scripts/build.mjs",
"build:test": "zx ./scripts/build.mjs --target=test",
"clean": "rimraf ./build",
"format": "npm run format:cpp && npm run format:js",
"format:cpp": "clang-format -style=chromium -i postject-api.h src/**.cpp test/**.c test/**.cpp",
Expand Down
71 changes: 47 additions & 24 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env zx

let target = argv.target;
let jobs = argv.jobs;

if (!jobs) {
Expand All @@ -15,34 +16,56 @@ if (!jobs) {
}
}

try {
await which("emcmake");
} catch {
console.log("ERROR: Couldn't find `emcmake`, is emsdk installed?");
process.exit(1);
}
async function build() {
try {
await which("emcmake");
} catch {
console.log("ERROR: Couldn't find `emcmake`, is emsdk installed?");
process.exit(1);
}

// Create build folder if needed
if (!(await fs.exists("./build"))) {
await $`mkdir -p build`;
}

cd("build");

// Create build folder if needed
if (!(await fs.exists("./build"))) {
await $`mkdir build`;
// Build with emsdk
await $`emcmake cmake -G Ninja ..`;
await $`cmake --build . -j ${jobs}`;

// Bundle api.js and copy artifacts to dist
await fs.copy("../src/api.js", "api.js");
await $`esbuild api.js --bundle --platform=node --outfile=../dist/api.js`;
await fs.copy("../src/cli.js", "../dist/cli.js");
await fs.copy("../postject-api.h", "../dist/postject-api.h");

cd("..");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't expect the directory change to persist after exiting the function scope :/ a defer instruction would be useful here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, seems to be a quirk of zx that would feel a little unexpected to folks who are used to writing these using sh

}
cd("build");

// Build with emsdk
await $`emcmake cmake -G Ninja ..`;
await $`cmake --build . -j ${jobs}`;
async function test() {
// Create build folder if needed
if (!(await fs.exists("./build/test"))) {
await $`mkdir -p build/test`;
}

// Bundle api.js and copy artifacts to dist
await fs.copy("../src/api.js", "api.js");
await $`esbuild api.js --bundle --platform=node --outfile=../dist/api.js`;
await fs.copy("../src/cli.js", "../dist/cli.js");
await fs.copy("../postject-api.h", "../dist/postject-api.h");
cd("build/test");

// Build tests
if (!(await fs.exists("./test"))) {
await $`mkdir test`;
await $`cmake ../../test`;
await $`cmake --build .`;

cd("../..");
}

cd("test");
await $`cmake ../../test`;
await $`cmake --build .`;
switch (target) {
case "build":
await build();
break;
case "test":
await test();
break;
default:
await build();
await test();
}