|
| 1 | +on: |
| 2 | + push: |
| 3 | + branches: |
| 4 | + - main |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + dry_run: |
| 8 | + description: 'Dry-run mode' |
| 9 | + required: true |
| 10 | + default: true |
| 11 | + type: boolean |
| 12 | + package_folder: |
| 13 | + description: 'Package folder path' |
| 14 | + required: true |
| 15 | + default: './Packages/ga.fuquna.rosettaui' |
| 16 | + type: string |
| 17 | + |
| 18 | + |
| 19 | +permissions: |
| 20 | + id-token: write # Required for OIDC |
| 21 | + contents: write |
| 22 | + pull-requests: write |
| 23 | + issues: write |
| 24 | + |
| 25 | +name: release-please |
| 26 | + |
| 27 | +jobs: |
| 28 | + release-please: |
| 29 | + if: ${{ github.event_name != 'workflow_dispatch' }} |
| 30 | + runs-on: ubuntu-latest |
| 31 | + outputs: |
| 32 | + # releases_created と paths_released を後続のジョブから参照できるようにする |
| 33 | + releases_created: ${{ steps.release.outputs.releases_created }} |
| 34 | + paths_released: ${{ steps.release.outputs.paths_released }} |
| 35 | + steps: |
| 36 | + - uses: googleapis/release-please-action@v4 |
| 37 | + id: release |
| 38 | + |
| 39 | + # リリースされたパッケージをnpm publishするジョブ |
| 40 | + publish: |
| 41 | + # release-pleaseジョブが完了してから実行 |
| 42 | + needs: release-please |
| 43 | + runs-on: ubuntu-latest |
| 44 | + # release-pleaseジョブでリリースが作成された場合にのみ実行 |
| 45 | + if: ${{ needs.release-please.outputs.releases_created == 'true' }} |
| 46 | + steps: |
| 47 | + - uses: actions/checkout@v4 |
| 48 | + - uses: actions/setup-node@v4 |
| 49 | + with: |
| 50 | + node-version: '22' |
| 51 | + registry-url: 'https://registry.npmjs.org' |
| 52 | + |
| 53 | + - name: Update npm |
| 54 | + run: npm install -g npm@latest |
| 55 | + |
| 56 | + # `release-please`の出力からリリースされたパッケージを特定し、npm publishを実行 |
| 57 | + - name: Publish to npm |
| 58 | + run: | |
| 59 | + # paths_released をパースして、リリースされたパッケージをループ処理 |
| 60 | + PACKAGES_TO_PUBLISH=$(echo '${{ needs.release-please.outputs.paths_released }}' | jq -r '.[]') |
| 61 | +
|
| 62 | + if [ -z "$PACKAGES_TO_PUBLISH" ]; then |
| 63 | + echo "No packages were released, skipping npm publish." |
| 64 | + exit 0 |
| 65 | + fi |
| 66 | +
|
| 67 | + echo "Packages to publish: $PACKAGES_TO_PUBLISH" |
| 68 | +
|
| 69 | + for package_path in $PACKAGES_TO_PUBLISH; do |
| 70 | + echo "Publishing $package_path..." |
| 71 | + cd "$package_path" |
| 72 | + npm publish |
| 73 | + cd - # 元のディレクトリに戻る |
| 74 | + done |
| 75 | +
|
| 76 | + manual-publish: |
| 77 | + if: ${{ github.event_name == 'workflow_dispatch' }} |
| 78 | + runs-on: ubuntu-latest |
| 79 | + permissions: |
| 80 | + contents: read |
| 81 | + id-token: write # npm publishに必要なOIDC認証のため(推奨) |
| 82 | + |
| 83 | + steps: |
| 84 | + - uses: actions/checkout@v4 |
| 85 | + - uses: actions/setup-node@v4 |
| 86 | + with: |
| 87 | + node-version: '22' |
| 88 | + registry-url: 'https://registry.npmjs.org' |
| 89 | + |
| 90 | + - name: Update npm |
| 91 | + run: npm install -g npm@latest |
| 92 | + |
| 93 | + - name: Publish to NPM |
| 94 | + working-directory: ${{ github.event.inputs.package_folder }} |
| 95 | + env: |
| 96 | + DRY_RUN: ${{ github.event.inputs.dry_run }} |
| 97 | + run: | |
| 98 | + if [ "$DRY_RUN" = "true" ]; then |
| 99 | + npm publish --dry-run |
| 100 | + else |
| 101 | + npm publish |
| 102 | + fi |
0 commit comments