current commit
261107.3 · build(deps): bump actions/setup-node from 7.0.0 to 7.1.0 (#6129)
name: Node.js compiled --shared-builtin-undici/undici-path CI

on:
  workflow_call:
    inputs:
      node-version:
        required: true
        type: string
      node-download-server-path:
        required: false
        type: string
        default: '/release'

permissions:
  contents: read

jobs:
  test-shared-builtin:
    name: Test with Node.js ${{ inputs.node-version }} compiled --shared-builtin-undici/undici-path
    runs-on: ubuntu-latest
    timeout-minutes: 120
    steps:
      # Checkout into a subdirectory otherwise Node.js tests will break due to finding Undici's package.json in a parent directory.
      - name: Checkout Repository
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          path: ./undici
          persist-credentials: false

      # Setup node, install deps, and build undici prior to building node with `--shared-builtin-undici/undici-path` and testing
      - name: Setup Node.js lts/*
        uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
        with:
          node-version: 'lts/*'

      - name: Install dependencies
        working-directory: ./undici
        run: npm ci

      - name: Install wasi-libc
        run: sudo apt-get install -y wasi-libc binaryen

      - name: Rebuild llhttp WASM from vendored sources
        working-directory: ./undici
        run: |
          export EXTERNAL_PATH=${{ github.workspace }}/undici
          export WASM_CC=clang
          export WASM_CFLAGS='--target=wasm32-wasi --sysroot=/usr'
          export WASM_LDFLAGS='-nodefaultlibs'
          export WASM_LDLIBS='-lc'
          node build/llhttp.js

      - name: Rebuild Milo WASM from vendored sources
        working-directory: ./undici
        run: |
          # Removing bundled artifacts ensures this job cannot reuse prebuilt Milo.
          rm lib/milo
          node build/milo.js

      - name: Determine latest release for Node.js ${{ inputs.node-version }}
        id: release
        uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
        with:
          result-encoding: string
          script: |
            const req = await fetch('https://nodejs.org/download${{ inputs.node-download-server-path }}/index.json')
            const releases = await req.json()

            const latest = releases.find((r) => r.version.startsWith('v${{ inputs.node-version }}.'))
            return latest?.version || ''

      - name: Skip until Node.js ${{ inputs.node-version }} is released
        if: steps.release.outputs.result == ''
        run: echo 'No matching Node.js ${{ inputs.node-version }} release is available yet; skipping shared builtin embedding checks.'

      - name: Download and extract source for Node.js ${{ steps.release.outputs.result }}
        if: steps.release.outputs.result != ''
        run: curl https://nodejs.org/download${{ inputs.node-download-server-path }}/${{ steps.release.outputs.result }}/node-${{ steps.release.outputs.result }}.tar.xz | tar xfJ -

      - name: Install ninja
        if: steps.release.outputs.result != ''
        run: sudo apt-get install ninja-build

      - name: ccache
        if: steps.release.outputs.result != ''
        uses: hendrikmuhs/ccache-action@f09c25b45002a07be2955cbe52e8cee55643f89d #v1.2.24
        with:
          key: node(external_undici)${{ inputs.node-version }}

      - name: Build node ${{ steps.release.outputs.result }} with --shared-builtin-undici/undici-path
        if: steps.release.outputs.result != ''
        working-directory: ./node-${{ steps.release.outputs.result }}
        run: |
          export CC="ccache gcc"
          export CXX="ccache g++"
          rm -rf deps/undici
          ./configure --shared-builtin-undici/undici-path ${{ github.workspace }}/undici/loader.js --ninja --prefix=./final
          make
          if grep -q '^build-ffi-tests:' Makefile; then
            make build-ffi-tests
          fi
          make install
          if make -qp | grep -q '^build-ffi-tests:'; then
            make build-ffi-tests
          fi
          echo "$(pwd)/final/bin" >> $GITHUB_PATH

      - name: Print version information
        if: steps.release.outputs.result != ''
        run: |
          echo OS: $(node -p "os.version()")
          echo Node.js: $(node --version)
          echo "Node.js built-in dependencies: $(node -p "'\r\n' + (Object.entries(process.versions).map(([k, v], i, arr) => (i !== arr.length - 1 ? '├──' : '└──') + k + '@' + v)).join('\r\n')")"
          echo npm: $(npm --version)
          echo git: $(git --version)
          echo external config: $(node -e "console.log(process.config)" | grep NODE_SHARED_BUILTIN_UNDICI_UNDICI_PATH)
          echo Node.js built-in undici version: $(node -p "process.versions.undici") # undefined for external Undici

      - name: Run tests
        if: steps.release.outputs.result != ''
        working-directory: ./node-${{ steps.release.outputs.result }}
        run: tools/test.py -p dots --flaky-tests=dontcare