name: Node.js on: push: branches: [master] pull_request: branches: [master] concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: build-and-test: permissions: contents: read runs-on: ${{ matrix.os }} strategy: matrix: # Supported Node.js versions on latest hosted runners os: [ubuntu-latest, macos-latest] node-version: [20, 22, 24, 25] # LTS coverage on macOS 14 (ARM64) include: - os: macos-14 node-version: 24 - os: macos-15-intel node-version: 24 - os: windows-2022 node-version: 24 steps: - uses: actions/checkout@v5 with: fetch-depth: 0 - name: Compute version id: version shell: bash run: | VERSION=$(bash scripts/compute-version.sh) echo "VERSION=$VERSION" >> "$GITHUB_ENV" echo "version=$VERSION" >> "$GITHUB_OUTPUT" echo "Computed version: $VERSION" - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v5 with: node-version: ${{ matrix.node-version }} - run: npm ci - run: npm test - name: Build Node.js prebuild if: ${{ matrix.node-version == 24 }} run: npm run prebuild - name: Verify Node.js prebuild layout if: ${{ matrix.node-version == 24 }} run: | node -e "const fs=require('fs'); const path=require('path'); const dirs=fs.readdirSync('prebuilds',{withFileTypes:true}).filter((entry)=>entry.isDirectory()).map((entry)=>entry.name); if(!dirs.includes('assets')) throw new Error('missing prebuilds/assets'); const platformDirs=dirs.filter((name)=>name!=='assets'); if(platformDirs.length!==1) throw new Error('expected one platform prebuild directory, found '+platformDirs.join(',')); const addon=path.join('prebuilds', platformDirs[0], 'opencc.node'); if(!fs.existsSync(addon)) throw new Error('missing '+addon); console.log('Verified '+addon+' with shared assets');" - name: Test Node.js prebuild if: ${{ matrix.node-version == 24 }} env: PREBUILDS_ONLY: 1 run: npm test - name: upload artifacts if: ${{ always() }} uses: actions/upload-artifact@v7 with: name: opencc-${{ env.VERSION }}-nodejs-${{ matrix.os }}-node-${{ matrix.node-version }} path: | node/build/** prebuilds/** **/npm-debug.log # Install the packed npm tarball without prebuilt binaries, so the # node-gyp source build path is exercised exactly as it runs on platforms # without a scoped binary package (issue #1409). pack-source-install: name: Source build from npm tarball (${{ matrix.os }}) permissions: contents: read runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, macos-15-intel] steps: - uses: actions/checkout@v5 with: fetch-depth: 0 - name: Use Node.js uses: actions/setup-node@v5 with: node-version: 24 - run: npm ci - name: Build prebuild assets run: npm run prebuild - name: Pack npm tarball shell: bash run: | mkdir -p dist/npm-artifacts npm pack --pack-destination dist/npm-artifacts - name: Install tarball from source and smoke test shell: bash run: | tarball="$(ls "$PWD"/dist/npm-artifacts/opencc-*.tgz)" install_dir="$(mktemp -d)" cd "$install_dir" npm init -y npm install --omit=optional --foreground-scripts "$tarball" test -f node_modules/opencc/build/Release/opencc.node node -e ' const assert = require("assert"); const OpenCC = require("opencc"); const converter = new OpenCC("s2t.json"); const converted = converter.convertSync("汉字"); assert.strictEqual(converted, "漢字"); console.log("Source-built opencc converts 汉字 ->", converted); '