name: CI env: DEBUG: 'napi:*' APP_NAME: 'package-template' on: push: branches: - main tags-ignore: - '**' pull_request: jobs: build: if: "!contains(github.event.head_commit.message, 'skip ci')" strategy: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] name: stable - ${{ matrix.os }} - node@14 runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 - name: Setup node uses: actions/setup-node@v2 with: node-version: 14 check-latest: true - name: Install uses: actions-rs/toolchain@v1 with: toolchain: stable profile: minimal override: true - name: Generate Cargo.lock uses: actions-rs/cargo@v1 with: command: generate-lockfile - name: Cache cargo registry uses: actions/cache@v1 with: path: ~/.cargo/registry key: stable-${{ matrix.os }}-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }} - name: Cache cargo index uses: actions/cache@v1 with: path: ~/.cargo/git key: stable-${{ matrix.os }}-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }} - name: Cache NPM dependencies uses: actions/cache@v1 with: path: node_modules key: npm-cache-${{ matrix.os }}-node@14-${{ hashFiles('yarn.lock') }} - name: 'Install dependencies' run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 - name: 'Build' run: yarn build env: MACOSX_DEPLOYMENT_TARGET: '10.13' - name: Upload artifact uses: actions/upload-artifact@v2 with: name: bindings-${{ matrix.os }} path: ${{ env.APP_NAME }}.*.node - name: Clear the cargo caches run: | cargo install cargo-cache --no-default-features --features ci-autoclean cargo-cache build-windows-i686: if: "!contains(github.event.head_commit.message, 'skip ci')" name: stable - windows-i686 - node@10 runs-on: windows-latest env: CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 32 CARGO_PROFILE_RELEASE_LTO: 'false' steps: - uses: actions/checkout@v2 - name: Install node x86 run: | choco install nodejs-lts --x86 -y --force refreshenv - name: Set 32bit NodeJS path run: | echo "C:\\Program Files (x86)\\nodejs" >> $GITHUB_PATH shell: bash - name: NodeJS arch run: node -e "console.log(process.arch)" - name: Cache NPM dependencies uses: actions/cache@v1 with: path: node_modules key: npm-cache-windows-i686-node@lts-${{ hashFiles('yarn.lock') }} - name: Install dependencies run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 - name: Install uses: actions-rs/toolchain@v1 with: toolchain: stable profile: minimal override: true - name: Install i686 toolchain run: rustup target add i686-pc-windows-msvc - name: Generate Cargo.lock uses: actions-rs/cargo@v1 with: command: generate-lockfile - name: Cache cargo registry uses: actions/cache@v1 with: path: ~/.cargo/registry key: stable-windows-i686-node@lts-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }} - name: Cache cargo index uses: actions/cache@v1 with: path: ~/.cargo/git key: stable-windows-i686-node@lts-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }} - name: Cross build i686 run: yarn build --target i686-pc-windows-msvc - name: Test binary run: yarn test - name: Upload artifact uses: actions/upload-artifact@v2 with: name: bindings-win32-i686 path: ${{ env.APP_NAME }}.*.node build-linux-musl: if: "!contains(github.event.head_commit.message, 'skip ci')" name: stable - linux-musl - node@10 runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Login to registry run: | docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD $DOCKER_REGISTRY_URL env: DOCKER_REGISTRY_URL: docker.pkg.github.com DOCKER_USERNAME: ${{ github.actor }} DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }} - name: Pull docker image run: | docker pull docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts docker tag docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts builder - name: Generate Cargo.lock uses: actions-rs/cargo@v1 with: command: generate-lockfile - name: Cache cargo registry uses: actions/cache@v1 with: path: ~/.cargo/registry key: stable-node-alpine-@10-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }} - name: Cache cargo index uses: actions/cache@v1 with: path: ~/.cargo/git key: stable-node-alpine-@10-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }} - name: Cache NPM dependencies uses: actions/cache@v1 with: path: node_modules key: npm-cache-alpine-node@10-${{ hashFiles('yarn.lock') }} - name: 'Install dependencies' run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 - name: 'Build' run: | docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/${{ env.APP_NAME }} -e DEBUG="napi:*" -w /${{ env.APP_NAME }} builder sh -c "yarn build" - name: Upload artifact uses: actions/upload-artifact@v2 with: name: bindings-linux-musl path: ${{ env.APP_NAME }}.*.node build-linux-arm7: name: stable - arm7-unknown-linux-gnu - node@14 runs-on: ubuntu-latest steps: - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset - uses: actions/checkout@v2 - name: Setup node uses: actions/setup-node@v1 with: node-version: 14 - name: Install uses: actions-rs/toolchain@v1 with: toolchain: stable profile: minimal override: true - name: Generate Cargo.lock uses: actions-rs/cargo@v1 with: command: generate-lockfile - name: Cache cargo registry uses: actions/cache@v1 with: path: ~/.cargo/registry key: stable-linux-arm7-gnu-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }} - name: Cache cargo index uses: actions/cache@v1 with: path: ~/.cargo/git key: stable-linux-arm7-gnu-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }} - name: Cache NPM dependencies uses: actions/cache@v1 with: path: node_modules key: npm-cache-linux-arm7-gnu-node@14-${{ hashFiles('yarn.lock') }} - name: Install aarch64 toolchain run: rustup target add armv7-unknown-linux-gnueabihf - name: Install cross compile toolchain run: | sudo apt-get update sudo apt-get install gcc-arm-linux-gnueabihf -y - name: Install dependencies run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 - name: Cross build arm7 run: yarn build --target armv7-unknown-linux-gnueabihf - name: Upload artifact uses: actions/upload-artifact@v2 with: name: bindings-linux-arm7 path: ${{ env.APP_NAME }}.*.node build-linux-aarch64: name: stable - aarch64-unknown-linux-gnu - node@14 runs-on: ubuntu-latest steps: - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset - uses: actions/checkout@v2 - name: Setup node uses: actions/setup-node@v2 with: node-version: 14 check-latest: true - name: Install uses: actions-rs/toolchain@v1 with: toolchain: stable profile: minimal override: true - name: Install aarch64 toolchain run: rustup target add aarch64-unknown-linux-gnu - name: Generate Cargo.lock uses: actions-rs/cargo@v1 with: command: generate-lockfile - name: Cache cargo registry uses: actions/cache@v1 with: path: ~/.cargo/registry key: stable-linux-aarch64-gnu-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }} - name: Cache cargo index uses: actions/cache@v1 with: path: ~/.cargo/git key: stable-linux-aarch64-gnu-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }} - name: Cache NPM dependencies uses: actions/cache@v1 with: path: node_modules key: npm-cache-linux-aarch64-gnu-node@14-${{ hashFiles('yarn.lock') }} - name: Install cross compile toolchain run: | sudo apt-get update sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu -y - name: Install dependencies run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 - name: Cross build aarch64 run: yarn build --target aarch64-unknown-linux-gnu - name: Upload artifact uses: actions/upload-artifact@v2 with: name: bindings-linux-aarch64 path: ${{ env.APP_NAME }}.*.node build-apple-silicon: name: stable - aarch64-apple-darwin - node@14 runs-on: macos-latest steps: - uses: actions/checkout@v2 - name: Setup node uses: actions/setup-node@v2 with: node-version: 14 check-latest: true - name: Install uses: actions-rs/toolchain@v1 with: toolchain: stable profile: minimal override: true - name: Install aarch64 toolchain run: rustup target add aarch64-apple-darwin - name: Generate Cargo.lock uses: actions-rs/cargo@v1 with: command: generate-lockfile - name: Cache cargo registry uses: actions/cache@v1 with: path: ~/.cargo/registry key: stable-apple-aarch64-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }} - name: Cache cargo index uses: actions/cache@v1 with: path: ~/.cargo/git key: stable-apple-aarch64-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }} - name: Cache NPM dependencies uses: actions/cache@v1 with: path: node_modules key: npm-cache-apple-aarch64-node@14-${{ hashFiles('yarn.lock') }} - name: Install dependencies run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 - name: Cross build aarch64 run: yarn build --target aarch64-apple-darwin - name: Upload artifact uses: actions/upload-artifact@v2 with: name: bindings-apple-aarch64 path: ${{ env.APP_NAME }}.*.node build-android-aarch64: name: Build - Android - aarch64 runs-on: macos-latest steps: - uses: actions/checkout@v2 - name: Setup node uses: actions/setup-node@v1 with: node-version: 14 - name: Install aarch64 toolchain run: rustup target add aarch64-linux-android - name: Generate Cargo.lock uses: actions-rs/cargo@v1 with: command: generate-lockfile - name: Cache cargo registry uses: actions/cache@v1 with: path: ~/.cargo/registry key: stable-apple-aarch64-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }} - name: Cache cargo index uses: actions/cache@v1 with: path: ~/.cargo/git key: stable-apple-aarch64-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }} - name: Cache NPM dependencies uses: actions/cache@v1 with: path: node_modules key: npm-cache-apple-aarch64-node@14-${{ hashFiles('yarn.lock') }} - name: Install dependencies run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 - name: Build shell: bash run: | export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android24-clang" yarn build --target aarch64-linux-android - name: Upload artifact uses: actions/upload-artifact@v2 with: name: bindings-android-aarch64 path: ${{ env.APP_NAME }}.*.node test: name: Test bindings on ${{ matrix.os }} - node@${{ matrix.node }} needs: - build strategy: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] node: ['10', '12', '14', '15'] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 - name: Setup node uses: actions/setup-node@v2 with: node-version: ${{ matrix.node }} check-latest: true - name: Cache NPM dependencies uses: actions/cache@v1 with: path: node_modules key: npm-cache-test-${{ matrix.os }}-node@${{ matrix.node }}-${{ hashFiles('yarn.lock') }} - name: 'Install dependencies' run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 - name: Download artifacts uses: actions/download-artifact@v2 with: name: bindings-${{ matrix.os }} path: . - name: List packages run: ls -R . shell: bash - name: Test bindings run: yarn test test-musl: name: Test bindings on alpine - node@${{ matrix.node }} needs: - build-linux-musl strategy: fail-fast: false matrix: node: ['10', '12', '14', '15'] runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Cache NPM dependencies uses: actions/cache@v1 with: path: node_modules key: npm-cache-alpine-node@${{ matrix.node }}-${{ hashFiles('yarn.lock') }} - name: 'Install dependencies' run: yarn install --frozen-lockfile --ignore-scripts --registry https://registry.npmjs.org --network-timeout 300000 - name: Download artifacts uses: actions/download-artifact@v2 with: name: bindings-linux-musl path: . - name: List files run: ls -R . shell: bash - name: Run tests run: docker run --rm -v $(pwd):/${{ env.APP_NAME }} -w /${{ env.APP_NAME }} node:${{ matrix.node }}-alpine sh -c "yarn test" test-aarch64: name: stable - aarch64-unknown-linux-gnu - node@${{ matrix.node }} runs-on: ubuntu-latest needs: - build-linux-aarch64 strategy: fail-fast: false matrix: node: ['10', '12', '14', '15'] steps: - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset - uses: actions/checkout@v2 - name: Setup node uses: actions/setup-node@v2 with: node-version: ${{ matrix.node }} check-latest: true - name: Cache NPM dependencies uses: actions/cache@v1 with: path: node_modules key: npm-cache-test-linux-aarch64-gnu-node@${{ matrix.node }}-${{ hashFiles('yarn.lock') }} - name: 'Install dependencies' run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 - name: Download artifacts uses: actions/download-artifact@v2 with: name: bindings-linux-aarch64 path: . - name: List run: ls -a - name: Run tests uses: docker://multiarch/ubuntu-core:arm64-focal with: args: > sh -c " apt-get update && \ apt-get install -y ca-certificates gnupg2 curl && \ curl -sL https://deb.nodesource.com/setup_${{ matrix.node }}.x | bash - && \ apt-get install -y nodejs && \ node ./simple-test.js " dependabot: needs: - test - test-musl - test-aarch64 - build-windows-i686 - build-apple-silicon - build-linux-arm7 - build-android-aarch64 runs-on: ubuntu-latest steps: - name: auto-merge uses: ridedott/dependabot-auto-merge-action@master with: GITHUB_LOGIN: dependabot[bot] GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} publish: name: Publish runs-on: ubuntu-latest needs: - test - test-musl - test-aarch64 - build-windows-i686 - build-apple-silicon - build-linux-arm7 - build-android-aarch64 steps: - uses: actions/checkout@v2 - name: Setup node uses: actions/setup-node@v2 with: node-version: 14 check-latest: true - name: Cache NPM dependencies uses: actions/cache@v1 with: path: node_modules key: npm-cache-publish-ubuntu-latest-${{ hashFiles('yarn.lock') }} - name: 'Install dependencies' run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 - name: Download all artifacts uses: actions/download-artifact@v2 with: path: artifacts - name: Move artifacts run: yarn artifacts - name: List packages run: ls -R npm shell: bash - name: Publish run: | if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$"; then echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc npm publish --access public elif git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+"; then echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc npm publish --tag next --access public else echo "Not a release, skipping publish" fi env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }}