Skip to content

Commit

Permalink
chore(ci): Fix publish-npm-package action (#9461)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #9457
  • Loading branch information
kdy1 authored Aug 20, 2024
1 parent 171d1e8 commit d43f1b1
Show file tree
Hide file tree
Showing 5 changed files with 387 additions and 316 deletions.
96 changes: 64 additions & 32 deletions .github/workflows/publish-npm-package.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Build npm package"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.package}}
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.package }}
cancel-in-progress: true

env:
Expand Down Expand Up @@ -67,27 +67,34 @@ jobs:
- host: macos-latest
target: x86_64-apple-darwin
build: |
cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --features plugin --target x86_64-apple-darwin
cp ../../bindings/target/x86_64-apple-darwin/release/swc .
chmod +x ./swc
if [[ ${{ inputs.package }} == "core" ]]; then
cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --features plugin --target x86_64-apple-darwin
cp ../../bindings/target/x86_64-apple-darwin/release/swc .
chmod +x ./swc
fi
yarn build --target x86_64-apple-darwin
strip -x *.node
- host: windows-latest
build: |
export CARGO_PROFILE_RELEASE_LTO=false
yarn build --target x86_64-pc-windows-msvc
cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --features plugin --target x86_64-pc-windows-msvc
cp ../../bindings/target/x86_64-pc-windows-msvc/release/swc .
if [[ ${{ inputs.package }} == "core" ]]; then
cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --features plugin --target x86_64-pc-windows-msvc
cp ../../bindings/target/x86_64-pc-windows-msvc/release/swc .
fi
target: x86_64-pc-windows-msvc
- host: windows-latest
# use npm to run test, because of corepack link the yarn with x64 Node.js
build: |
export DISABLE_PLUGIN_E2E_TESTS=true
export CARGO_PROFILE_RELEASE_LTO=false
cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --target i686-pc-windows-msvc
cp ../../bindings/target/i686-pc-windows-msvc/release/swc .
yarn build --target i686-pc-windows-msvc --no-default-features --features swc_v1
npm run test
if [[ ${{ inputs.package }} == "core" ]]; then
cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --target i686-pc-windows-msvc
cp ../../bindings/target/i686-pc-windows-msvc/release/swc .
yarn build --target i686-pc-windows-msvc --no-default-features --features swc_v1
else
yarn build --target i686-pc-windows-msvc
fi
target: i686-pc-windows-msvc
- host: ubuntu-latest
target: x86_64-unknown-linux-gnu
Expand All @@ -97,18 +104,26 @@ jobs:
unset CC_x86_64_unknown_linux_gnu && unset CC && RUSTFLAGS='-C target-feature=+sse2' cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --features plugin --target x86_64-unknown-linux-gnu &&
rm -rf ../../bindings/target/target/x86_64-unknown-linux-gnu/release/.cargo-lock &&
cp ../../bindings/target/x86_64-unknown-linux-gnu/release/swc . && chmod +x ./swc &&
yarn build --target x86_64-unknown-linux-gnu
if [[ ${{ inputs.package }} == "core" ]]; then
yarn build --target x86_64-unknown-linux-gnu --no-default-features --features swc_v1
else
yarn build --target x86_64-unknown-linux-gnu
fi
- host: ubuntu-latest
target: x86_64-unknown-linux-musl
# musl build is slow, let's disable the LTO
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
build: >-
set -e &&
export CARGO_PROFILE_RELEASE_LTO=false &&
RUSTFLAGS='-C target-feature=+sse2' cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --features plugin --target x86_64-unknown-linux-musl &&
rm -rf target/release/.cargo-lock &&
cp ../../bindings/target/x86_64-unknown-linux-musl/release/swc . && chmod +x ./swc &&
RUSTFLAGS='-C target-feature=+sse2 -C target-feature=-crt-static' yarn build --target x86_64-unknown-linux-musl
if [[ ${{ inputs.package }} == "core" ]]; then
RUSTFLAGS='-C target-feature=+sse2' cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --features plugin --target x86_64-unknown-linux-musl &&
rm -rf target/release/.cargo-lock &&
cp ../../bindings/target/x86_64-unknown-linux-musl/release/swc . && chmod +x ./swc &&
RUSTFLAGS='-C target-feature=+sse2 -C target-feature=-crt-static' yarn build --target x86_64-unknown-linux-musl
else
RUSTFLAGS='-C target-feature=+sse2 -C target-feature=-crt-static' yarn build --target x86_64-unknown-linux-musl
fi
- host: macos-latest
target: aarch64-apple-darwin
build: |
Expand All @@ -117,9 +132,11 @@ jobs:
export CXX=$(xcrun -f clang++);
SYSROOT=$(xcrun --sdk macosx --show-sdk-path);
export CFLAGS="-isysroot $SYSROOT -isystem $SYSROOT";
cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --features plugin --target aarch64-apple-darwin
cp ../../bindings/target/aarch64-apple-darwin/release/swc .
chmod +x ./swc
if [[ ${{ inputs.package }} == "core" ]]; then
cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --features plugin --target aarch64-apple-darwin
cp ../../bindings/target/aarch64-apple-darwin/release/swc .
chmod +x ./swc
fi
yarn build --target aarch64-apple-darwin
- host: ubuntu-latest
target: aarch64-unknown-linux-gnu
Expand All @@ -128,17 +145,26 @@ jobs:
set -e &&
export JEMALLOC_SYS_WITH_LG_PAGE=16 &&
rustup target add aarch64-unknown-linux-gnu &&
RUSTFLAGS='' cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --features plugin --target aarch64-unknown-linux-gnu &&
cp ../../bindings/target/aarch64-unknown-linux-gnu/release/swc . && chmod +x ./swc &&
export CC_aarch64_unknown_linux_gnu=/usr/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-gcc &&
yarn build --target aarch64-unknown-linux-gnu
if [[ ${{ inputs.package }} == "core" ]]; then
RUSTFLAGS='' cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --features plugin --target aarch64-unknown-linux-gnu &&
cp ../../bindings/target/aarch64-unknown-linux-gnu/release/swc . && chmod +x ./swc &&
export CC_aarch64_unknown_linux_gnu=/usr/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-gcc &&
yarn build --target aarch64-unknown-linux-gnu
else
export CC_aarch64_unknown_linux_gnu=/usr/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-gcc &&
yarn build --target aarch64-unknown-linux-gnu
fi
- host: ubuntu-latest
target: armv7-unknown-linux-gnueabihf
build: |
export DISABLE_PLUGIN_E2E_TESTS=true
yarn napi build --bin swc --release --target armv7-unknown-linux-gnueabihf --manifest-path ../../bindings/swc_cli/Cargo.toml -x --target-dir ../release -o .
chmod +x ./swc
yarn build --target armv7-unknown-linux-gnueabihf --no-default-features --features swc_v1 --use-napi-cross
if [[ ${{ inputs.package }} == "core" ]]; then
yarn napi build --bin swc --release --target armv7-unknown-linux-gnueabihf --manifest-path ../../bindings/swc_cli/Cargo.toml -x --target-dir ../release -o .
chmod +x ./swc
yarn build --target armv7-unknown-linux-gnueabihf --no-default-features --features swc_v1 --use-napi-cross
else
yarn build --target armv7-unknown-linux-gnueabihf --use-napi-cross
fi
- host: ubuntu-latest
target: aarch64-unknown-linux-musl
downloadTarget: aarch64-unknown-linux-musl
Expand All @@ -158,9 +184,13 @@ jobs:
export DISABLE_PLUGIN_E2E_TESTS=true
export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=256
export CARGO_PROFILE_RELEASE_LTO=false
cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --target aarch64-pc-windows-msvc
cp ../../bindings/target/aarch64-pc-windows-msvc/release/swc.exe .
yarn build --target aarch64-pc-windows-msvc --no-default-features --features swc_v1
if [[ ${{ inputs.package }} == "core" ]]; then
cargo build --manifest-path ../../bindings/swc_cli/Cargo.toml --release --target aarch64-pc-windows-msvc
cp ../../bindings/target/aarch64-pc-windows-msvc/release/swc.exe .
yarn build --target aarch64-pc-windows-msvc --no-default-features --features swc_v1
else
yarn build --target aarch64-pc-windows-msvc
fi
name: "Build ${{ inputs.package }} - ${{ matrix.settings.target }} - node@20"
runs-on: ${{ matrix.settings.host }}
steps:
Expand Down Expand Up @@ -248,7 +278,8 @@ jobs:
with:
name: bindings-${{ matrix.settings.target }}
path: |
packages/core/swc*
packages/${{ inputs.package }}/swc*
packages/${{ inputs.package }}/*.node
if-no-files-found: error
test-macOS-windows-binding:
name: Test bindings on ${{ matrix.settings.target }} - node@${{ matrix.node }}
Expand Down Expand Up @@ -331,7 +362,7 @@ jobs:
- name: Build TypeScript
run: yarn build:ts
- name: Test bindings
run: docker run --rm -v $(pwd):/swc -w /swc node:${{ matrix.node }}-slim sh -c 'npm install -f -g yarn@1.22.19 && env DISABLE_PLUGIN_E2E_TESTS=true yarn test'
run: docker run --rm -v $(pwd):/swc -w /swc node:${{ matrix.node }}-slim sh -c 'npm install -f -g yarn@1.22.19 && cd ./packages/${{ inputs.package }} && env DISABLE_PLUGIN_E2E_TESTS=true yarn test'
test-linux-x64-musl-binding:
name: Test bindings on x86_64-unknown-linux-musl - node@${{ matrix.node }}
needs:
Expand Down Expand Up @@ -371,7 +402,7 @@ jobs:
- name: Build TypeScript
run: yarn build:ts
- name: Test bindings
run: docker run --rm -v $(pwd):/swc -w /swc node:${{ matrix.node }}-alpine sh -c 'npm install -f -g yarn@1.22.19 && env DISABLE_PLUGIN_E2E_TESTS=true yarn test'
run: docker run --rm -v $(pwd):/swc -w /swc node:${{ matrix.node }}-alpine sh -c 'npm install -f -g yarn@1.22.19 && cd ./packages/${{ inputs.package }} && env DISABLE_PLUGIN_E2E_TESTS=true yarn test'
# test-linux-aarch64-musl-binding:
# name: Test bindings on aarch64-unknown-linux-musl - node@lts
# needs:
Expand Down Expand Up @@ -498,6 +529,7 @@ jobs:
shell: bash

- name: Move binaries
if: inputs.package == 'core'
shell: bash
working-directory: ./packages/${{ inputs.package }}
run: |
Expand All @@ -521,7 +553,7 @@ jobs:
npm config set provenance true
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
echo "npmAlwaysAuth:true\n npmAuthToken: '$NPM_TOKEN'\n" >> ~/.yarnrc
(cd packages/core && yarn workspaces foreach -Rt npm publish --tolerate-republish --tag $NPM_TAG)
(cd packages/${{ inputs.package }} && yarn workspaces foreach -Rt npm publish --tolerate-republish --tag $NPM_TAG)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand Down
63 changes: 19 additions & 44 deletions packages/html/binding.d.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,46 @@
/* tslint:disable */
/* eslint-disable */

