Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 148 additions & 0 deletions .github/workflows/publish-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# Publishes `wbn` (js/bundle) or `wbn-sign` (js/sign) to npm via Google's
# OSS Exit Gate pipeline.
#
# How to use:
# 1. Bump the `version` in `js/bundle/package.json` (for `wbn`) or
# `js/sign/package.json` (for `wbn-sign`) and merge to `main`.
# 2. Go to Actions -> "Publish to npm via OSS Exit Gate" -> "Run workflow"
# on the `main` branch.
# 3. Select the `package` (`wbn-sign` or `wbn`).
# 4. Set `dry_run` to `true` to test building, WIF authentication, and staging
# to Artifact Registry without publishing to public npm, or `false` to
# trigger the actual public release on npmjs.com.

name: Publish to npm via OSS Exit Gate

on:
workflow_dispatch:
inputs:
package:
description: 'Package to publish (wbn-sign or wbn)'
required: true
type: choice
default: 'wbn-sign'
options:
- wbn-sign
- wbn
dry_run:
description: 'Dry run: stage to Artifact Registry to test auth/build, then clean up without publishing to public npm'
required: false
type: boolean
default: false

permissions:
contents: read

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
env:
PACKAGE_NAME: ${{ inputs.package }}
PACKAGE_DIR: ${{ inputs.package == 'wbn' && 'js/bundle' || 'js/sign' }}
DRY_RUN: ${{ inputs.dry_run }}
steps:
- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Use Node.js 24.x
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
with:
node-version: '24.x'
cache: 'npm'
cache-dependency-path: ${{ env.PACKAGE_DIR }}/package-lock.json

- name: Install dependencies, build, and test (${{ inputs.package }})
working-directory: ${{ env.PACKAGE_DIR }}
run: |
npm ci
npm run build
npm test

- name: Authenticate to Google Cloud for OSS Exit Gate
id: auth
uses: google-github-actions/auth@7c6bc770dae815cd3e89ee6cdf493a5fab2cc093 # v3
with:
workload_identity_provider: 'projects/305452601764/locations/global/workloadIdentityPools/builders/providers/github'

- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db # v3

- name: Clean up stale releases from staging repo
run: |
# clean up stale releases from staging repo
packages=$(gcloud artifacts packages list \
--project="oss-exit-gate-prod" \
--location="us" \
--repository="webpackage--npm" \
--format="value(name)" 2>/dev/null)

echo "${packages}" | xargs -r -I {} sh -c '
package_name=$(basename "{}")
echo "Deleting package: $package_name..."
gcloud artifacts packages delete "{}" \
--project="oss-exit-gate-prod" \
--location="us" \
--repository="webpackage--npm" \
--quiet
'

- name: Stage to Artifact Registry and trigger OSS Exit Gate
working-directory: ${{ env.PACKAGE_DIR }}
env:
ACCESS_TOKEN: ${{ steps.auth.outputs.auth_token }}
RUN_ID: ${{ github.run_id }}
RUN_ATTEMPT: ${{ github.run_attempt }}
run: |
PKG_VERSION=$(node -p "require('./package.json').version")
echo "Preparing ${PACKAGE_NAME}@${PKG_VERSION} (DRY_RUN=${DRY_RUN})..."

# Clean any prior staged package entry in Artifact Registry so retries
# for the same version do not fail on AR npm version tombstones.
gcloud artifacts packages delete "${PACKAGE_NAME}" \
--project=oss-exit-gate-prod \
--repository=webpackage--npm \
--location=us \
--quiet || true

cat << 'NPMRC' > "$HOME/.npmrc"
registry=https://us-npm.pkg.dev/oss-exit-gate-prod/webpackage--npm/
//us-npm.pkg.dev/oss-exit-gate-prod/webpackage--npm/:always-auth=true
NPMRC
echo "//us-npm.pkg.dev/oss-exit-gate-prod/webpackage--npm/:_authToken=${ACCESS_TOKEN}" >> "$HOME/.npmrc"
trap 'rm -f "$HOME/.npmrc"' EXIT

npm publish --access public --registry="https://us-npm.pkg.dev/oss-exit-gate-prod/webpackage--npm/"

cat << MANIFEST > manifest.json
{
"publish_all": false,
"publishing_groups": [
{
"packages": [
{
"name": "${PACKAGE_NAME}",
"version": "${PKG_VERSION}"
}
]
}
]
}
MANIFEST

echo "Generated manifest.json:"
cat manifest.json

if [[ "${DRY_RUN}" == "true" ]]; then
echo "Dry run enabled: skipping GCS manifest upload to OSS Exit Gate and cleaning up staged package."
gcloud artifacts packages delete "${PACKAGE_NAME}" \
--project=oss-exit-gate-prod \
--repository=webpackage--npm \
--location=us \
--quiet || true
exit 0
fi

gcloud storage cp manifest.json "gs://oss-exit-gate-prod-projects-bucket/webpackage/npm/manifests/manifest-${PACKAGE_NAME}-${PKG_VERSION}-${RUN_ID}-${RUN_ATTEMPT}.json"
9 changes: 9 additions & 0 deletions js/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,12 @@ extension and then in VScode's settings have the following entries:
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
```

## Publishing `wbn` and `wbn-sign` to npm

Both `wbn` (`js/bundle`) and `wbn-sign` (`js/sign`) are published independently via the [`.github/workflows/publish-npm.yml`](../.github/workflows/publish-npm.yml) GitHub Actions workflow using Google's OSS Exit Gate pipeline:

1. Update the `"version"` field in `js/bundle/package.json` (for `wbn`) or `js/sign/package.json` (for `wbn-sign`) and merge the PR into `main`.
2. In GitHub, navigate to **Actions** -> **Publish to npm via OSS Exit Gate** -> **Run workflow** (on the `main` branch).
3. Select the target **`package`** (`wbn-sign` or `wbn`).
4. *(Optional)* Check **`dry_run`** to verify building, testing, Workload Identity Federation authentication, and staging to Artifact Registry without publishing to public npm. Leave `dry_run` unchecked to publish the release to npmjs.com.