name: Release # - Push to main: publish a snapshot to npm with the `dev` dist-tag. # - Manual run on a branch: publish a named snapshot (no tests), with the `snapshot_name` input # (defaults to the branch name) as npm dist-tag. On main without a name, same as a push to main. # - Push of a v* tag (created with .tools/prepare-release.sh): run all the verification # workflows on the tagged commit, then build and publish to npm, create the GitHub release # and deploy the docs. Re-run the failed jobs, or dispatch this workflow on the tag, to retry. # # NOTE: npm trusted publishing is bound to this file name, don't rename it. on: push: branches: [main] tags: ["v*"] workflow_dispatch: inputs: snapshot_name: description: "Snapshot name, used as npm dist-tag. Defaults to the branch name. Ignored when running on a tag" required: false default: "" type: string concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: false jobs: test: if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || startsWith(github.ref, 'refs/tags/v') uses: ./.github/workflows/test.yml integration: if: startsWith(github.ref, 'refs/tags/v') uses: ./.github/workflows/integration.yaml permissions: contents: read issues: read checks: write pull-requests: write actions: read integration-gen: if: startsWith(github.ref, 'refs/tags/v') uses: ./.github/workflows/integration-gen.yaml permissions: contents: read issues: read checks: write pull-requests: write actions: read integration-fetch: if: startsWith(github.ref, 'refs/tags/v') uses: ./.github/workflows/integration-fetch.yaml permissions: contents: read issues: read checks: write pull-requests: write actions: read compatibility: if: startsWith(github.ref, 'refs/tags/v') uses: ./.github/workflows/compatibility.yaml secrets: inherit snapshot: # Gated on the tests when pushing to main, manual snapshots don't run them. if: ${{ !cancelled() && github.ref_type == 'branch' && needs.test.result != 'failure' }} needs: test runs-on: ubuntu-latest permissions: contents: read id-token: write steps: - uses: actions/checkout@v4.4.0 - name: Setup Node.js uses: actions/setup-node@v4.4.0 with: node-version: 24 registry-url: "https://registry.npmjs.org" - uses: pnpm/action-setup@v4.3.0 with: version: 11.1.3 - name: Install dependencies run: pnpm install --frozen-lockfile - name: Set snapshot version id: snapshot env: SNAPSHOT_NAME: ${{ inputs.snapshot_name }} run: | # We're using 0.0.0 to avoid this version to be higher than released versions. # A snapshot MUST not be published with the latest dist-tag (omitting --tag defaults to latest) # to avoid users to install snapshot releases when using pnpm install, # see https://docs.npmjs.com/cli/v9/commands/npm-dist-tag for more info TIMESTAMP=$(date '+%Y%m%d%H%M%S') if [ -z "$SNAPSHOT_NAME" ] && [ "$GITHUB_REF_NAME" = "main" ]; then # To use it: "@restatedev/restate-sdk": "^0.0.0-SNAPSHOT" VERSION="0.0.0-SNAPSHOT-$TIMESTAMP" NPM_TAG="dev" else # To use it: "@restatedev/restate-sdk": "" # SNAPSHOT. sorts lower than SNAPSHOT-, so ^0.0.0-SNAPSHOT keeps resolving to the main snapshots. NAME=$(echo "${SNAPSHOT_NAME:-$GITHUB_REF_NAME}" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9-]+/-/g; s/^-+//; s/-+$//') if [[ ! "$NAME" =~ ^[a-z][a-z0-9-]*$ ]] || [ "$NAME" = "latest" ]; then echo "::error::Invalid snapshot name '$NAME', it must start with a letter and can't be 'latest'. Set the snapshot_name input" exit 1 fi VERSION="0.0.0-SNAPSHOT.$NAME.$TIMESTAMP" NPM_TAG="$NAME" fi echo "npm_tag=$NPM_TAG" >> "$GITHUB_OUTPUT" echo "Publishing \`$VERSION\` with dist-tag \`$NPM_TAG\`, e.g. \`npm install @restatedev/restate-sdk@$NPM_TAG\`" >> "$GITHUB_STEP_SUMMARY" for pkg in packages/libs/*/package.json; do jq --arg ver "$VERSION" '.version = $ver' "$pkg" > "$pkg.tmp" && mv "$pkg.tmp" "$pkg" done # Update workspace protocol dependencies to use the snapshot version pnpm install --no-frozen-lockfile # Build after setting the version, as it gets embedded in the build output (e.g. the user agent) - name: Build run: pnpm build - name: Publish snapshot run: pnpm --filter "./packages/libs/**" publish --tag "${{ steps.snapshot.outputs.npm_tag }}" --access public --no-git-checks --provenance release: if: startsWith(github.ref, 'refs/tags/v') needs: [test, integration, integration-gen, integration-fetch, compatibility] runs-on: ubuntu-latest permissions: contents: write id-token: write outputs: npm_tag: ${{ steps.version.outputs.npm_tag }} steps: - uses: actions/checkout@v4.4.0 - name: Setup Node.js uses: actions/setup-node@v4.4.0 with: node-version: 24 registry-url: "https://registry.npmjs.org" - uses: pnpm/action-setup@v4.3.0 with: version: 11.1.3 - name: Check version and compute npm dist-tag id: version run: | VERSION="${GITHUB_REF_NAME#v}" echo "version=$VERSION" >> "$GITHUB_OUTPUT" for pkg in packages/libs/*/package.json; do PKG_VERSION=$(jq -r '.version' "$pkg") if [ "$PKG_VERSION" != "$VERSION" ]; then echo "::error::$pkg has version $PKG_VERSION, expected $VERSION. Create the release tag with .tools/prepare-release.sh" exit 1 fi done if [[ "$VERSION" == *-* ]]; then # Pre-release versions (e.g. 1.2.3-rc.1, 1.2.3-alpha.0) MUST NOT be published # with the latest npm dist-tag (omitting --tag defaults to latest), otherwise # users would get the pre-release on a plain install. # We use the pre-release identifier (rc, alpha, beta, ...) as the dist-tag. PRERELEASE_ID="${VERSION#*-}" echo "prerelease=true" >> "$GITHUB_OUTPUT" echo "npm_tag=${PRERELEASE_ID%%.*}" >> "$GITHUB_OUTPUT" exit 0 fi echo "prerelease=false" >> "$GITHUB_OUTPUT" # Releasing an older line (e.g. a backport) must not move the latest dist-tag backwards. LATEST=$(npm view @restatedev/restate-sdk dist-tags.latest) if [ "$(printf '%s\n%s\n' "$LATEST" "$VERSION" | sort -V | tail -n1)" = "$VERSION" ]; then echo "npm_tag=latest" >> "$GITHUB_OUTPUT" else MAJOR_MINOR=$(echo "$VERSION" | cut -d. -f1,2) echo "npm_tag=release-$MAJOR_MINOR" >> "$GITHUB_OUTPUT" fi - name: Install dependencies run: pnpm install --frozen-lockfile - name: Build run: pnpm build # Already published packages are skipped, so this is safe to re-run. - name: Publish to npm run: pnpm -r --filter "./packages/libs/**" publish --tag "${{ steps.version.outputs.npm_tag }}" --access public --no-git-checks --provenance - name: Create GitHub release env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} TAG: ${{ github.ref_name }} run: | if gh release view "$TAG" >/dev/null 2>&1; then echo "Release $TAG already exists" exit 0 fi EXTRA_FLAGS=() if [ "${{ steps.version.outputs.prerelease }}" = "true" ]; then EXTRA_FLAGS+=(--prerelease) fi if [ "${{ steps.version.outputs.npm_tag }}" != "latest" ]; then EXTRA_FLAGS+=(--latest=false) fi gh release create "$TAG" --title "Release $TAG" --generate-notes --verify-tag "${EXTRA_FLAGS[@]}" docs: needs: release if: needs.release.outputs.npm_tag == 'latest' uses: ./.github/workflows/release-docs.yml permissions: contents: read pages: write id-token: write