# Publishes the npm packages (scripts/build-npm.mjs, scripts/publish-npm.mjs): the @open-artifact/* libraries, # @open-artifact/cli and dsh-open-artifact. Each version npm already has is skipped, so bump the versions you want # released, then push a tag (v0.2.0) or run the workflow by hand. # # On a tag, CHANGELOG.md must have that version's entry (written from `node scripts/changelog.mjs`): the run stops # before publishing without one. The GitHub release gets those notes and a prebuilt plugin bundle. # # npm signs in by trusted publishing (OIDC): each package names this repository and this file as its trusted # publisher on npmjs.com (`npm trust github --file publish-npm.yml --repo JimLiu/open-artifact --allow-publish`). # No npm token is stored here, and npm adds provenance. A new package is claimed once from a computer first: # `node scripts/publish-npm.mjs --claim` publishes the staged version of each package npm doesn't have (npm trusts # only a package it has, and refuses placeholder versions), then sets this workflow as its trusted publisher. name: Publish to npm on: push: tags: ['v*'] workflow_dispatch: inputs: dry-run: description: Show what would be published, without publishing type: boolean default: false permissions: contents: write # the GitHub release id-token: write concurrency: group: publish-npm cancel-in-progress: false jobs: publish: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Check the changelog if: github.ref_type == 'tag' run: node scripts/changelog.mjs --check "$GITHUB_REF_NAME" - uses: actions/setup-node@v4 with: node-version: 24 registry-url: https://registry.npmjs.org cache: npm # Trusted publishing needs npm 11.5.1 or later. - run: npm install -g npm@11 - run: npm ci - name: Build run: | npm run build node scripts/build-skill.mjs node scripts/build-npm.mjs - name: Package prebuilt plugins if: github.ref_type == 'tag' run: | node scripts/build-plugins.mjs --no-skill cp -R dist/plugins "$RUNNER_TEMP/open-artifact-plugins" cd "$RUNNER_TEMP" zip -qr open-artifact-plugins.zip open-artifact-plugins - name: Publish # npm attempts the OIDC exchange even in a dry run, but logs failures only at verbose level. env: npm_config_loglevel: ${{ inputs.dry-run && 'verbose' || 'notice' }} run: node scripts/publish-npm.mjs ${{ inputs.dry-run && '--dry-run' || '' }} - name: GitHub release if: github.ref_type == 'tag' && !inputs.dry-run env: GH_TOKEN: ${{ github.token }} run: | node scripts/changelog.mjs --notes "$GITHUB_REF_NAME" > "$RUNNER_TEMP/notes.md" bundle="$RUNNER_TEMP/open-artifact-plugins.zip" if uploaded=$(gh release view "$GITHUB_REF_NAME" --json assets --jq 'any(.assets[]; .name == "open-artifact-plugins.zip" and .state == "uploaded")'); then if [[ "$uploaded" != true ]]; then gh release upload "$GITHUB_REF_NAME" "$bundle" --clobber fi gh release edit "$GITHUB_REF_NAME" --notes-file "$RUNNER_TEMP/notes.md" --draft=false else gh release create "$GITHUB_REF_NAME" "$bundle" --title "$GITHUB_REF_NAME" --notes-file "$RUNNER_TEMP/notes.md" --verify-tag fi