diff --git a/.github/workflows/npm-publish.yaml b/.github/workflows/npm-publish.yaml deleted file mode 100644 index d90876b..0000000 --- a/.github/workflows/npm-publish.yaml +++ /dev/null @@ -1,42 +0,0 @@ -name: release - -on: - release: - types: [published] - # release-tag workflow は GITHUB_TOKEN で GitHub release を作成するが、 - # GITHUB_TOKEN が起こしたイベントは他の workflow をトリガーしない仕様の - # ため、上の release: published では起動しない。手動で publish できるよう - # workflow_dispatch を用意している。 - workflow_dispatch: - -jobs: - publish: - runs-on: ubuntu-latest - - permissions: - contents: read - id-token: write - - steps: - # release イベントはタグを、workflow_dispatch は実行対象ブランチ - # (通常は main) をチェックアウトする。publish するバージョンは - # どちらの場合もチェックアウトした package.json から取得する。 - - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - with: - ref: ${{ github.event.release.tag_name || github.ref }} - - name: Setup Node.js 24.x - uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 - with: - node-version: 24.x - registry-url: https://registry.npmjs.org - - uses: pnpm/action-setup@b307475762933b98ed359c036b0e51f26b63b74b # v5.0.0 - - name: Upgrade npm for Trusted Publishing - run: npm install -g npm@latest - - run: pnpm i --frozen-lockfile - - run: pnpm run lint - - run: pnpm run fmt:check - - run: pnpm run test - - run: pnpm run build - - name: Publish to npm - if: github.event_name == 'workflow_dispatch' || github.event.release.prerelease == false - run: npm publish --provenance --access public diff --git a/.github/workflows/release-tag.yaml b/.github/workflows/release-tag.yaml index 042e272..cab82e7 100644 --- a/.github/workflows/release-tag.yaml +++ b/.github/workflows/release-tag.yaml @@ -10,6 +10,9 @@ jobs: runs-on: ubuntu-latest permissions: contents: write + outputs: + version: ${{ steps.version.outputs.value }} + created: ${{ steps.tag-check.outputs.exists == 'false' }} steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: @@ -34,3 +37,31 @@ jobs: git tag "v$VERSION" git push origin "v$VERSION" gh release create "v$VERSION" --title "v$VERSION" --generate-notes + + publish: + needs: release-tag + # 新しいタグを作成した場合のみ publish する。GITHUB_TOKEN が起こした + # release イベントは別 workflow をトリガーしないため、publish は別 + # workflow ではなく同一 workflow の後続ジョブとして実行する。 + if: needs.release-tag.outputs.created == 'true' + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - name: Setup Node.js 24.x + uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 + with: + node-version: 24.x + registry-url: https://registry.npmjs.org + - uses: pnpm/action-setup@b307475762933b98ed359c036b0e51f26b63b74b # v5.0.0 + - name: Upgrade npm for Trusted Publishing + run: npm install -g npm@latest + - run: pnpm i --frozen-lockfile + - run: pnpm run lint + - run: pnpm run fmt:check + - run: pnpm run test + - run: pnpm run build + - name: Publish to npm + run: npm publish --provenance --access public