name: node-release permissions: id-token: write # Required for trusted publishing contents: write on: push: branches: [main] workflow_dispatch: jobs: release-check: name: Check if version is published runs-on: ubuntu-latest defaults: run: shell: bash steps: - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v4 with: persist-credentials: false - name: Use Node.js from nvmrc uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v4 with: node-version-file: 'platform/node/.nvmrc' - name: Check if version is published id: check working-directory: platform/node run: | packageName="$( node -e "console.log(require('./package.json').name)" )" currentVersion="$( node -e "console.log(require('./package.json').version)" )" isPublished="$( npm view "$packageName" versions --json | jq -c --arg cv "$currentVersion" 'any(. == $cv)' )" echo "published=$isPublished" >> "$GITHUB_OUTPUT" echo "currentVersion: $currentVersion" echo "isPublished: $isPublished" outputs: published: ${{ steps.check.outputs.published }} publish_binaries: needs: release-check if: ${{ needs.release-check.outputs.published == 'false' }} runs-on: ${{ matrix.runs-on }} permissions: contents: write strategy: fail-fast: false matrix: include: - runs-on: ubuntu-24.04 arch: x86_64 - runs-on: ubuntu-24.04-arm arch: arm64 - runs-on: macos-15-intel arch: x86_64 - runs-on: macos-15 arch: arm64 - runs-on: windows-2022 arch: x86_64 - runs-on: windows-11-arm arch: arm64 continue-on-error: true env: BUILDTYPE: "Release" defaults: run: working-directory: ./ shell: bash steps: - if: runner.os == 'Windows' run: git config --global core.longpaths true - name: Checkout uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v4 with: submodules: recursive persist-credentials: false - name: Get OS Architecture if: runner.os == 'MacOS' || runner.os == 'Linux' run: uname -m - name: Install dependencies (MacOS) if: runner.os == 'MacOS' env: HOMEBREW_NO_AUTO_UPDATE: 1 HOMEBREW_NO_INSTALL_CLEANUP: 1 run: | brew list ccache || brew install ccache brew list ninja || brew install ninja brew list pkg-config || brew install pkg-config brew list glfw || brew install glfw brew list libuv || brew install libuv - name: Install dependencies (Linux) if: runner.os == 'Linux' env: DEBIAN_FRONTEND: noninteractive run: | sudo apt-get update sudo apt-get install -y \ ccache \ ninja-build \ pkg-config \ xvfb \ libcurl4-openssl-dev \ libglfw3-dev \ libuv1-dev \ libjpeg-dev \ libpng-dev \ libwebp-dev /usr/sbin/update-ccache-symlinks - name: Use Node.js from nvmrc uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v4 with: node-version-file: 'platform/node/.nvmrc' - name: npm ci working-directory: platform/node run: npm ci --ignore-scripts - name: Set up msvc dev cmd (Windows x64) if: runner.os == 'Windows' && matrix.arch == 'x86_64' uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1 - name: Set up msvc dev cmd (Windows ARM64) if: runner.os == 'Windows' && matrix.arch == 'arm64' uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1 with: arch: amd64_arm64 - name: Test VSCMD_ARG_TGT_ARCH Environment if: runner.os == 'Windows' run: | echo "VSCMD_ARG_TGT_ARCH=%VSCMD_ARG_TGT_ARCH%" shell: cmd - name: cmake version run: | cmake --version - name: Set up ccache (MacOS/Linux) if: runner.os == 'MacOS' || runner.os == 'Linux' uses: hendrikmuhs/ccache-action@5ebbd400eff9e74630f759d94ddd7b6c26299639 # v1.2.20 with: key: ${{ matrix.runs-on }}-${{ matrix.arch }}-${{ env.BUILDTYPE }}-${{ github.job }}-${{ github.sha }} restore-keys: | ${{ matrix.runs-on }}-${{ matrix.arch }}-${{ env.BUILDTYPE }}-${{ github.job }}-${{ github.ref }}-${{ github.sha }} ${{ matrix.runs-on }}-${{ matrix.arch }}-${{ env.BUILDTYPE }}-${{ github.job }}-${{ github.ref }} ${{ matrix.runs-on }}-${{ matrix.arch }}-${{ env.BUILDTYPE }}-${{ github.job }} ${{ matrix.runs-on }}-${{ matrix.arch }}-${{ env.BUILDTYPE }} - name: Set up ccache (Windows) if: runner.os == 'Windows' uses: hendrikmuhs/ccache-action@5ebbd400eff9e74630f759d94ddd7b6c26299639 # v1.2.20 with: variant: "sccache" key: ${{ matrix.runs-on }}-${{ matrix.arch }}-${{ env.BUILDTYPE }}-${{ github.job }}-${{ github.sha }} restore-keys: | ${{ matrix.runs-on }}-${{ matrix.arch }}-${{ env.BUILDTYPE }}-${{ github.job }}-${{ github.ref }}-${{ github.sha }} ${{ matrix.runs-on }}-${{ matrix.arch }}-${{ env.BUILDTYPE }}-${{ github.job }}-${{ github.ref }} ${{ matrix.runs-on }}-${{ matrix.arch }}-${{ env.BUILDTYPE }}-${{ github.job }} ${{ matrix.runs-on }}-${{ matrix.arch }}-${{ env.BUILDTYPE }} - name: Cache cmake-node-module deps uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 with: # downloaded with platform/node/cmake/module.cmake path: build/headers key: ${{ runner.os }}-${{ runner.arch }}-cmake-node-module-deps - name: Configure maplibre-native (MacOS) if: runner.os == 'MacOS' run: | cmake --preset macos-metal-node -DCMAKE_BUILD_TYPE=${{ env.BUILDTYPE }} - name: Configure maplibre-native (Linux) if: runner.os == 'Linux' run: | cmake --preset linux-opengl-node -DCMAKE_BUILD_TYPE=${{ env.BUILDTYPE }} - name: Get vcpkg commit id if: runner.os == 'Windows' shell: pwsh run: | $vcpkg_commit_id = ($(git submodule status .\platform\windows\vendor\vcpkg).Trim() -split ' ')[0] Add-Content -Path $env:GITHUB_ENV -Value "VCPKG_COMMIT_ID=${vcpkg_commit_id}" - name: Restore vcpkg binary cache if: runner.os == 'Windows' uses: actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 with: path: ${{ github.workspace }}\platform\windows\vendor\vcpkg\archives key: vcpkg-${{ env.VCPKG_COMMIT_ID }} - name: Configure maplibre-native (Windows x64) if: runner.os == 'Windows' && matrix.arch == 'x86_64' shell: pwsh env: VCPKG_INSTALL_OPTIONS: "--debug" VCPKG_BINARY_SOURCES: "clear;files,${{ github.workspace }}\\platform\\windows\\vendor\\vcpkg\\archives,readwrite" run: | cmake --preset windows-opengl-node -DCMAKE_BUILD_TYPE=${{ env.BUILDTYPE }} - name: Configure maplibre-native (Windows arm64) if: runner.os == 'Windows' && matrix.arch == 'arm64' shell: pwsh env: VCPKG_INSTALL_OPTIONS: "--debug" VCPKG_BINARY_SOURCES: "clear;files,${{ github.workspace }}\\platform\\windows\\vendor\\vcpkg\\archives,readwrite" run: | cmake --preset windows-arm64-opengl-node -DCMAKE_BUILD_TYPE=${{ env.BUILDTYPE }} - name: Build maplibre-native (MacOS/Linux) if: runner.os == 'MacOS' || runner.os == 'Linux' run: | cmake --build build -j "$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null)" - name: Build maplibre-native (Windows) if: runner.os == 'Windows' run: | cmake --build build - name: Publish X64 Release to Github if: matrix.arch == 'x86_64' working-directory: platform/node env: PUBLISH: true BUILDTYPE: RelWithDebInfo NODE_PRE_GYP_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | ./scripts/publish.sh - name: Publish ARM Release to Github if: matrix.arch == 'arm64' working-directory: platform/node env: PUBLISH: true BUILDTYPE: RelWithDebInfo NODE_PRE_GYP_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | ./scripts/publish.sh --target_arch=arm64 publish_npm: runs-on: ubuntu-latest needs: publish_binaries defaults: run: shell: bash steps: - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v4 with: persist-credentials: false - name: Use Node.js from nvmrc uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v4 with: node-version-file: 'platform/node/.nvmrc' registry-url: 'https://registry.npmjs.org' - name: Get version id: package-version uses: martinbeentjes/npm-get-version-action@3cf273023a0dda27efcd3164bdfb51908dd46a5b # v1.3.1 with: path: platform/node - name: npm ci working-directory: platform/node run: npm ci --ignore-scripts - name: Prepare release id: prepare_release working-directory: platform/node run: | RELEASE_TYPE="$(node -e "console.log(require('semver').prerelease('${{ steps.package-version.outputs.current-version }}') ? 'prerelease' : 'regular')")" if [[ $RELEASE_TYPE == 'regular' ]]; then echo "prerelease=false" >> "$GITHUB_OUTPUT" else echo "prerelease=true" >> "$GITHUB_OUTPUT" fi - name: Extract changelog for version working-directory: platform/node run: | awk '/^##/ { p = 0 }; p == 1 { print }; $0 == "## ${{ steps.package-version.outputs.current-version }}" { p = 1 };' CHANGELOG.md > changelog_for_version.md cat changelog_for_version.md - name: Update Release Notes id: update_release_notes uses: ncipollo/release-action@b7eabc95ff50cbeeedec83973935c8f306dfcd0b # v1.20.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag: node-v${{ steps.package-version.outputs.current-version }} name: node-v${{ steps.package-version.outputs.current-version }} bodyFile: platform/node/changelog_for_version.md allowUpdates: true draft: true prerelease: ${{ steps.prepare_release.outputs.prerelease }} - name: Publish to NPM (release) if: ${{ steps.prepare_release.outputs.prerelease == 'false' }} working-directory: platform/node run: | npm publish --access public - name: Publish to NPM (prerelease) if: ${{ steps.prepare_release.outputs.prerelease == 'true' }} working-directory: platform/node run: | npm publish --tag next --access public