Skip to content

fix(ci): 升级 npm 版本以修复 Alpine 构建失败 #54

fix(ci): 升级 npm 版本以修复 Alpine 构建失败

fix(ci): 升级 npm 版本以修复 Alpine 构建失败 #54

Workflow file for this run

name: Build and Release
on:
push:
branches:
- master
tags:
- 'v*'
pull_request:
workflow_dispatch:
inputs:
publish_npm:
description: 'Publish to npm'
required: false
type: boolean
default: false
jobs:
linux-gnu-x64:
runs-on: ubuntu-24.04
container:
image: alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3:latest
env:
ZIG_TARGET: x86_64-linux-gnu
steps:
- name: Install prerequisites
run: yum install -y git curl wget xz tar unzip rsync which python3 python3-pip python3-setuptools autoconf automake libtool pkgconfig gcc gcc-c++ make ninja-build cmake file vim procps-ng iputils
- name: Checkout
uses: actions/checkout@v4
- name: Install Node.js
run: |
curl -fsSL https://rpm.nodesource.com/setup_18.x | bash -
yum install -y nodejs
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.2
- name: Configure Zig environment
run: |
ZIG_BIN=$(command -v zig)
if [ -z "$ZIG_BIN" ]; then
echo "zig binary not found" >&2
exit 1
fi
echo "ZIG_BIN=$ZIG_BIN" >> "$GITHUB_ENV"
echo "CC=$ZIG_BIN cc -target $ZIG_TARGET -fno-sanitize=undefined" >> "$GITHUB_ENV"
echo "CXX=$ZIG_BIN c++ -target $ZIG_TARGET -fno-sanitize=undefined" >> "$GITHUB_ENV"
echo "CFLAGS=-fPIC -fno-sanitize=undefined" >> "$GITHUB_ENV"
echo "CXXFLAGS=-fPIC -fno-sanitize=undefined" >> "$GITHUB_ENV"
echo "LDFLAGS=-static-libstdc++ -static-libgcc -fno-sanitize=undefined" >> "$GITHUB_ENV"
- name: Install npm dependencies
run: npm install --no-audit --prefer-offline
- name: Build RocketMQ native deps
run: ./deps/rocketmq/build.sh
- name: Build addon
run: npx cmake-js compile --CDCMAKE_BUILD_TYPE=Release
- name: Package artifact
run: |
mkdir -p Release
strip --strip-all build/rocketmq.node
cp build/rocketmq.node Release/linux-x86_64-gnu-rocketmq.node
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: linux-x86_64-gnu
path: Release/linux-x86_64-gnu-rocketmq.node
linux-gnu-arm64:
runs-on: ubuntu-24.04-arm
container:
image: alibaba-cloud-linux-3-registry.cn-hangzhou.cr.aliyuncs.com/alinux3/alinux3:latest
env:
ZIG_TARGET: aarch64-linux-gnu
steps:
- name: Install prerequisites
run: yum install -y git curl wget xz tar unzip rsync which python3 python3-pip python3-setuptools autoconf automake libtool pkgconfig gcc gcc-c++ make ninja-build cmake file vim procps-ng iputils
- name: Checkout
uses: actions/checkout@v4
- name: Install Node.js
run: |
curl -fsSL https://rpm.nodesource.com/setup_18.x | bash -
yum install -y nodejs
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.2
- name: Configure Zig environment
run: |
ZIG_BIN=$(command -v zig)
if [ -z "$ZIG_BIN" ]; then
echo "zig binary not found" >&2
exit 1
fi
echo "ZIG_BIN=$ZIG_BIN" >> "$GITHUB_ENV"
echo "CC=$ZIG_BIN cc -target $ZIG_TARGET -fno-sanitize=undefined" >> "$GITHUB_ENV"
echo "CXX=$ZIG_BIN c++ -target $ZIG_TARGET -fno-sanitize=undefined" >> "$GITHUB_ENV"
echo "CFLAGS=-fPIC -fno-sanitize=undefined" >> "$GITHUB_ENV"
echo "CXXFLAGS=-fPIC -fno-sanitize=undefined" >> "$GITHUB_ENV"
echo "LDFLAGS=-static-libstdc++ -static-libgcc -fno-sanitize=undefined" >> "$GITHUB_ENV"
- name: Install npm dependencies
run: npm install --no-audit --prefer-offline
- name: Build RocketMQ native deps
run: ./deps/rocketmq/build.sh
- name: Build addon
run: npx cmake-js compile --CDCMAKE_BUILD_TYPE=Release
- name: Package artifact
run: |
mkdir -p Release
strip --strip-all build/rocketmq.node
cp build/rocketmq.node Release/linux-aarch64-gnu-rocketmq.node
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: linux-aarch64-gnu
path: Release/linux-aarch64-gnu-rocketmq.node
linux-musl-x64:
runs-on: ubuntu-24.04
container:
image: alpine:latest
env:
ZIG_TARGET: x86_64-linux-musl
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install system dependencies
run: apk add --no-cache nodejs npm bash build-base cmake ninja python3 curl unzip git autoconf automake libtool pkgconfig
- name: Upgrade npm
run: npm install -g npm@latest
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.2
- name: Configure Zig environment
run: |
ZIG_BIN=$(command -v zig)
if [ -z "$ZIG_BIN" ]; then
echo "zig binary not found" >&2
exit 1
fi
echo "ZIG_BIN=$ZIG_BIN" >> "$GITHUB_ENV"
echo "CC=$ZIG_BIN cc -target $ZIG_TARGET -fno-sanitize=undefined" >> "$GITHUB_ENV"
echo "CXX=$ZIG_BIN c++ -target $ZIG_TARGET -fno-sanitize=undefined" >> "$GITHUB_ENV"
echo "CFLAGS=-fPIC -fno-sanitize=undefined" >> "$GITHUB_ENV"
echo "CXXFLAGS=-fPIC -fno-sanitize=undefined" >> "$GITHUB_ENV"
echo "LDFLAGS=-static-libstdc++ -static-libgcc -fno-sanitize=undefined" >> "$GITHUB_ENV"
- name: Install npm dependencies
run: npm install --no-audit --prefer-offline
- name: Build RocketMQ native deps
run: ./deps/rocketmq/build.sh
- name: Build addon
run: npx cmake-js compile --CDCMAKE_BUILD_TYPE=Release
- name: Package artifact
run: |
mkdir -p Release
strip --strip-all build/rocketmq.node
cp build/rocketmq.node Release/linux-x86_64-musl-rocketmq.node
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: linux-x86_64-musl
path: Release/linux-x86_64-musl-rocketmq.node
linux-musl-arm64:
runs-on: ubuntu-24.04-arm
env:
ZIG_TARGET: aarch64-linux-musl
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install system dependencies
run: sudo apt-get update && sudo apt-get install -y build-essential cmake ninja-build python3 curl unzip git autoconf automake libtool pkg-config
- name: Setup Zig
uses: mlugg/setup-zig@v2
with:
version: 0.15.2
- name: Configure Zig environment
run: |
ZIG_BIN=$(command -v zig)
if [ -z "$ZIG_BIN" ]; then
echo "zig binary not found" >&2
exit 1
fi
echo "ZIG_BIN=$ZIG_BIN" >> "$GITHUB_ENV"
echo "CC=$ZIG_BIN cc -target $ZIG_TARGET -fno-sanitize=undefined" >> "$GITHUB_ENV"
echo "CXX=$ZIG_BIN c++ -target $ZIG_TARGET -fno-sanitize=undefined" >> "$GITHUB_ENV"
echo "CFLAGS=-fPIC -fno-sanitize=undefined" >> "$GITHUB_ENV"
echo "CXXFLAGS=-fPIC -fno-sanitize=undefined" >> "$GITHUB_ENV"
echo "LDFLAGS=-static-libstdc++ -static-libgcc -fno-sanitize=undefined" >> "$GITHUB_ENV"
- name: Install npm dependencies
run: npm install --no-audit --prefer-offline
- name: Build RocketMQ native deps
run: ./deps/rocketmq/build.sh
- name: Build addon
run: npx cmake-js compile --CDCMAKE_BUILD_TYPE=Release
- name: Package artifact
run: |
mkdir -p Release
strip --strip-all build/rocketmq.node
cp build/rocketmq.node Release/linux-aarch64-musl-rocketmq.node
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: linux-aarch64-musl
path: Release/linux-aarch64-musl-rocketmq.node
macos-universal:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: Install build tools
run: brew install cmake ninja xz autoconf automake libtool pkg-config
- name: Install npm dependencies
run: npm install --no-audit --prefer-offline
- name: Build RocketMQ native deps
run: ./deps/rocketmq/build.sh
- name: Build addon
run: |
npx cmake-js compile --CDCMAKE_BUILD_TYPE=Release \
--CDCMAKE_OSX_ARCHITECTURES="arm64;x86_64" \
--CDCMAKE_OSX_DEPLOYMENT_TARGET=11 \
--CDCMAKE_SKIP_DEPENDENCY_TRACKING=ON
- name: Package artifact
run: |
mkdir -p Release
strip -S -x build/rocketmq.node
cp build/rocketmq.node Release/darwin-universal-rocketmq.node
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: darwin-universal
path: Release/darwin-universal-rocketmq.node
release:
needs: [linux-gnu-x64, linux-gnu-arm64, linux-musl-x64, linux-musl-arm64, macos-universal]
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Prepare Release directory
run: |
mkdir -p Release
find artifacts -name "*.node" -exec cp {} Release/ \;
ls -lh Release/
- name: Create Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
draft: false
prerelease: false
files: Release/*.node
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-npm:
needs: release
runs-on: ubuntu-latest
if: (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) || (github.event_name == 'workflow_dispatch' && inputs.publish_npm)
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
registry-url: 'https://registry.npmjs.org'
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Prepare Release directory
run: |
mkdir -p Release
find artifacts -name "*.node" -exec cp {} Release/ \;
ls -lh Release/
- name: Verify version consistency
if: startsWith(github.ref, 'refs/tags/v')
run: |
PKG_VERSION=$(node -p "require('./package.json').version")
TAG_VERSION=${GITHUB_REF#refs/tags/v}
if [ "$PKG_VERSION" != "$TAG_VERSION" ]; then
echo "❌ Version mismatch: package.json=$PKG_VERSION, tag=$TAG_VERSION"
exit 1
fi
echo "✅ Version consistent: $PKG_VERSION"
- name: Install dependencies (skip native build)
run: npm ci --ignore-scripts
- name: Build TypeScript
run: npm run build:ts
- name: Validate build output
run: |
echo "Validating TypeScript build..."
if [ ! -f "dist/index.js" ]; then
echo "❌ dist/index.js not found"
exit 1
fi
if [ ! -f "dist/index.d.ts" ]; then
echo "❌ dist/index.d.ts not found"
exit 1
fi
echo "✅ TypeScript build verified"
echo "Validating native addons..."
for f in linux-x86_64-gnu linux-aarch64-gnu linux-x86_64-musl linux-aarch64-musl darwin-universal; do
if [ ! -f "Release/${f}-rocketmq.node" ]; then
echo "❌ Missing: ${f}-rocketmq.node"
exit 1
fi
done
echo "✅ All native addons present"
- name: Verify package contents
run: |
echo "=== Package contents ==="
npm pack --dry-run
echo ""
echo "=== Release binaries ==="
ls -lh Release/
- name: Publish to npm
run: npm publish --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}