feat(cli): upgrade ci.yml templates

This commit is contained in:
LongYinan 2022-03-07 00:26:20 +08:00
parent f783e9537f
commit 1cac0ac804
6 changed files with 92 additions and 61 deletions

View file

@ -45,7 +45,7 @@ jobs:
- name: Install ziglang - name: Install ziglang
uses: goto-bus-stop/setup-zig@v1 uses: goto-bus-stop/setup-zig@v1
with: with:
version: 0.9.0 version: 0.9.1
- name: Cache NPM dependencies - name: Cache NPM dependencies
uses: actions/cache@v2 uses: actions/cache@v2
with: with:

View file

@ -1,6 +1,6 @@
FROM ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine FROM ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
ARG ZIG_VERSION=0.9.0 ARG ZIG_VERSION=0.9.1
RUN apk add xz && \ RUN apk add xz && \
rustup target add x86_64-unknown-linux-gnu && \ rustup target add x86_64-unknown-linux-gnu && \

View file

@ -46,33 +46,37 @@ jobs:
architecture: 'x86' architecture: 'x86'
- host: ubuntu-latest - host: ubuntu-latest
target: 'x86_64-unknown-linux-gnu' target: 'x86_64-unknown-linux-gnu'
architecture: 'x64' docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine-zig
docker: | build: >-
docker pull $DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-debian set -e &&\n
docker tag $DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-debian builder rustup target add x86_64-unknown-linux-gnu &&\n
build: | yarn build --target x86_64-unknown-linux-gnu --zig --zig-abi-suffix 2.12 &&\n
docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/build -w /build builder yarn build && strip *.node llvm-strip -x *.node
- host: ubuntu-latest - host: ubuntu-latest
target: 'x86_64-unknown-linux-musl' target: 'x86_64-unknown-linux-musl'
architecture: 'x64' docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
docker: | build: >-
docker pull $DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-alpine set -e &&
docker tag $DOCKER_REGISTRY_URL/napi-rs/napi-rs/nodejs-rust:lts-alpine builder yarn build &&
build: docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/build -w /build builder yarn build && strip *.node strip *.node
- host: macos-latest - host: macos-latest
target: 'aarch64-apple-darwin' target: 'aarch64-apple-darwin'
build: | build: |
yarn build --target=aarch64-apple-darwin 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 strip -x *.node
- host: ubuntu-latest - host: ubuntu-latest
architecture: 'x64'
target: 'aarch64-unknown-linux-gnu' target: 'aarch64-unknown-linux-gnu'
setup: | docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine-zig
sudo apt-get update build: >-
sudo apt-get install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu -y set -e &&\n
build: | rustup target add aarch64-unknown-linux-gnu &&\n
yarn build --target=aarch64-unknown-linux-gnu yarn build --target aarch64-unknown-linux-gnu --zig --zig-abi-suffix 2.17 &&\n
aarch64-linux-gnu-strip *.node llvm-strip -x *.node
- host: ubuntu-latest - host: ubuntu-latest
architecture: 'x64' architecture: 'x64'
target: 'armv7-unknown-linux-gnueabihf' target: 'armv7-unknown-linux-gnueabihf'
@ -105,12 +109,12 @@ jobs:
- host: ubuntu-latest - host: ubuntu-latest
architecture: 'x64' architecture: 'x64'
target: 'aarch64-unknown-linux-musl' target: 'aarch64-unknown-linux-musl'
downloadTarget: 'aarch64-unknown-linux-musl' docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
docker: | build: >-
docker pull ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine set -e &&\n
docker tag ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine builder rustup target add aarch64-unknown-linux-musl &&\n
build: | yarn build --target aarch64-unknown-linux-musl &&\n
docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/build -w /build builder sh -c "yarn build --target=aarch64-unknown-linux-musl && /aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip *.node" /aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip *.node
- host: windows-latest - host: windows-latest
architecture: 'x64' architecture: 'x64'
target: 'aarch64-pc-windows-msvc' target: 'aarch64-pc-windows-msvc'
@ -120,18 +124,20 @@ jobs:
runs-on: \${{ matrix.settings.host }} runs-on: \${{ matrix.settings.host }}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Setup node - name: Setup node
uses: actions/setup-node@v3 uses: actions/setup-node@v3
if: \${{ !matrix.settings.docker }}
with: with:
node-version: 16 node-version: 16
check-latest: true check-latest: true
cache: 'yarn' cache: yarn
architecture: \${{ matrix.settings.architecture }} architecture: \${{ matrix.settings.architecture }}
- name: Install - name: Install
uses: actions-rs/toolchain@v1 uses: actions-rs/toolchain@v1
if: \${{ !matrix.settings.docker }}
with: with:
profile: minimal profile: minimal
override: true override: true
@ -140,6 +146,7 @@ jobs:
- name: Generate Cargo.lock - name: Generate Cargo.lock
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
if: \${{ !matrix.settings.docker }}
with: with:
command: generate-lockfile command: generate-lockfile
@ -147,25 +154,19 @@ jobs:
uses: actions/cache@v2 uses: actions/cache@v2
with: with:
path: ~/.cargo/registry path: ~/.cargo/registry
key: \${{ matrix.settings.target }}-node@16-cargo-registry-trimmed-\${{ hashFiles('**/Cargo.lock') }} key: \${{ matrix.settings.target }}-cargo-registry
- name: Cache cargo index - name: Cache cargo index
uses: actions/cache@v2 uses: actions/cache@v2
with: with:
path: ~/.cargo/git path: ~/.cargo/git
key: \${{ matrix.settings.target }}-node@16-cargo-index-trimmed-\${{ hashFiles('**/Cargo.lock') }} key: \${{ matrix.settings.target }}-cargo-index
- name: Cache NPM dependencies - name: Cache NPM dependencies
uses: actions/cache@v2 uses: actions/cache@v2
with: with:
path: node_modules path: node_modules
key: npm-cache-\${{ matrix.settings.target }}-node@16-\${{ hashFiles('yarn.lock') }} key: npm-cache-build-\${{ matrix.settings.target }}-node@16
- name: Pull latest image
run: \${{ matrix.settings.docker }}
env:
DOCKER_REGISTRY_URL: ghcr.io
if: \${{ matrix.settings.docker }}
- name: Setup toolchain - name: Setup toolchain
run: \${{ matrix.settings.setup }} run: \${{ matrix.settings.setup }}
@ -175,8 +176,17 @@ jobs:
- name: 'Install dependencies' - name: 'Install dependencies'
run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
- name: Build in docker
uses: addnab/docker-run-action@v3
if: \${{ matrix.settings.docker }}
with:
image: \${{ matrix.settings.docker }}
options: -v \${{ env.HOME }}/.cargo/git:/root/.cargo/git -v \${{ env.HOME }}/.cargo/registry:/root/.cargo/registry -v \${{ github.workspace }}:/build -w /build
run: \${{ matrix.settings.build }}
- name: 'Build' - name: 'Build'
run: \${{ matrix.settings.build }} run: \${{ matrix.settings.build }}
if: \${{ !matrix.settings.docker }}
shell: bash shell: bash
- name: Upload artifact - name: Upload artifact
@ -190,10 +200,10 @@ jobs:
runs-on: macos-10.15 runs-on: macos-10.15
name: Build FreeBSD name: Build FreeBSD
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Build - name: Build
id: build id: build
uses: vmactions/freebsd-vm@v0.1.5 uses: vmactions/freebsd-vm@v0.1.6
env: env:
DEBUG: 'napi:*' DEBUG: 'napi:*'
RUSTUP_HOME: /usr/local/rustup RUSTUP_HOME: /usr/local/rustup
@ -230,7 +240,7 @@ jobs:
rm -rf node_modules rm -rf node_modules
rm -rf target rm -rf target
- name: Upload artifact - name: Upload artifact
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v3
with: with:
name: bindings-freebsd name: bindings-freebsd
path: \${{ env.APP_NAME }}.*.node path: \${{ env.APP_NAME }}.*.node
@ -252,7 +262,7 @@ jobs:
runs-on: \${{ matrix.settings.host }} runs-on: \${{ matrix.settings.host }}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Setup node - name: Setup node
uses: actions/setup-node@v3 uses: actions/setup-node@v3
@ -271,7 +281,7 @@ jobs:
run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
- name: Download artifacts - name: Download artifacts
uses: actions/download-artifact@v2 uses: actions/download-artifact@v3
with: with:
name: bindings-\${{ matrix.settings.target }} name: bindings-\${{ matrix.settings.target }}
path: . path: .
@ -294,7 +304,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Setup node - name: Setup node
uses: actions/setup-node@v3 uses: actions/setup-node@v3
@ -313,7 +323,7 @@ jobs:
run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
- name: Download artifacts - name: Download artifacts
uses: actions/download-artifact@v2 uses: actions/download-artifact@v3
with: with:
name: bindings-x86_64-unknown-linux-gnu name: bindings-x86_64-unknown-linux-gnu
path: . path: .
@ -336,7 +346,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Setup node - name: Setup node
uses: actions/setup-node@v3 uses: actions/setup-node@v3
@ -355,7 +365,7 @@ jobs:
run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
- name: Download artifacts - name: Download artifacts
uses: actions/download-artifact@v2 uses: actions/download-artifact@v3
with: with:
name: bindings-x86_64-unknown-linux-musl name: bindings-x86_64-unknown-linux-musl
path: . path: .
@ -380,10 +390,10 @@ jobs:
steps: steps:
- run: docker run --rm --privileged multiarch/qemu-user-static:register --reset - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Download artifacts - name: Download artifacts
uses: actions/download-artifact@v2 uses: actions/download-artifact@v3
with: with:
name: bindings-aarch64-unknown-linux-gnu name: bindings-aarch64-unknown-linux-gnu
path: . path: .
@ -421,10 +431,10 @@ jobs:
steps: steps:
- run: docker run --rm --privileged multiarch/qemu-user-static:register --reset - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Download artifacts - name: Download artifacts
uses: actions/download-artifact@v2 uses: actions/download-artifact@v3
with: with:
name: bindings-aarch64-unknown-linux-musl name: bindings-aarch64-unknown-linux-musl
path: . path: .
@ -465,10 +475,10 @@ jobs:
steps: steps:
- run: docker run --rm --privileged multiarch/qemu-user-static:register --reset - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Download artifacts - name: Download artifacts
uses: actions/download-artifact@v2 uses: actions/download-artifact@v3
with: with:
name: bindings-armv7-unknown-linux-gnueabihf name: bindings-armv7-unknown-linux-gnueabihf
path: . path: .
@ -509,7 +519,7 @@ jobs:
- build-freebsd - build-freebsd
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: Setup node - name: Setup node
uses: actions/setup-node@v3 uses: actions/setup-node@v3
@ -529,7 +539,7 @@ jobs:
run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 run: yarn install --ignore-scripts --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
- name: Download all artifacts - name: Download all artifacts
uses: actions/download-artifact@v2 uses: actions/download-artifact@v3
with: with:
path: artifacts path: artifacts

