1+ name : Publish
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+ paths-ignore :
8+ - ' **/*.md'
9+
10+ jobs :
11+ bump-version :
12+ if : github.repository_owner == 'mackenly' && needs.lint.result == 'success' && needs.test.result == 'success'
13+ runs-on : ubuntu-latest
14+ timeout-minutes : 10
15+ permissions :
16+ contents : write
17+
18+ steps :
19+ - name : Checkout code
20+ uses : actions/checkout@v4
21+ with :
22+ fetch-depth : 0
23+
24+ - name : Set up Node.js
25+ uses : actions/setup-node@v4
26+ with :
27+ node-version : ' 22'
28+
29+ - name : Install dependencies
30+ run : npm ci
31+
32+ - name : Run lint
33+ run : npm run lint
34+
35+ - name : Run tests
36+ run : npm run test
37+
38+ - name : Bump version and update jsr.json
39+ id : bump_version
40+ run : |
41+ git config --global user.email "github-actions[bot]@users.noreply.github.com"
42+ git config --global user.name "github-actions[bot]"
43+ # First bump the version in package.json and get the new tag
44+ new_tag=$(npm version patch --no-git-tag-version)
45+ echo "new_tag=${new_tag}" >> $GITHUB_ENV
46+
47+ # Now update jsr.json with the new version from package.json
48+ new_version=$(jq -r '.version' package.json)
49+ jq --arg new_version "$new_version" '.version = $new_version' jsr.json > jsr.tmp && mv jsr.tmp jsr.json
50+
51+ # Commit all changes and push with tag
52+ git add package.json jsr.json
53+ git commit -m "ci: bump version to $new_tag"
54+ git tag $new_tag
55+ git push origin main --follow-tags
56+
57+ publish-npm :
58+ if : success()
59+ runs-on : ubuntu-latest
60+ needs : bump-version
61+ timeout-minutes : 10
62+ permissions :
63+ contents : read
64+
65+ steps :
66+ - name : Checkout code
67+ uses : actions/checkout@v4
68+
69+ - name : Set up Node.js
70+ uses : actions/setup-node@v4
71+ with :
72+ node-version : ' 22'
73+ registry-url : ' https://registry.npmjs.org'
74+ scope : ' @${{ github.repository_owner }}'
75+
76+ - name : Configure npm
77+ run : echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ~/.npmrc
78+ env :
79+ NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
80+
81+ - name : Install dependencies
82+ run : npm ci
83+
84+ - name : Build
85+ run : npm run build
86+
87+ - name : Publish to npm
88+ run : npm publish --access public --tag latest
89+ env :
90+ NODE_AUTH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
91+
92+ publish-github-packages :
93+ if : success()
94+ runs-on : ubuntu-latest
95+ needs : bump-version
96+ timeout-minutes : 10
97+ permissions :
98+ contents : read
99+ packages : write
100+
101+ steps :
102+ - name : Checkout code
103+ uses : actions/checkout@v4
104+
105+ - name : Set up Node.js
106+ uses : actions/setup-node@v4
107+ with :
108+ node-version : ' 22'
109+ registry-url : ' https://npm.pkg.github.com'
110+ scope : ' @${{ github.repository_owner }}'
111+
112+ - name : Install dependencies
113+ run : npm ci
114+
115+ - name : Build
116+ run : npm run build
117+
118+ - name : Publish to GitHub Packages
119+ run : npm publish --access public
120+ env :
121+ NODE_AUTH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
122+
123+ publish-jsr :
124+ if : success()
125+ runs-on : ubuntu-latest
126+ needs : bump-version
127+ timeout-minutes : 10
128+ permissions :
129+ contents : read
130+ id-token : write # The OIDC ID token is used for authentication with JSR.
131+
132+ steps :
133+ - name : Checkout code
134+ uses : actions/checkout@v4
135+
136+ - name : Publish to jsr
137+ run : npx jsr publish
138+
139+ create-release :
140+ if : success()
141+ runs-on : ubuntu-latest
142+ needs : bump-version
143+ timeout-minutes : 10
144+ permissions :
145+ contents : read
146+
147+ steps :
148+ - name : Checkout code
149+ uses : actions/checkout@v4
150+
151+ - name : Create release
152+ id : create_release
153+ uses : ncipollo/release-action@v1
154+ env :
155+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
156+ with :
157+ tag : ${{ env.new_tag }}
158+ name : ${{ env.new_tag }}
159+ generateReleaseNotes : true
160+ draft : false
161+ prerelease : false
0 commit comments