Skip to content

Publish to NPM

Publish to NPM #118

Workflow file for this run

name: Publish to NPM
on:
# Since we still need to manually upload binaries, use manual run
# Ideally this would trigger off `release`
workflow_dispatch:
inputs:
patch:
description: 'Patch Version'
required: true
default: '0'
prerelease:
description: 'Is Prerelease'
type: boolean
default: false
jobs:
version:
outputs:
version: ${{ steps.echo.outputs.version }}
date: ${{ steps.echo.outputs.date }}
release_version: ${{ steps.echo.outputs.release_version }}
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- id: echo
run: |
echo "date=$(cat src/workerd/io/supported-compatibility-date.txt)" >> $GITHUB_OUTPUT;
echo "version=${{ inputs.prerelease == false && '1' || '0'}}.$(cat src/workerd/io/supported-compatibility-date.txt | tr -d '-').${{ inputs.patch }}" >> $GITHUB_OUTPUT;
echo "release_version=1.$(cat src/workerd/io/supported-compatibility-date.txt | tr -d '-').0" >> $GITHUB_OUTPUT;
publish-arch-specific:
# if: github.repository_owner == 'cloudflare'
name: Publish arch-specific packages to npm
needs: version
runs-on: ubuntu-latest
strategy:
matrix:
arch: [darwin-64, darwin-arm64, linux-64, linux-arm64, windows-64]
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Use Node
uses: actions/setup-node@v4
with:
node-version: 18
- name: Modify package.json version
run: node npm/scripts/bump-version.mjs npm/workerd-${{ matrix.arch }}/package.json
env:
WORKERD_VERSION: ${{ needs.version.outputs.version }}
LATEST_COMPATIBILITY_DATE: ${{ needs.version.outputs.date }}
- uses: robinraju/release-downloader@v1.9
with:
tag: v${{ needs.version.outputs.release_version }}
fileName: workerd-${{ matrix.arch }}.gz
tarBall: false
zipBall: false
out-file-path: 'release-downloads'
token: ${{ secrets.GITHUB_TOKEN }}
# release-downloader does not support .gz files (unlike .tar.gz), decompress manually
# Using the -N flag the right file name should be restored
- run: gzip -dN $GITHUB_WORKSPACE/release-downloads/workerd-${{ matrix.arch }}.gz
- run: chmod +x $GITHUB_WORKSPACE/release-downloads/workerd
if: matrix.arch != 'windows-64'
- run: mkdir npm/workerd-${{ matrix.arch }}/bin
- run: cp $GITHUB_WORKSPACE/release-downloads/workerd${{ matrix.arch == 'windows-64' && '.exe' || '' }} npm/workerd-${{ matrix.arch }}/bin/workerd${{ matrix.arch == 'windows-64' && '.exe' || '' }}
- run: echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > npm/workerd-${{ matrix.arch }}/.npmrc
- run: cd npm/workerd-${{ matrix.arch }} && npm publish --access public --tag ${{ inputs.prerelease == true && 'beta' || 'latest'}}
env:
NPM_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
publish-wrapper:
# if: github.repository_owner == 'cloudflare'
name: Publish `workerd` to NPM
needs: [version, publish-arch-specific]
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Use Node
uses: actions/setup-node@v4
with:
node-version: 18
- name: Cache
id: cache
uses: actions/cache@v4
# Use same cache and build configuration as release build, this allows us to keep download
# sizes small and generate types with optimization enabled, should be slightly faster.
with:
path: ~/bazel-disk-cache
key: bazel-disk-cache-release-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE') }}
- name: Setup Linux
run: |
export DEBIAN_FRONTEND=noninteractive
wget https://apt.llvm.org/llvm.sh
sed -i '/apt-get install/d' llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 15
sudo apt-get install -y --no-install-recommends clang-15 lld-15 libunwind-15 libc++abi1-15 libc++1-15 libc++-15-dev
echo "build:linux --action_env=CC=/usr/lib/llvm-15/bin/clang --action_env=CXX=/usr/lib/llvm-15/bin/clang++" >> .bazelrc
echo "build:linux --host_action_env=CC=/usr/lib/llvm-15/bin/clang --host_action_env=CXX=/usr/lib/llvm-15/bin/clang++" >> .bazelrc
- name: Build type generating Worker
run: |
bazel build --disk_cache=~/bazel-disk-cache --strip=always --remote_cache=https://bazel:${{ secrets.BAZEL_CACHE_KEY }}@bazel-remote-cache.devprod.cloudflare.dev --config=release_linux //types:types_worker
- name: Modify package.json version
run: node npm/scripts/bump-version.mjs npm/workerd/package.json
env:
WORKERD_VERSION: ${{ needs.version.outputs.version }}
LATEST_COMPATIBILITY_DATE: ${{ needs.version.outputs.date }}
- run: mkdir -p npm/workerd/lib
- run: mkdir -p npm/workerd/bin
- name: Build node-install
run: npx esbuild npm/lib/node-install.ts --outfile=npm/workerd/install.js --bundle --target=node16 --define:LATEST_COMPATIBILITY_DATE="\"${LATEST_COMPATIBILITY_DATE}\"" --define:WORKERD_VERSION="\"${WORKERD_VERSION}\"" --platform=node --external:workerd --log-level=warning
env:
WORKERD_VERSION: ${{ needs.version.outputs.version }}
LATEST_COMPATIBILITY_DATE: ${{ needs.version.outputs.date }}
- name: Build node-shim
run: npx esbuild npm/lib/node-shim.ts --outfile=npm/workerd/bin/workerd --bundle --target=node16 --define:LATEST_COMPATIBILITY_DATE="\"${LATEST_COMPATIBILITY_DATE}\"" --define:WORKERD_VERSION="\"${WORKERD_VERSION}\"" --platform=node --external:workerd --log-level=warning
env:
WORKERD_VERSION: ${{ needs.version.outputs.version }}
LATEST_COMPATIBILITY_DATE: ${{ needs.version.outputs.date }}
- name: Build node-path
run: npx esbuild npm/lib/node-path.ts --outfile=npm/workerd/lib/main.js --bundle --target=node16 --define:LATEST_COMPATIBILITY_DATE="\"${LATEST_COMPATIBILITY_DATE}\"" --define:WORKERD_VERSION="\"${WORKERD_VERSION}\"" --platform=node --external:workerd --log-level=warning
env:
WORKERD_VERSION: ${{ needs.version.outputs.version }}
LATEST_COMPATIBILITY_DATE: ${{ needs.version.outputs.date }}
- name: Build package
run: node npm/scripts/build-shim-package.mjs
env:
WORKERD_VERSION: ${{ needs.version.outputs.version }}
LATEST_COMPATIBILITY_DATE: ${{ needs.version.outputs.date }}
- run: echo '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' > npm/workerd/.npmrc
- run: cd npm/workerd && npm publish --access public --tag ${{ inputs.prerelease == true && 'beta' || 'latest'}}
env:
NPM_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}