Skip to content

Commit 3087585

Browse files
committed
ci(publish): bump package version, publish to npm on main and push version commit/tag
Run publish on main (not tags), bump package.json patch version before publish, publish to npm, then commit+tag and push; add concurrency, proper git config, fetch-depth, and write permissions for pushing the bump.
1 parent 9359795 commit 3087585

1 file changed

Lines changed: 35 additions & 5 deletions

File tree

.github/workflows/publish.yml

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1-
name: Publish to npm
1+
name: Bump & publish to npm
22

33
on:
44
push:
5-
tags:
6-
- "v*"
5+
branches:
6+
- main
7+
8+
# Only one release at a time; never cancel a release mid-publish.
9+
concurrency:
10+
group: publish-main
11+
cancel-in-progress: false
712

813
jobs:
914
publish:
1015
runs-on: ubuntu-latest
1116
permissions:
12-
contents: read
17+
contents: write # to push the version bump commit + tag
1318
id-token: write # for npm provenance
1419
steps:
1520
- uses: actions/checkout@v6
21+
with:
22+
fetch-depth: 0
1623

1724
- uses: actions/setup-node@v6
1825
with:
@@ -30,6 +37,29 @@ jobs:
3037
env:
3138
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3239

33-
- run: npm publish --access public
40+
- name: Configure git
41+
run: |
42+
git config user.name "github-actions[bot]"
43+
git config user.email "github-actions[bot]@users.noreply.github.com"
44+
45+
- name: Bump version (patch)
46+
id: bump
47+
run: |
48+
# Bump package.json only — no commit/tag yet, and skip the
49+
# postversion hook so nothing is pushed before we publish.
50+
VERSION=$(npm version patch --no-git-tag-version --ignore-scripts)
51+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
52+
echo "Bumped to $VERSION"
53+
54+
- name: Publish to npm
55+
run: npm publish --access public
3456
env:
3557
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
58+
59+
- name: Commit, tag & push
60+
run: |
61+
VERSION="${{ steps.bump.outputs.version }}"
62+
git commit -am "chore(release): $VERSION [skip ci]"
63+
git tag -a "$VERSION" -m "$VERSION"
64+
git push origin "HEAD:main"
65+
git push origin "$VERSION"

0 commit comments

Comments
 (0)