Skip to content
Merged
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
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ on:

jobs:
check:
runs-on: "ubuntu-latest"
strategy:
matrix:
os: ["ubuntu-latest", "codspeedhq-arm64-ubuntu-22.04"]
runs-on: ${{ matrix.os }}
steps:
- uses: "actions/checkout@v4"
with:
Expand All @@ -35,7 +38,7 @@ jobs:
# list the directories in ./examples and output them to a github action workflow variables as a JSON array
- run: |
examples=$(find ./examples -maxdepth 1 -mindepth 1 -type d -printf '%f\n' | jq -R -s -c 'split("\n") | map(select(length > 0))')
echo "::set-output name=examples::$examples"
echo "examples=$examples" >> $GITHUB_OUTPUT
id: list-examples

node-versions:
Expand Down
36 changes: 35 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,31 @@ permissions:
contents: write

jobs:
build-native-arm:
runs-on: codspeedhq-arm64-ubuntu-22.04

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
cache: pnpm
node-version-file: .nvmrc
- run: pnpm install --frozen-lockfile --prefer-offline
- name: Build native code on ARM
run: pnpm moon core:build-native-addon
- name: Upload ARM prebuilds
uses: actions/upload-artifact@v4
with:
name: arm-prebuilds
path: packages/core/prebuilds

build:
runs-on: ubuntu-latest
needs: build-native-arm

steps:
- uses: actions/checkout@v4
Expand All @@ -28,8 +51,19 @@ jobs:
- name: Build the libraries
run: pnpm moon run :build

- name: Download ARM prebuilds
uses: actions/download-artifact@v4
with:
name: arm-prebuilds
path: packages/core/prebuilds

- name: Publish the libraries
run: pnpm publish -r --access=public --no-git-checks
run: |
if [[ "${{ github.ref }}" == *"-alpha"* ]]; then
pnpm publish -r --access=public --no-git-checks --tag=alpha
else
pnpm publish -r --access=public --no-git-checks
fi
env:
NPM_CONFIG_PROVENANCE: true
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export function getCodspeedRunnerMode(): CodSpeedRunnerMode {
}

export const setupCore = () => {
if (!native_core.isBound) {
throw new Error(
"Native core module is not bound, CodSpeed integration will not work properly"
);
}

native_core.InstrumentHooks.setIntegration("codspeed-node", __VERSION__);
linuxPerf.start();
checkV8Flags();
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/native_core/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from "path";
import { logDebug } from "../utils";
import { InstrumentHooks } from "./instruments/hooks";
import { LinuxPerf } from "./linux_perf/linux_perf";
interface NativeCore {
Expand All @@ -21,6 +22,8 @@ try {
isBound: true,
};
} catch (e) {
logDebug("Failed to bind native core, instruments will not work.");
logDebug(e);
native_core = {
LinuxPerf: class LinuxPerf {
start() {
Expand Down
7 changes: 7 additions & 0 deletions packages/core/tests/index.integ.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ describe("without bindings", () => {
const initialEnv = process.env;
beforeAll(() => {
process.env.npm_config_arch = "unknown";
// Prevent node-gyp from falling back to a local version of the native core in packages/core/build
process.env.PREBUILDS_ONLY = "1";
});
afterAll(() => {
process.env = initialEnv;
Expand All @@ -24,4 +26,9 @@ describe("without bindings", () => {
const isBound = require("..").isBound as boolean;
expect(isBound).toBe(false);
});

it("should throw when calling setupCore", () => {
const setupCore = require("..").setupCore as () => unknown;
expect(setupCore).toThrowError("Native core module is not bound");
});
});