progfay/scrapbox-parser

View on GitHub
.github/workflows/publish.yml

Summary

Maintainability
Test Coverage
name: "Publish"

on:
  workflow_dispatch:
    inputs:
      new_version:
        description: ref. https://docs.npmjs.com/cli/commands/npm-version
        required: true
        type: choice
        options:
        - major
        - minor
        - patch

jobs:
  publish:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      id-token: write # The OIDC ID token is used for authentication with JSR.
    steps:
      - uses: actions/checkout@v4.2.2
      - uses: actions/setup-node@v4.1.0
        with:
          registry-url: 'https://registry.npmjs.org'
      - name: Publish package
        run: |
          # Setup Git user
          git config user.name "actions-user"
          git config user.email "action@github.com"

          # Set package version
          npm version $NEW_VERSION
          node -p 'JSON.stringify({ ...require("./jsr.json"), version: require("./package.json").version }, undefined, "\t")' > _jsr.json && mv _jsr.json jsr.json
          git add jsr.json
          git commit --amend --no-edit

          # Install dependencies
          npm ci

          # Publish
          npm publish --provenance --access public
          npm exec --yes -- jsr publish

          # Push version up commit
          git push
        env:
          NEW_VERSION: ${{ inputs.new_version }}
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}