Skip to content

Commit 194d38e

Browse files
authored
Support trusted publishing for tag releases (#223)
* Support trusted publishing for tag releases Unify the publish job to handle both main branch (dev) and v* tag (release) publishes using npm trusted publishing with OIDC. * Fix prettier formatting
1 parent db08606 commit 194d38e

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Node.js CI
33
on:
44
push:
55
branches: [main]
6+
tags: ["v*"]
67
pull_request:
78
branches: [main]
89

@@ -91,11 +92,10 @@ jobs:
9192
run: pnpm install
9293
- name: Lint
9394
run: pnpm run lint
94-
main-release:
95-
name: Publish dev version to NPM
95+
publish:
96+
name: Publish to NPM
9697
runs-on: ubuntu-latest
97-
environment: CI
98-
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'captbaritone/grats'
98+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) && github.repository == 'captbaritone/grats'
9999
needs: [build, test, lint]
100100
permissions:
101101
contents: read
@@ -115,11 +115,16 @@ jobs:
115115
run: npm install -g npm@11.7.0
116116
- name: Install dependencies
117117
run: pnpm install
118-
- name: Build latest (main) version
118+
- name: Build
119119
run: pnpm run build
120-
- name: Set package version
120+
- name: Set dev version (main branch)
121+
if: github.ref == 'refs/heads/main'
121122
run: pnpm version --no-git-tag-version 0.0.0-main-${RELEASE_COMMIT_SHA:0:8}
122123
env:
123124
RELEASE_COMMIT_SHA: ${{ github.sha }}
124-
- name: Publish
125+
- name: Publish dev version (main branch)
126+
if: github.ref == 'refs/heads/main'
125127
run: pnpm publish --tag main --access=public --no-git-checks
128+
- name: Publish release (tag)
129+
if: startsWith(github.ref, 'refs/tags/v')
130+
run: pnpm publish --access=public --no-git-checks

0 commit comments

Comments
 (0)