From 3eab8c78e16e2c07f6ecfd60994bbd3b54d3d41e Mon Sep 17 00:00:00 2001 From: CherishCai <785427346@qq.com> Date: Wed, 22 Nov 2023 21:05:21 +0800 Subject: [PATCH] ci: CI --- .github/workflows/CI.yml | 143 +++++++++++++++------------------------ package.json | 2 +- 2 files changed, 55 insertions(+), 90 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index d1e03bc..19da681 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -3,6 +3,9 @@ env: DEBUG: napi:* APP_NAME: nacos-sdk-rust-binding-node MACOSX_DEPLOYMENT_TARGET: '10.13' +permissions: + contents: write + id-token: write 'on': push: branches: @@ -17,6 +20,9 @@ env: - .editorconfig - docs/** pull_request: null +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: build: strategy: @@ -41,7 +47,7 @@ jobs: docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian build: |- set -e && - RUST_BACKTRACE=full yarn build --target x86_64-unknown-linux-gnu && + yarn build --target x86_64-unknown-linux-gnu && strip *.node - host: ubuntu-latest target: x86_64-unknown-linux-musl @@ -50,6 +56,11 @@ jobs: - host: macos-latest target: aarch64-apple-darwin build: | + sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*; + export CC=$(xcrun -f clang); + export CXX=$(xcrun -f clang++); + SYSROOT=$(xcrun --sdk macosx --show-sdk-path); + export CFLAGS="-isysroot $SYSROOT -isystem $SYSROOT"; yarn build --target aarch64-apple-darwin strip -x *.node - host: ubuntu-latest @@ -57,7 +68,7 @@ jobs: docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64 build: |- set -e && - RUST_BACKTRACE=1 yarn build --target aarch64-unknown-linux-gnu && + yarn build --target aarch64-unknown-linux-gnu && aarch64-unknown-linux-gnu-strip *.node - host: ubuntu-latest target: armv7-unknown-linux-gnueabihf @@ -65,7 +76,7 @@ jobs: sudo apt-get update sudo apt-get install gcc-arm-linux-gnueabihf -y build: | - RUST_BACKTRACE=1 yarn build --target armv7-unknown-linux-gnueabihf + yarn build --target armv7-unknown-linux-gnueabihf arm-linux-gnueabihf-strip *.node - host: ubuntu-latest target: aarch64-linux-android @@ -91,13 +102,12 @@ jobs: name: stable - ${{ matrix.settings.target }} - node@18 runs-on: ${{ matrix.settings.host }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 if: ${{ !matrix.settings.docker }} with: node-version: 18 - check-latest: true cache: yarn - name: Install uses: dtolnay/rust-toolchain@stable @@ -118,7 +128,7 @@ jobs: - uses: goto-bus-stop/setup-zig@v2 if: ${{ matrix.settings.target == 'armv7-unknown-linux-gnueabihf' }} with: - version: 0.10.1 + version: 0.11.0 - name: Setup toolchain run: ${{ matrix.settings.setup }} if: ${{ matrix.settings.setup }} @@ -130,11 +140,10 @@ jobs: - name: Install dependencies run: yarn install - name: Setup node x86 - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 if: matrix.settings.target == 'i686-pc-windows-msvc' with: node-version: 18 - check-latest: true cache: yarn architecture: x86 - name: Build in docker @@ -155,37 +164,35 @@ jobs: path: ${{ env.APP_NAME }}.*.node if-no-files-found: error build-freebsd: - runs-on: macos-12 + runs-on: macos-13 name: Build FreeBSD steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Build id: build - uses: vmactions/freebsd-vm@v0 + uses: cross-platform-actions/action@v0.21.1 env: DEBUG: napi:* - RUSTUP_HOME: /usr/local/rustup - CARGO_HOME: /usr/local/cargo RUSTUP_IO_THREADS: 1 with: - envs: DEBUG RUSTUP_HOME CARGO_HOME RUSTUP_IO_THREADS - usesh: true - mem: 3000 - prepare: | - pkg install -y -f curl node libnghttp2 - curl -qL https://www.npmjs.com/install.sh | sh - npm install --location=global --ignore-scripts yarn + operating_system: freebsd + version: '13.2' + memory: 13G + cpu_count: 3 + environment_variables: 'DEBUG RUSTUP_IO_THREADS' + shell: bash + run: | + sudo pkg install -y -f curl node libnghttp2 npm + sudo npm install -g yarn --ignore-scripts curl https://sh.rustup.rs -sSf --output rustup.sh sh rustup.sh -y --profile minimal --default-toolchain beta - export PATH="/usr/local/cargo/bin:$PATH" + source "$HOME/.cargo/env" echo "~~~~ rustc --version ~~~~" rustc --version echo "~~~~ node -v ~~~~" node -v echo "~~~~ yarn --version ~~~~" yarn --version - run: | - export PATH="/usr/local/cargo/bin:$PATH" pwd ls -lah whoami @@ -193,8 +200,6 @@ jobs: freebsd-version yarn install yarn build - strip -x *.node - yarn test rm -rf node_modules rm -rf target rm -rf .yarn/cache @@ -214,18 +219,18 @@ jobs: settings: - host: windows-latest target: x86_64-pc-windows-msvc + - host: macos-latest + target: x86_64-apple-darwin node: - - '14' - - '16' - '18' + - '20' runs-on: ${{ matrix.settings.host }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} - check-latest: true cache: yarn - name: Install dependencies run: yarn install @@ -247,17 +252,15 @@ jobs: fail-fast: false matrix: node: - - '14' - - '16' - '18' + - '20' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} - check-latest: true cache: yarn - name: Install dependencies run: yarn install @@ -279,17 +282,15 @@ jobs: fail-fast: false matrix: node: - - '14' - - '16' - '18' + - '20' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} - check-latest: true cache: yarn - name: Install dependencies run: | @@ -313,12 +314,11 @@ jobs: fail-fast: false matrix: node: - - '14' - - '16' - '18' + - '20' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Download artifacts uses: actions/download-artifact@v3 with: @@ -333,7 +333,7 @@ jobs: yarn config set supportedArchitectures.libc "glibc" yarn install - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 with: platforms: arm64 - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes @@ -347,12 +347,12 @@ jobs: yarn test ls -la test-linux-aarch64-musl-binding: - name: Test bindings on aarch64-unknown-linux-musl - node@${{ matrix.node }} + name: Test bindings on aarch64-unknown-linux-musl - node@lts needs: - build runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Download artifacts uses: actions/download-artifact@v3 with: @@ -367,7 +367,7 @@ jobs: yarn config set supportedArchitectures.libc "musl" yarn install - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 with: platforms: arm64 - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes @@ -387,12 +387,11 @@ jobs: fail-fast: false matrix: node: - - '14' - - '16' - '18' + - '20' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Download artifacts uses: actions/download-artifact@v3 with: @@ -406,7 +405,7 @@ jobs: yarn config set supportedArchitectures.cpu "arm" yarn install - name: Set up QEMU - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 with: platforms: arm - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes @@ -419,39 +418,6 @@ jobs: set -e yarn test ls -la - universal-macOS: - name: Build universal macOS binary - needs: - - build - runs-on: macos-latest - steps: - - uses: actions/checkout@v3 - - name: Setup node - uses: actions/setup-node@v3 - with: - node-version: 18 - check-latest: true - cache: yarn - - name: Install dependencies - run: yarn install - - name: Download macOS x64 artifact - uses: actions/download-artifact@v3 - with: - name: bindings-x86_64-apple-darwin - path: artifacts - - name: Download macOS arm64 artifact - uses: actions/download-artifact@v3 - with: - name: bindings-aarch64-apple-darwin - path: artifacts - - name: Combine binaries - run: yarn universal - - name: Upload artifact - uses: actions/upload-artifact@v3 - with: - name: bindings-universal-apple-darwin - path: ${{ env.APP_NAME }}.*.node - if-no-files-found: error publish: name: Publish runs-on: ubuntu-latest @@ -463,14 +429,12 @@ jobs: - test-linux-aarch64-gnu-binding - test-linux-aarch64-musl-binding - test-linux-arm-gnueabihf-binding - - universal-macOS steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 18 - check-latest: true cache: yarn - name: Install dependencies run: yarn install @@ -485,6 +449,7 @@ jobs: shell: bash - name: Publish run: | + npm config set provenance true if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$"; then echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc diff --git a/package.json b/package.json index fbe486a..41b42ae 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ } }, "devDependencies": { - "@napi-rs/cli": "^2.14.6", + "@napi-rs/cli": "^2.15.2", "ava": "^5.1.1" }, "ava": {