Skip to content

Commit

Permalink
feat: 更新 CI 配置
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Dec 11, 2023
1 parent 8bd0342 commit 5f2ba64
Show file tree
Hide file tree
Showing 8 changed files with 681 additions and 113 deletions.
198 changes: 198 additions & 0 deletions .github/workflows/build-rust-binding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
name: Build Rust Binaries

on:
workflow_call:
inputs:
name:
description: 'The name of the binary to build'
required: false
default: 'taro'
type: string

jobs:
build:
strategy:
fail-fast: false
matrix:
settings:
- host: macos-latest
target: x86_64-apple-darwin
build: |
pnpm build:binding:release
strip -x *.node
- host: windows-latest
build: pnpm build:binding:release
target: x86_64-pc-windows-msvc
- host: ubuntu-latest
target: x86_64-unknown-linux-gnu
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
build: |-
set -e &&
pnpm build:binding:release --target x86_64-unknown-linux-gnu &&
strip *.node
- host: macos-latest
target: aarch64-apple-darwin
build: |
pnpm build:binding:release --target aarch64-apple-darwin
strip -x *.node
name: stable - ${{ matrix.settings.target }}
runs-on: ${{ matrix.settings.host }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref || github.head_ref || github.ref_name }}
- name: Setup Node.js
uses: actions/setup-node@v3
if: ${{ !matrix.settings.docker }}
with:
node-version: 16
check-latest: true
- name: Rust Install
uses: dtolnay/rust-toolchain@stable
if: ${{ !matrix.settings.docker }}
with:
toolchain: stable
targets: ${{ matrix.settings.target }}
# Bootstrap project
- name: Cache pnpm modules
uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- name: Pnpm Install
uses: pnpm/action-setup@v2.4.0
with:
version: 7
run_install: |
- recursive: true
args: [--frozen-lockfile]
- name: Build in docker
uses: addnab/docker-run-action@v3
if: ${{ matrix.settings.docker }}
with:
image: ${{ matrix.settings.docker }}
options: '--user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build'
run: ${{ matrix.settings.build }}
- name: Build
run: ${{ matrix.settings.build }}
if: ${{ !matrix.settings.docker }}
shell: bash
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: bindings-${{ matrix.settings.target }}
path: ${{ inputs.name }}.*.node
if-no-files-found: error
test-macOS-windows-binding:
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
needs:
- build
strategy:
fail-fast: false
matrix:
settings:
- host: macos-latest
target: x86_64-apple-darwin
- host: windows-latest
target: x86_64-pc-windows-msvc
node:
- '14'
- '16'
runs-on: ${{ matrix.settings.host }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref || github.head_ref || github.ref_name }}
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
check-latest: true
cache: pnpm
- name: Install dependencies
run: pnpm install
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: bindings-${{ matrix.settings.target }}
path: .
- name: List packages
run: ls -R .
shell: bash
- name: Test bindings
run: pnpm test:binding
test-linux-x64-gnu-binding:
name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
needs:
- build
strategy:
fail-fast: false
matrix:
node:
- '14'
- '16'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref || github.head_ref || github.ref_name }}
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
check-latest: true
cache: pnpm
- name: Install dependencies
run: pnpm install
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: bindings-x86_64-unknown-linux-gnu
path: .
- name: List packages
run: ls -R .
shell: bash
- name: Test bindings
run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim pnpm test:binding
universal-macOS:
name: Build universal macOS binary
needs:
- build
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref || github.head_ref || github.ref_name }}
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16
check-latest: true
cache: pnpm
- name: Install dependencies
run: pnpm 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: pnpm universal
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: bindings-universal-apple-darwin
path: ${{ inputs.name }}.*.node
if-no-files-found: error

17 changes: 12 additions & 5 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: Node CI

env:
DEBUG: napi:*
MACOSX_DEPLOYMENT_TARGET: '10.13'
on:
push:
branches:
Expand All @@ -13,10 +15,15 @@ permissions:
contents: read # to fetch code (actions/checkout)

jobs:
build-rust-binding:
name: Build Rust Binding
uses: ./.github/workflows/build-rust-binding.yml
with:
name: "taro"
build:

runs-on: ubuntu-latest

needs: [build-rust-binding]
strategy:
fail-fast: false
matrix:
Expand All @@ -25,9 +32,9 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with :
ref : ${{ github.ref || github.head_ref || github.ref_name }}
- name: Use Node.js ${{ matrix.node-version }}
with:
ref: ${{ github.ref || github.head_ref || github.ref_name }}
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ env:
CI: true
permissions: {}
jobs:
build-rust-binding:
name: Build Rust Binding
uses: ./.github/workflows/build-rust-binding.yml
with:
name: "taro"
publish:
permissions:
contents: write # to create tags and refs
Expand All @@ -23,6 +28,7 @@ jobs:

name: Publish
runs-on: ubuntu-latest
needs: [build-rust-binding]
steps:
# Setup
- name: Checkout
Expand Down Expand Up @@ -119,6 +125,12 @@ jobs:
run_install: |
- recursive: true
args: [--frozen-lockfile]
- name: Download all artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: Move artifacts
run: pnpm artifacts
- name: build
run: pnpm build

Expand Down
41 changes: 0 additions & 41 deletions .github/workflows/rust-binding.yml

This file was deleted.

5 changes: 5 additions & 0 deletions crates/native_binding/__test__/index.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import test from 'ava'

test('native_binding', async t => {
t.pass()
})
7 changes: 5 additions & 2 deletions crates/native_binding/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"prepublishOnly": "napi prepublish -t npm",
"format": "run-p format:source format:rs",
"format:rs": "cargo fmt",
"format:source": "prettier . -w"
"format:source": "prettier . -w",
"test": "ava",
"universal": "napi universal"
},
"files": [
"binding.js",
Expand All @@ -30,7 +32,8 @@
"author": "luckyadam",
"license": "MIT",
"devDependencies": {
"@napi-rs/cli": "3.0.0-alpha.5"
"@napi-rs/cli": "3.0.0-alpha.5",
"ava": "5.3.1"
},
"bugs": {
"url": "https://github.com/NervJS/taro/issues"
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@
"prepare": "husky install",
"build": "pnpm -r --aggregate-output --filter=./packages/* build",
"build:binding:debug": "pnpm --filter @tarojs/binding run build:debug",
"build:binding:release": "pnpm --filter @tarojs/binding run build:release",
"build:binding:release": "pnpm --filter @tarojs/binding run build",
"format::rs": "cargo fmt --all",
"clear-all": "rimraf **/node_modules",
"lint": "eslint packages/ --ext .js --ext .ts --ext .tsx",
"lint:style": "stylelint ./packages/**/*.{css,scss}",
"test": "pnpm --if-present -r --aggregate-output --filter=./packages/* test:ci",
"test:binding": "pnpm --filter @tarojs/binding run test",
"updateSnapshot": "pnpm --if-present -r --aggregate-output --filter=./packages/* updateSnapshot",
"version": "run-s version:*",
"version:release": "pnpm --parallel -r --aggregate-output --filter=./packages/* exec npm version ${npm_package_version}",
"version:git": "git add . && git commit -m \"chore(release): publish ${npm_package_version}\"",
"version:changelog": "conventional-changelog -p angular"
"version:changelog": "conventional-changelog -p angular",
"universal": "pnpm --filter @tarojs/binding run universal",
"artifacts": "pnpm --filter @tarojs/binding run artifacts"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
Expand Down
Loading

0 comments on commit 5f2ba64

Please sign in to comment.