From de749534bba390ea37cc83a440e03eb109bef8f9 Mon Sep 17 00:00:00 2001 From: DarkSky <25152247+darkskygit@users.noreply.github.com> Date: Tue, 19 Sep 2023 20:48:12 +0800 Subject: [PATCH] ci: add multiple platform build (#28) --- .github/actions/setup-rust/action.yml | 4 ++ .github/workflows/y-octo-node.yml | 55 ++++++++++++++++++++++----- y-octo-node/Cargo.toml | 2 +- y-octo-node/package.json | 4 +- y-octo-node/scripts/run-test.mts | 16 +++++--- 5 files changed, 63 insertions(+), 18 deletions(-) diff --git a/.github/actions/setup-rust/action.yml b/.github/actions/setup-rust/action.yml index d2a2a4d..ddcd7dd 100644 --- a/.github/actions/setup-rust/action.yml +++ b/.github/actions/setup-rust/action.yml @@ -21,4 +21,8 @@ runs: toolchain: ${{ inputs.toolchain }} targets: ${{ inputs.targets }} components: ${{ inputs.components }} + - name: Add Targets + if: ${{ inputs.targets }} + run: rustup target add ${{ inputs.targets }} + shell: bash - uses: Swatinem/rust-cache@v2 diff --git a/.github/workflows/y-octo-node.yml b/.github/workflows/y-octo-node.yml index d778ac2..ab53dd9 100644 --- a/.github/workflows/y-octo-node.yml +++ b/.github/workflows/y-octo-node.yml @@ -10,15 +10,35 @@ on: env: DEBUG: napi:* COVERAGE: true + MACOSX_DEPLOYMENT_TARGET: "10.13" jobs: build-node: name: Build Node Binding - runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + settings: + - target: x86_64-apple-darwin + host: macos-latest + # - target: aarch64-apple-darwin + # host: macos-latest + - target: x86_64-pc-windows-msvc + host: windows-latest + # - target: aarch64-pc-windows-msvc + # host: windows-latest + - target: x86_64-unknown-linux-gnu + host: ubuntu-latest + # - target: aarch64-unknown-linux-gnu + # host: ubuntu-latest + # - target: x86_64-unknown-linux-musl + # host: ubuntu-latest + # - target: aarch64-unknown-linux-musl + # host: ubuntu-latest + runs-on: ${{ matrix.settings.host }} env: RUSTFLAGS: "-C debuginfo=1" environment: development - steps: - uses: actions/checkout@v3 - name: Setup Node.js @@ -26,14 +46,14 @@ jobs: - name: Setup Rust uses: ./.github/actions/setup-rust with: - target: "x86_64-unknown-linux-gnu" + targets: ${{ matrix.settings.target }} - name: Build node binding - run: yarn build:node + run: yarn build:node --target ${{ matrix.settings.target }} - name: Upload y-octo.node uses: actions/upload-artifact@v3 with: - name: y-octo.node - path: ./y-octo-node/y-octo.linux-x64-gnu.node + name: y-octo.${{ matrix.settings.target }}.node + path: ./y-octo-node/*.node if-no-files-found: error test-node: @@ -65,25 +85,40 @@ jobs: node-binding-test: name: Node Binding Test - runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + settings: + - target: x86_64-apple-darwin + host: macos-latest + - target: x86_64-unknown-linux-gnu + host: ubuntu-latest + - target: x86_64-pc-windows-msvc + host: windows-latest + runs-on: ${{ matrix.settings.host }} needs: build-node steps: - uses: actions/checkout@v3 - name: Setup Node.js uses: ./.github/actions/setup-node - - name: Download y-octo.node + - name: Download y-octo.${{ matrix.settings.target }}.node uses: actions/download-artifact@v3 with: - name: y-octo.node + name: y-octo.${{ matrix.settings.target }}.node path: ./y-octo-node + - name: Run node binding tests + run: ls -lah & ls -lah tests + working-directory: y-octo-node + shell: bash - name: Run node binding tests run: yarn test:node:coverage working-directory: y-octo-node + shell: bash - name: Upload server test coverage results uses: codecov/codecov-action@v3 with: token: ${{ secrets.CODECOV_TOKEN }} files: ./y-octo-node/.coverage/lcov.info flags: node-binding-test - name: y-octo + name: y-octo.${{ matrix.settings.target }}.node fail_ci_if_error: false diff --git a/y-octo-node/Cargo.toml b/y-octo-node/Cargo.toml index c936f4e..69ba858 100644 --- a/y-octo-node/Cargo.toml +++ b/y-octo-node/Cargo.toml @@ -14,7 +14,7 @@ crate-type = ["cdylib"] anyhow = "1" napi = { version = "2", features = ["anyhow", "napi4"] } napi-derive = "2" -y-octo = { path = "../y-octo", features = ["large_refs"] } +y-octo = { workspace = true, features = ["large_refs"] } [build-dependencies] napi-build = "2" diff --git a/y-octo-node/package.json b/y-octo-node/package.json index eac80cf..3e9c861 100644 --- a/y-octo-node/package.json +++ b/y-octo-node/package.json @@ -8,8 +8,10 @@ "triples": { "additional": [ "aarch64-apple-darwin", + "aarch64-pc-windows-msvc", "aarch64-unknown-linux-gnu", - "aarch64-pc-windows-msvc" + "x86_64-unknown-linux-musl", + "aarch64-unknown-linux-musl" ] }, "ts": { diff --git a/y-octo-node/scripts/run-test.mts b/y-octo-node/scripts/run-test.mts index 8a15acd..2ee63fe 100755 --- a/y-octo-node/scripts/run-test.mts +++ b/y-octo-node/scripts/run-test.mts @@ -28,12 +28,16 @@ const env = { }; if (process.argv[2] === "all") { - const cp = spawn("node", [...sharedArgs, resolve(testDir, "*")], { - cwd: root, - env, - stdio: "inherit", - shell: true, - }); + const cp = spawn( + "node", + [...sharedArgs, ...files.map((f) => resolve(testDir, f))], + { + cwd: root, + env, + stdio: "inherit", + shell: true, + }, + ); cp.on("exit", (code) => { process.exit(code ?? 0); });