feat(cli): new command upgrade

- Add .gitignore file
- Upgrade actions in CI.yml
- Using the new cross compile image for x86_64-linux-gnu and aarch64-linux-gnu
This commit is contained in:
LongYinan 2022-05-03 16:38:30 +08:00
parent a91a8b4201
commit 652aa3cc57
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7
7 changed files with 282 additions and 56 deletions

View file

@ -41,6 +41,14 @@ jobs:
push: true push: true
tags: ghcr.io/${{ github.repository }}/nodejs-rust:lts-debian tags: ghcr.io/${{ github.repository }}/nodejs-rust:lts-debian
- name: Build and push debian aarch64 cross
uses: docker/build-push-action@v2
with:
file: debian-aarch64.Dockerfile
platforms: linux/amd64
push: true
tags: ghcr.io/${{ github.repository }}/nodejs-rust:lts-debian-aarch64
- name: Build and push debian with zig - name: Build and push debian with zig
uses: docker/build-push-action@v2 uses: docker/build-push-action@v2
with: with:

View file

@ -0,0 +1,190 @@
export const GitIgnore = `# Created by https://www.toptal.com/developers/gitignore/api/node
# Edit at https://www.toptal.com/developers/gitignore?templates=node
### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# End of https://www.toptal.com/developers/gitignore/api/node
# Created by https://www.toptal.com/developers/gitignore/api/macos
# Edit at https://www.toptal.com/developers/gitignore?templates=macos
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### macOS Patch ###
# iCloud generated files
*.icloud
# End of https://www.toptal.com/developers/gitignore/api/macos
# Created by https://www.toptal.com/developers/gitignore/api/windows
# Edit at https://www.toptal.com/developers/gitignore?templates=windows
### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
# End of https://www.toptal.com/developers/gitignore/api/windows
#Added by cargo
/target
Cargo.lock
*.node
`

View file

@ -46,12 +46,11 @@ jobs:
architecture: 'x86' architecture: 'x86'
- host: ubuntu-latest - host: ubuntu-latest
target: 'x86_64-unknown-linux-gnu' target: 'x86_64-unknown-linux-gnu'
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine-zig docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
build: >- build: >-
set -e &&\n set -e &&\n
rustup target add x86_64-unknown-linux-gnu &&\n yarn build --target x86_64-unknown-linux-gnu &&\n
yarn build --target x86_64-unknown-linux-gnu --zig --zig-abi-suffix 2.12 &&\n strip *.node
llvm-strip -x *.node
- host: ubuntu-latest - host: ubuntu-latest
target: 'x86_64-unknown-linux-musl' target: 'x86_64-unknown-linux-musl'
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
@ -71,12 +70,11 @@ jobs:
strip -x *.node strip -x *.node
- host: ubuntu-latest - host: ubuntu-latest
target: 'aarch64-unknown-linux-gnu' target: 'aarch64-unknown-linux-gnu'
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine-zig docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64
build: >- build: >-
set -e &&\n set -e &&\n
rustup target add aarch64-unknown-linux-gnu &&\n yarn build --target aarch64-unknown-linux-gnu &&\n
yarn build --target aarch64-unknown-linux-gnu --zig --zig-abi-suffix 2.17 &&\n aarch64-unknown-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'
@ -144,26 +142,21 @@ jobs:
toolchain: stable toolchain: stable
target: \${{ matrix.settings.target }} target: \${{ matrix.settings.target }}
- name: Generate Cargo.lock
uses: actions-rs/cargo@v1
if: \${{ !matrix.settings.docker }}
with:
command: generate-lockfile
- name: Cache cargo - name: Cache cargo
uses: actions/cache@v2 uses: actions/cache@v3
with: with:
path: ~/.cargo/registry path: |
key: \${{ matrix.settings.target }}-cargo-registry ~/.cargo/registry/index/
~/.cargo/registry/cache/
- name: Cache cargo index ~/.cargo/git/db/
uses: actions/cache@v2 .cargo-cache/registry/index/
with: .cargo-cache/registry/cache/
path: ~/.cargo/git .cargo-cache/git/db/
key: \${{ matrix.settings.target }}-cargo-index target/
key: \${{ matrix.settings.target }}-cargo-\${{ matrix.settings.host }}
- name: Cache NPM dependencies - name: Cache NPM dependencies
uses: actions/cache@v2 uses: actions/cache@v3
with: with:
path: node_modules path: node_modules
key: npm-cache-build-\${{ matrix.settings.target }}-node@16 key: npm-cache-build-\${{ matrix.settings.target }}-node@16
@ -181,7 +174,7 @@ jobs:
if: \${{ matrix.settings.docker }} if: \${{ matrix.settings.docker }}
with: with:
image: \${{ matrix.settings.docker }} 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 options: --user 0:0 -v \${{ github.workspace }}/.cargo-cache/git/db:/root/.cargo/git/db -v \${{ github.workspace }}/.cargo/registry/cache:/root/.cargo/registry/cache -v \${{ github.workspace }}/.cargo/registry/index:/root/.cargo/registry/index -v \${{ github.workspace }}:/build -w /build
run: \${{ matrix.settings.build }} run: \${{ matrix.settings.build }}
- name: 'Build' - name: 'Build'
@ -190,7 +183,7 @@ jobs:
shell: bash shell: bash
- name: Upload artifact - name: Upload artifact
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v3
with: with:
name: bindings-\${{ matrix.settings.target }} name: bindings-\${{ matrix.settings.target }}
path: \${{ env.APP_NAME }}.*.node path: \${{ env.APP_NAME }}.*.node
@ -258,7 +251,7 @@ jobs:
target: 'x86_64-apple-darwin' target: 'x86_64-apple-darwin'
- host: windows-latest - host: windows-latest
target: 'x86_64-pc-windows-msvc' target: 'x86_64-pc-windows-msvc'
node: ['12', '14', '16'] node: ['14', '16', '18']
runs-on: \${{ matrix.settings.host }} runs-on: \${{ matrix.settings.host }}
steps: steps:
@ -272,7 +265,7 @@ jobs:
cache: 'yarn' cache: 'yarn'
- name: Cache NPM dependencies - name: Cache NPM dependencies
uses: actions/cache@v2 uses: actions/cache@v3
with: with:
path: node_modules path: node_modules
key: npm-cache-test-\${{ matrix.settings.target }}-\${{ matrix.node }}-\${{ hashFiles('yarn.lock') }} key: npm-cache-test-\${{ matrix.settings.target }}-\${{ matrix.node }}-\${{ hashFiles('yarn.lock') }}
@ -300,7 +293,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
node: ['12', '14', '16'] node: ['14', '16', '18']
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@ -314,10 +307,10 @@ jobs:
cache: 'yarn' cache: 'yarn'
- name: Cache NPM dependencies - name: Cache NPM dependencies
uses: actions/cache@v2 uses: actions/cache@v3
with: with:
path: node_modules path: node_modules
key: npm-cache-test-linux-x64-gnu-\${{ matrix.node }}-\${{ hashFiles('yarn.lock') }} key: npm-cache-test-linux-x64-gnu-\${{ matrix.node }}
- 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
@ -342,7 +335,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
node: ['12', '14', '16'] node: ['14', '16', '18']
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@ -356,10 +349,10 @@ jobs:
cache: 'yarn' cache: 'yarn'
- name: Cache NPM dependencies - name: Cache NPM dependencies
uses: actions/cache@v2 uses: actions/cache@v3
with: with:
path: node_modules path: node_modules
key: npm-cache-test-x86_64-unknown-linux-musl-\${{ matrix.node }}-\${{ hashFiles('yarn.lock') }} key: npm-cache-test-x86_64-unknown-linux-musl-\${{ matrix.node }}
- 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
@ -384,7 +377,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
node: ['12', '14', '16'] node: ['14', '16', '18']
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@ -403,10 +396,10 @@ jobs:
shell: bash shell: bash
- name: Cache NPM dependencies - name: Cache NPM dependencies
uses: actions/cache@v2 uses: actions/cache@v3
with: with:
path: node_modules path: node_modules
key: npm-cache-test-linux-aarch64-gnu-\${{ matrix.node }}-\${{ hashFiles('yarn.lock') }} key: npm-cache-test-linux-aarch64-gnu-\${{ matrix.node }}
- name: Install dependencies - name: Install dependencies
run: yarn install --ignore-scripts --ignore-platform --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 run: yarn install --ignore-scripts --ignore-platform --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
@ -444,10 +437,10 @@ jobs:
shell: bash shell: bash
- name: Cache NPM dependencies - name: Cache NPM dependencies
uses: actions/cache@v2 uses: actions/cache@v3
with: with:
path: node_modules path: node_modules
key: npm-cache-test-linux-aarch64-musl-\${{ matrix.node }}-\${{ hashFiles('yarn.lock') }} key: npm-cache-test-linux-aarch64-musl-\${{ matrix.node }}
- name: Install dependencies - name: Install dependencies
run: yarn install --ignore-scripts --ignore-platform --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 run: yarn install --ignore-scripts --ignore-platform --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
@ -469,7 +462,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
node: ['12', '14', '16'] node: ['14', '16', '18']
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@ -488,10 +481,10 @@ jobs:
shell: bash shell: bash
- name: Cache NPM dependencies - name: Cache NPM dependencies
uses: actions/cache@v2 uses: actions/cache@v3
with: with:
path: node_modules path: node_modules
key: npm-cache-test-linux-arm-gnueabihf-\${{ matrix.node }}-\${{ hashFiles('yarn.lock') }} key: npm-cache-test-linux-arm-gnueabihf-\${{ matrix.node }}
- name: Install dependencies - name: Install dependencies
run: yarn install --ignore-scripts --ignore-platform --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000 run: yarn install --ignore-scripts --ignore-platform --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
@ -529,12 +522,10 @@ jobs:
cache: 'yarn' cache: 'yarn'
- name: Cache NPM dependencies - name: Cache NPM dependencies
uses: actions/cache@v2 uses: actions/cache@v3
with: with:
path: node_modules path: node_modules
key: npm-cache-ubuntu-latest-\${{ hashFiles('yarn.lock') }} key: npm-cache-ubuntu-latest-publish
restore-keys: |
npm-cache-
- 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

View file

@ -9,6 +9,7 @@ import { CreateNpmDirCommand } from '../create-npm-dir'
import { debugFactory } from '../debug' import { debugFactory } from '../debug'
import { DefaultPlatforms } from '../parse-triple' import { DefaultPlatforms } from '../parse-triple'
import { GitIgnore } from './.gitignore-template'
import { createCargoContent } from './cargo' import { createCargoContent } from './cargo'
import { createCargoConfig } from './cargo-config' import { createCargoConfig } from './cargo-config'
import { createGithubActionsCIYml } from './ci-yml' import { createGithubActionsCIYml } from './ci-yml'
@ -200,6 +201,7 @@ test('sum from native', (t) => {
edition = "2021" edition = "2021"
`, `,
) )
this.writeFile('.gitignore', GitIgnore)
} }
private writeFile(path: string, content: string) { private writeFile(path: string, content: string) {

View file

@ -17,7 +17,7 @@ export const createPackageJson = (
license: 'MIT', license: 'MIT',
devDependencies: { devDependencies: {
'@napi-rs/cli': `^${version}`, '@napi-rs/cli': `^${version}`,
ava: '^4.0.1', ava: '^4.2.0',
}, },
engines: { engines: {
node: '>= 10', node: '>= 10',

35
debian-aarch64.Dockerfile Normal file
View file

@ -0,0 +1,35 @@
FROM messense/manylinux2014-cross:aarch64
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
CC=clang \
CXX=clang++ \
CC_aarch64_unknown_linux_gnu=clang \
CXX_aarch64_unknown_linux_gnu=clang++
RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \
echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main" >> /etc/apt/sources.list && \
echo "deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main" >> /etc/apt/sources.list && \
curl -sL https://deb.nodesource.com/setup_16.x | bash - && \
apt-get install -y --fix-missing --no-install-recommends \
curl \
llvm-14 \
clang-14 \
lld-14 \
nodejs \
xz-utils \
rcs \
git \
make \
ninja-build && \
apt-get autoremove -y && \
curl https://sh.rustup.rs -sSf | sh -s -- -y && \
rustup target add aarch64-unknown-linux-gnu && \
npm install -g yarn pnpm lerna && \
npm cache clean --force && \
npm cache verify && \
ln -sf /usr/bin/clang-14 /usr/bin/clang && \
ln -sf /usr/bin/clang++-14 /usr/bin/clang++ && \
ln -sf /usr/bin/lld-14 /usr/bin/lld && \
ln -sf /usr/bin/clang-14 /usr/bin/cc

View file

@ -11,14 +11,14 @@ ENV RUSTUP_HOME=/usr/local/rustup \
CXX_x86_64_unknown_linux_gnu=clang++ CXX_x86_64_unknown_linux_gnu=clang++
RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \ RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \
echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-13 main" >> /etc/apt/sources.list && \ echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main" >> /etc/apt/sources.list && \
echo "deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-13 main" >> /etc/apt/sources.list && \ echo "deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main" >> /etc/apt/sources.list && \
curl -sL https://deb.nodesource.com/setup_16.x | bash - && \ curl -sL https://deb.nodesource.com/setup_16.x | bash - && \
apt-get install -y --fix-missing --no-install-recommends \ apt-get install -y --fix-missing --no-install-recommends \
curl \ curl \
llvm-13 \ llvm-14 \
clang-13 \ clang-14 \
lld-13 \ lld-14 \
nodejs \ nodejs \
xz-utils \ xz-utils \
rcs \ rcs \
@ -34,10 +34,10 @@ RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \
rustup target add aarch64-unknown-linux-gnu && \ rustup target add aarch64-unknown-linux-gnu && \
rustup target add armv7-unknown-linux-gnueabihf && \ rustup target add armv7-unknown-linux-gnueabihf && \
npm install -g yarn pnpm lerna && \ npm install -g yarn pnpm lerna && \
ln -sf /usr/bin/clang-13 /usr/bin/clang && \ ln -sf /usr/bin/clang-14 /usr/bin/clang && \
ln -sf /usr/bin/clang++-13 /usr/bin/clang++ && \ ln -sf /usr/bin/clang++-14 /usr/bin/clang++ && \
ln -sf /usr/bin/lld-13 /usr/bin/lld && \ ln -sf /usr/bin/lld-14 /usr/bin/lld && \
ln -sf /usr/bin/clang-13 /usr/bin/cc ln -sf /usr/bin/clang-14 /usr/bin/cc
RUN wget https://www.nasm.us/pub/nasm/releasebuilds/${NASM_VERSION}/nasm-${NASM_VERSION}.tar.xz && \ RUN wget https://www.nasm.us/pub/nasm/releasebuilds/${NASM_VERSION}/nasm-${NASM_VERSION}.tar.xz && \
tar -xf nasm-${NASM_VERSION}.tar.xz && \ tar -xf nasm-${NASM_VERSION}.tar.xz && \