|
1 | | -name: Publish |
| 1 | +name: Publish GitHub Package |
| 2 | + |
2 | 3 | on: |
3 | | - issues: |
4 | | - types: [labeled] |
| 4 | + workflow_dispatch: |
5 | 5 |
|
6 | 6 | permissions: |
7 | | - actions: read |
8 | | - contents: write |
9 | | - issues: write |
10 | | - id-token: write |
| 7 | + contents: read |
| 8 | + packages: write |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: publish-hono-openapi |
| 12 | + cancel-in-progress: false |
11 | 13 |
|
12 | 14 | jobs: |
13 | 15 | publish: |
14 | | - if: >- |
15 | | - github.event.label.name == 'accepted' && |
16 | | - github.event.issue.state == 'open' |
| 16 | + if: github.repository == 'photon-hq/hono-openapi' && github.ref == 'refs/heads/main' |
17 | 17 | runs-on: ubuntu-latest |
18 | | - name: Publish release |
19 | | - timeout-minutes: 15 |
20 | 18 | steps: |
21 | | - - name: Generate GitHub App token |
22 | | - id: token |
23 | | - uses: actions/create-github-app-token@v2 |
24 | | - with: |
25 | | - app-id: ${{ vars.CRAFT_APP_ID }} |
26 | | - private-key: ${{ secrets.CRAFT_APP_PRIVATE_KEY }} |
27 | | - |
28 | | - - name: Parse version from issue title |
29 | | - id: release |
30 | | - env: |
31 | | - ISSUE_TITLE: ${{ github.event.issue.title }} |
32 | | - run: | |
33 | | - set -euo pipefail |
34 | | - # Title: "publish: <owner>/<repo>@<version>" |
35 | | - version="${ISSUE_TITLE##*@}" |
36 | | - if [[ -z "$version" ]]; then |
37 | | - echo "::error::Could not parse version from title: $ISSUE_TITLE" |
38 | | - exit 1 |
39 | | - fi |
40 | | - echo "version=$version" >> "$GITHUB_OUTPUT" |
41 | | - echo "branch=release/$version" >> "$GITHUB_OUTPUT" |
42 | | -
|
43 | | - - uses: actions/checkout@v4 |
44 | | - with: |
45 | | - ref: release/${{ steps.release.outputs.version }} |
46 | | - token: ${{ steps.token.outputs.token }} |
47 | | - fetch-depth: 0 |
48 | | - |
49 | | - - uses: pnpm/action-setup@v4 |
50 | | - |
51 | | - - uses: actions/setup-node@v4 |
| 19 | + - uses: actions/checkout@v7 |
| 20 | + - uses: pnpm/action-setup@v6 |
| 21 | + - uses: actions/setup-node@v6 |
52 | 22 | with: |
53 | 23 | node-version: 24 |
54 | | - registry-url: "https://registry.npmjs.org" |
55 | | - |
56 | | - - name: Set git user |
57 | | - run: | |
58 | | - git config user.name "github-actions[bot]" |
59 | | - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
60 | | -
|
61 | | - - name: Ensure npm supports trusted publishing |
62 | | - run: npm install -g npm@latest |
63 | | - |
64 | | - - name: Install Craft |
65 | | - run: | |
66 | | - CRAFT_URL=$(curl -fsSL https://api.github.com/repos/getsentry/craft/releases/latest \ |
67 | | - | jq -r '.assets[] | select(.name == "craft") | .browser_download_url') |
68 | | - sudo curl -fsSL -o /usr/local/bin/craft "$CRAFT_URL" |
69 | | - sudo chmod +x /usr/local/bin/craft |
70 | | -
|
71 | | - - name: Wait for package artifacts on release branch |
| 24 | + cache: pnpm |
| 25 | + registry-url: https://npm.pkg.github.com |
| 26 | + scope: '@photon-hq' |
| 27 | + - run: pnpm install --frozen-lockfile |
72 | 28 | env: |
73 | | - GH_TOKEN: ${{ steps.token.outputs.token }} |
74 | | - run: | |
75 | | - set -euo pipefail |
76 | | - branch="${{ steps.release.outputs.branch }}" |
77 | | - echo "Waiting for Package Artifacts on $branch..." |
78 | | - run_id=$(gh run list --workflow "Package Artifacts" --branch "$branch" \ |
79 | | - --json databaseId --jq '.[0].databaseId') |
80 | | - if [[ -z "$run_id" || "$run_id" == "null" ]]; then |
81 | | - echo "::error::No Package Artifacts run found for branch $branch" |
82 | | - exit 1 |
83 | | - fi |
84 | | - gh run watch "$run_id" --exit-status |
85 | | -
|
86 | | - - name: Publish with Craft |
87 | | - run: craft publish "${{ steps.release.outputs.version }}" --no-input --no-status-check |
88 | | - env: |
89 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
90 | | - GITHUB_API_TOKEN: ${{ steps.token.outputs.token }} |
91 | | - |
92 | | - - name: Close issue on success |
93 | | - if: success() |
94 | | - env: |
95 | | - GH_TOKEN: ${{ steps.token.outputs.token }} |
96 | | - run: | |
97 | | - gh issue close "${{ github.event.issue.number }}" \ |
98 | | - --comment "Published **v${{ steps.release.outputs.version }}** successfully. |
99 | | - [Workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})" |
100 | | -
|
101 | | - - name: Handle failure |
102 | | - if: failure() |
| 29 | + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + - run: pnpm test --run |
| 31 | + - run: pnpm build |
| 32 | + - run: pnpm publish --tag latest --no-git-checks |
103 | 33 | env: |
104 | | - GH_TOKEN: ${{ steps.token.outputs.token }} |
105 | | - run: | |
106 | | - gh issue comment "${{ github.event.issue.number }}" \ |
107 | | - --body "Publish failed. See [run logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})." |
108 | | - gh issue edit "${{ github.event.issue.number }}" --remove-label accepted |
| 34 | + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments