From 0cfb84ce4a810890cb92a7338747bbc5fb829cd2 Mon Sep 17 00:00:00 2001 From: Drew Stone Date: Thu, 14 May 2026 12:46:01 -0600 Subject: [PATCH] =?UTF-8?q?ci:=20add=20publish.yml=20=E2=80=94=20auto-publ?= =?UTF-8?q?ish=20to=20npm=20on=20v*=20tag=20push?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mirrors the tangle-network/agent-runtime publish workflow. Tag push fires verify (lint+typecheck+test+build+version-lock check), then publish (idempotent — skips if version already on npm registry). Requires NPM_TOKEN repo secret. --- .github/workflows/publish.yml | 83 +++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..717e337 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,83 @@ +name: Publish + +on: + push: + tags: + - 'v*' + workflow_dispatch: + +jobs: + verify: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: pnpm/action-setup@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + registry-url: https://registry.npmjs.org + + - name: Install deps + run: pnpm install --frozen-lockfile + + - name: Lint + run: pnpm run lint + + - name: Typecheck + run: pnpm run typecheck + + - name: Test + run: pnpm run test + + - name: Build + run: pnpm run build + + - name: Verify tag/version lock + run: | + NPM_VERSION=$(node -p "require('./package.json').version") + if [[ "${GITHUB_REF:-}" == refs/tags/v* ]]; then + TAG_VERSION="${GITHUB_REF#refs/tags/v}" + if [ "$TAG_VERSION" != "$NPM_VERSION" ]; then + echo "::error::Tag/version mismatch: tag=$TAG_VERSION package=$NPM_VERSION." + exit 1 + fi + fi + echo "Version locked: $NPM_VERSION" + + publish-npm: + needs: verify + if: startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@v4 + + - uses: pnpm/action-setup@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + registry-url: https://registry.npmjs.org + + - run: pnpm install --frozen-lockfile + - run: pnpm run build + + # Idempotent: re-running a tag whose npm version is already published + # must not fail the workflow. + - name: Publish to npm (skip if already published) + run: | + NAME=$(node -p "require('./package.json').name") + VERSION=$(node -p "require('./package.json').version") + if npm view "$NAME@$VERSION" version >/dev/null 2>&1; then + echo "$NAME@$VERSION already on registry; skipping publish" + else + pnpm publish --no-git-checks --access public + fi + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}