/* auto-generated by NAPI-RS */
/* eslint-disable */

export interface Diagnostic {
level: string;
message: string;
span: any;
}
export interface TransformOutput {
code: string;
errors?: Array<Diagnostic>;
}
export interface Attribute {
namespace?: string;
prefix?: string;
name: string;
value?: string;
}
export interface Element {
tagName: string;
namespace: string;
attributes: Array<Attribute>;
isSelfClosing: boolean;
}
export function minify(
code: Buffer,
opts: Buffer,
signal?: AbortSignal | undefined | null
): Promise<TransformOutput>;
export function minifyFragment(
code: Buffer,
opts: Buffer,
signal?: AbortSignal | undefined | null
): Promise<TransformOutput>;
export function minifySync(code: Buffer, opts: Buffer): TransformOutput;
export function minifyFragmentSync(code: Buffer, opts: Buffer): TransformOutput;

export interface Diagnostic {
level: string;
message: string;
span: any;
}
export interface TransformOutput {
code: string;
errors?: Array<Diagnostic>;
}
export interface Attribute {
namespace?: string;
prefix?: string;
name: string;
value?: string;
}

export interface Element {
tagName: string;
namespace: string;
attributes: Array<Attribute>;
isSelfClosing: boolean;
}
export function minify(

export declare function minify(
code: Buffer,
opts: Buffer,
signal?: AbortSignal | undefined | null
): Promise<TransformOutput>;
export function minifyFragment(

export declare function minifyFragment(
code: Buffer,
opts: Buffer,
signal?: AbortSignal | undefined | null
): Promise<TransformOutput>;
export function minifySync(code: Buffer, opts: Buffer): TransformOutput;
export function minifyFragmentSync(code: Buffer, opts: Buffer): TransformOutput;

export declare function minifyFragmentSync(
code: Buffer,
opts: Buffer
): TransformOutput;

export declare function minifySync(code: Buffer, opts: Buffer): TransformOutput;

export interface TransformOutput {
code: string;
errors?: Array<Diagnostic>;
}
Loading

0 comments on commit d43f1b1

Please sign in to comment.