Skip to content

Commit 78a2f68

Browse files
Update npm-publish.yml
1 parent 0f52657 commit 78a2f68

1 file changed

Lines changed: 30 additions & 2 deletions

File tree

.github/workflows/npm-publish.yml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ on:
1010
jobs:
1111
publish:
1212
runs-on: ubuntu-latest
13+
1314
permissions:
14-
contents: write
15+
contents: write
1516

1617
steps:
1718
- name: Checkout code
@@ -29,12 +30,39 @@ jobs:
2930
- name: Install dependencies
3031
run: npm ci
3132

32-
- name: Run tests
33+
- name: Run tests (fixed)
3334
run: npm test -- --passWithNoTests
3435

3536
- name: Build package
3637
run: npm run build
3738

39+
- name: Conditional version bump and publish
40+
run: |
41+
if [[ ${{ github.ref }} == refs/heads/master ]]; then
42+
git config user.name 'GitHub Actions'
43+
git config user.email 'actions@github.com'
44+
fi
45+
46+
if [[ ${{ github.ref }} == refs/tags/* ]]; then
47+
echo "Tag push/Release detected: Publishing without version bump."
48+
npm publish --access public
49+
elif [[ ${{ github.ref }} == refs/heads/master ]]; then
50+
echo "Master branch push detected: Bumping version and publishing."
51+
52+
npm version patch -m "ci: bump version to %s [skip ci]"
53+
npm publish --access public
54+
else
55+
echo "Not master or a tag. Skipping publish."
56+
fi
57+
env:
58+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
59+
60+
- name: Push version changes
61+
if: github.ref == 'refs/heads/master'
62+
run: git push origin master --follow-tags
63+
env:
64+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
65+
3866
- name: Conditional version bump and publish
3967

4068
run: |

0 commit comments

Comments
 (0)