From e34b3dc5c2c86c7b0b37c319fb2f35d7d7caf3bf Mon Sep 17 00:00:00 2001 From: LongYinan Date: Wed, 29 Jul 2020 22:04:47 +0800 Subject: [PATCH] ci: upgrade pipeline --- .github/workflows/lint.yaml | 62 ++++++++++++++++ .github/workflows/linux-musl.yaml | 8 +- .github/workflows/linux.yaml | 74 ------------------- .github/workflows/macos.yaml | 74 ------------------- .github/workflows/napi3.yaml | 21 +++++- .github/workflows/{windows.yaml => test.yaml} | 52 ++++++++----- package.json | 7 +- 7 files changed, 124 insertions(+), 174 deletions(-) create mode 100644 .github/workflows/lint.yaml delete mode 100644 .github/workflows/linux.yaml delete mode 100644 .github/workflows/macos.yaml rename .github/workflows/{windows.yaml => test.yaml} (60%) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 00000000..50688315 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,62 @@ +name: Lint + +on: [push, pull_request] + +jobs: + lint: + name: Lint SourceCode + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Setup node + uses: actions/setup-node@v1 + with: + node-version: 12 + + - name: Install + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: default + 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: lint-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }} + + - name: Cache cargo index + uses: actions/cache@v1 + with: + path: ~/.cargo/git + key: lint-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }} + + - name: Cache NPM dependencies + uses: actions/cache@v1 + with: + path: node_modules + key: lint-${{ hashFiles('yarn.lock') }} + restore-keys: | + npm-cache- + + - name: 'Install dependencies' + run: yarn install --frozen-lockfile --registry https://registry.npmjs.org + + - name: 'Lint JS/TS' + run: yarn lint + + - name: 'Lint rust' + run: cargo fmt -- --check + + - name: Clear the cargo caches + run: | + cargo install cargo-cache --no-default-features --features ci-autoclean + cargo-cache diff --git a/.github/workflows/linux-musl.yaml b/.github/workflows/linux-musl.yaml index 4ad5fe9b..0dbd2fe3 100644 --- a/.github/workflows/linux-musl.yaml +++ b/.github/workflows/linux-musl.yaml @@ -27,6 +27,12 @@ jobs: 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: 'Install node dependencies' + run: docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/napi-rs -w /napi-rs builder yarn + + - name: 'Build TypeScript' + run: docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/napi-rs -w /napi-rs builder yarn build + - name: Run check run: | docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/napi-rs -w /napi-rs builder cargo check --all --bins --examples --tests -vvv @@ -37,6 +43,6 @@ jobs: - name: Unit test run: | - docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/napi-rs -w /napi-rs builder sh -c "yarn && yarn --cwd ./test_module build && yarn test" + docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/napi-rs -w /napi-rs builder sh -c "yarn --cwd ./test_module build && yarn test" env: RUST_BACKTRACE: 1 diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml deleted file mode 100644 index d1603e6a..00000000 --- a/.github/workflows/linux.yaml +++ /dev/null @@ -1,74 +0,0 @@ -name: Linux - -on: [push, pull_request] - -jobs: - build_and_test: - strategy: - fail-fast: false - matrix: - node: ['10', '12', '14'] - - name: stable - x86_64-unknown-linux-gnu - node@${{ matrix.node }} - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Setup node - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node }} - - - name: Install stable - uses: actions-rs/toolchain@v1 - with: - toolchain: stable-x86_64-unknown-linux-gnu - 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-x86_64-unknown-linux-gnu-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }} - - name: Cache cargo index - uses: actions/cache@v1 - with: - path: ~/.cargo/git - key: stable-x86_64-unknown-linux-gnu-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }} - - name: Cache cargo build - uses: actions/cache@v1 - with: - path: target - key: stable-x86_64-unknown-linux-gnu-cargo-build-trimmed-${{ hashFiles('**/Cargo.lock') }} - - - name: Check build - uses: actions-rs/cargo@v1 - with: - command: check - args: --all --bins --examples --tests -vvv - - - name: Tests - uses: actions-rs/cargo@v1 - timeout-minutes: 5 - with: - command: test - args: -p napi-sys --lib -- --nocapture - - - name: Unit tests - run: | - yarn - yarn --cwd ./test_module build - yarn test - env: - RUST_BACKTRACE: 1 - - - name: Clear the cargo caches - run: | - cargo install cargo-cache --no-default-features --features ci-autoclean - cargo-cache diff --git a/.github/workflows/macos.yaml b/.github/workflows/macos.yaml deleted file mode 100644 index 1f95d00a..00000000 --- a/.github/workflows/macos.yaml +++ /dev/null @@ -1,74 +0,0 @@ -name: macOS - -on: [push, pull_request] - -jobs: - build_and_test: - strategy: - fail-fast: false - matrix: - node: ['10', '12', '14'] - - name: stable - x86_64-apple-darwin - node@${{ matrix.node }} - runs-on: macos-latest - - steps: - - uses: actions/checkout@v2 - - - name: Setup node - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node }} - - - name: Install stable - uses: actions-rs/toolchain@v1 - with: - toolchain: stable-x86_64-apple-darwin - 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-x86_64-apple-darwin-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }} - - name: Cache cargo index - uses: actions/cache@v1 - with: - path: ~/.cargo/git - key: stable-x86_64-apple-darwin-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }} - - name: Cache cargo build - uses: actions/cache@v1 - with: - path: target - key: stable-x86_64-apple-darwin-cargo-build-trimmed-${{ hashFiles('**/Cargo.lock') }} - - - name: Check build - uses: actions-rs/cargo@v1 - with: - command: check - args: --all --bins --examples --tests -vvv - - - name: Tests - uses: actions-rs/cargo@v1 - timeout-minutes: 5 - with: - command: test - args: -p napi-sys --lib -- --nocapture - - - name: Unit tests - run: | - yarn - yarn --cwd ./test_module build - yarn test - env: - RUST_BACKTRACE: 1 - - - name: Clear the cargo caches - run: | - cargo install cargo-cache --no-default-features --features ci-autoclean - cargo-cache diff --git a/.github/workflows/napi3.yaml b/.github/workflows/napi3.yaml index 57564d79..13d2212b 100644 --- a/.github/workflows/napi3.yaml +++ b/.github/workflows/napi3.yaml @@ -31,17 +31,31 @@ jobs: uses: actions/cache@v1 with: path: ~/.cargo/registry - key: stable-x86_64-unknown-linux-gnu-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }} + key: stable-napi3-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }} - name: Cache cargo index uses: actions/cache@v1 with: path: ~/.cargo/git - key: stable-x86_64-unknown-linux-gnu-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }} + key: stable-napi3-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }} - name: Cache cargo build uses: actions/cache@v1 with: path: target - key: stable-x86_64-unknown-linux-gnu-cargo-build-trimmed-${{ hashFiles('**/Cargo.lock') }} + key: stable-napi3-cargo-build-trimmed-${{ hashFiles('**/Cargo.lock') }} + + - name: Cache NPM dependencies + uses: actions/cache@v1 + with: + path: node_modules + key: napi3-${{ hashFiles('yarn.lock') }} + restore-keys: | + npm-cache- + + - name: 'Install dependencies' + run: yarn add ava@2 --dev --ignore-engines + + - name: 'Build TypeScript' + run: yarn build - name: Check build uses: actions-rs/cargo@v1 @@ -58,7 +72,6 @@ jobs: - name: Unit tests run: | - yarn add ava@2 --dev --ignore-engines yarn --cwd ./test_module build yarn test env: diff --git a/.github/workflows/windows.yaml b/.github/workflows/test.yaml similarity index 60% rename from .github/workflows/windows.yaml rename to .github/workflows/test.yaml index bcffd24f..02b3489d 100644 --- a/.github/workflows/windows.yaml +++ b/.github/workflows/test.yaml @@ -1,4 +1,4 @@ -name: Windows +name: Test on: [push, pull_request] @@ -8,11 +8,10 @@ jobs: fail-fast: false matrix: node: ['10', '12', '14'] - target: - - x86_64-pc-windows-msvc + os: [ubuntu-latest, macos-latest, windows-latest] - name: stable - ${{ matrix.target }} - node@${{ matrix.node }} - runs-on: windows-latest + name: stable - ${{ matrix.os }} - node@${{ matrix.node }} + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 @@ -21,37 +20,54 @@ jobs: uses: actions/setup-node@v1 with: node-version: ${{ matrix.node }} - - name: Install stable - uses: actions-rs/toolchain@v1 - with: - toolchain: stable-${{ matrix.target }} - profile: minimal - override: true + - name: Install llvm + if: matrix.os == 'windows-latest' run: choco install -y llvm - - name: set environment variables - uses: allenevans/set-env@v1.1.0 + + - name: Set llvm path + if: matrix.os == 'windows-latest' + uses: allenevans/set-env@v1.0.0 with: LIBCLANG_PATH: 'C:\Program Files\LLVM\bin' + + - 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.target }}-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }} + key: stable-${{ matrix.os }}-node@${{ matrix.node }}-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }} + - name: Cache cargo index uses: actions/cache@v1 with: path: ~/.cargo/git - key: stable-${{ matrix.target }}-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }} - - name: Cache cargo build + key: stable-${{ matrix.os }}gnu-node@${{ matrix.node }}-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }} + + - name: Cache NPM dependencies uses: actions/cache@v1 with: - path: target - key: stable-${{ matrix.target }}-cargo-build-trimmed-${{ hashFiles('**/Cargo.lock') }} + path: node_modules + key: npm-cache-${{ matrix.os }}-node@${{ matrix.node }}-${{ hashFiles('yarn.lock') }} + restore-keys: | + npm-cache- + + - name: 'Install dependencies' + run: yarn install --frozen-lockfile --registry https://registry.npmjs.org + + - name: 'Build TypeScript' + run: yarn build - name: Check build uses: actions-rs/cargo@v1 diff --git a/package.json b/package.json index d77ca325..c9a676ca 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.2.4", "description": "A minimal library for building compiled Node add-ons in Rust.", "bin": { - "napi": "scripts/napi.js" + "napi": "scripts/index.js" }, "repository": { "type": "git", @@ -18,12 +18,14 @@ ], "license": "MIT", "scripts": { + "build": "tsc -p tsconfig.json", "format": "run-p format:md format:json format:yaml format:source format:rs", "format:md": "prettier --parser markdown --write './**/*.md'", "format:json": "prettier --parser json --write './**/*.json'", "format:rs": "cargo fmt", "format:source": "prettier --config ./package.json --write './**/*.js'", "format:yaml": "prettier --parser yaml --write './**/*.{yml,yaml}'", + "lint": "eslint -c .eslintrc.yml", "test": "ava" }, "bugs": { @@ -33,7 +35,6 @@ "dependencies": { "clipanion": "^2.4.2", "inquirer": "^7.3.3", - "minimist": "^1.2.5", "toml": "^3.0.0" }, "prettier": { @@ -43,7 +44,7 @@ "trailingComma": "all", "arrowParens": "always" }, - "files": ["scripts/napi.js", "LICENSE"], + "files": ["scripts", "LICENSE"], "lint-staged": { "*.js": ["prettier --write"], "*.@(yml|yaml)": ["prettier --parser yaml --write"],