View file

@ -115,8 +115,12 @@ export class NewProjectCommand extends Command {
debug(`Running command: ${chalk.green('[${command}]')}`) debug(`Running command: ${chalk.green('[${command}]')}`)
if (!this.dryRun) { if (!this.dryRun) {
mkdirSync(join(process.cwd(), this.dirname!)) mkdirSync(join(process.cwd(), this.dirname!), {
mkdirSync(join(process.cwd(), this.dirname!, 'src')) recursive: true,
})
mkdirSync(join(process.cwd(), this.dirname!, 'src'), {
recursive: true,
})
} }
const [s, pkgName] = this.name!.split('/') const [s, pkgName] = this.name!.split('/')
@ -135,12 +139,27 @@ export class NewProjectCommand extends Command {
) )
this.writeFile('src/lib.rs', LibRs) this.writeFile('src/lib.rs', LibRs)
mkdirSync(join(process.cwd(), this.dirname!, '__test__'), {
recursive: true,
})
this.writeFile(
'__test__/index.spec.mjs',
`import test from 'ava'
import { sum } from '../index.js'
test('sum from native', (t) => {
t.is(sum(1, 2), 3)
})
`,
)
if (this.enableGithubActions) { if (this.enableGithubActions) {
const githubDir = join(process.cwd(), this.dirname!, '.github') const githubDir = join(process.cwd(), this.dirname!, '.github')
const workflowsDir = join(githubDir, 'workflows') const workflowsDir = join(githubDir, 'workflows')
if (!this.dryRun) { if (!this.dryRun) {
mkdirSync(githubDir) mkdirSync(githubDir, { recursive: true })
mkdirSync(workflowsDir) mkdirSync(workflowsDir, { recursive: true })
} }
this.writeFile( this.writeFile(
join('.github', 'workflows', 'CI.yml'), join('.github', 'workflows', 'CI.yml'),
@ -171,7 +190,7 @@ export class NewProjectCommand extends Command {
if (cargoConfig.length) { if (cargoConfig.length) {
const configDir = join(process.cwd(), this.dirname!, '.cargo') const configDir = join(process.cwd(), this.dirname!, '.cargo')
if (!this.dryRun) { if (!this.dryRun) {
mkdirSync(configDir) mkdirSync(configDir, { recursive: true })
this.writeFile(join('.cargo', 'config.toml'), cargoConfig) this.writeFile(join('.cargo', 'config.toml'), cargoConfig)
} }
} }

View file

@ -17,6 +17,7 @@ export const createPackageJson = (
license: 'MIT', license: 'MIT',
devDependencies: { devDependencies: {
'@napi-rs/cli': `^${version}`, '@napi-rs/cli': `^${version}`,
ava: '^4.0.1',
}, },
engines: { engines: {
node: '>= 10', node: '>= 10',
@ -26,6 +27,7 @@ export const createPackageJson = (
build: 'napi build --platform --release', build: 'napi build --platform --release',
'build:debug': 'napi build --platform', 'build:debug': 'napi build --platform',
prepublishOnly: 'napi prepublish -t npm', prepublishOnly: 'napi prepublish -t npm',
test: 'ava',
version: 'napi version', version: 'napi version',
}, },
} }

View file

@ -1,6 +1,6 @@
FROM ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian FROM ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
ARG ZIG_VERSION=0.9.0 ARG ZIG_VERSION=0.9.1
RUN wget https://ziglang.org/download/${ZIG_VERSION}/zig-linux-x86_64-${ZIG_VERSION}.tar.xz && \ RUN wget https://ziglang.org/download/${ZIG_VERSION}/zig-linux-x86_64-${ZIG_VERSION}.tar.xz && \
tar -xvf zig-linux-x86_64-${ZIG_VERSION}.tar.xz && \ tar -xvf zig-linux-x86_64-${ZIG_VERSION}.tar.xz && \