Skip to content

Commit 5193893

Browse files
committed
ci: trigger release on push to master instead of tag push
1 parent 79be62f commit 5193893

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

.github/workflows/release.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: Release
22

33
on:
44
push:
5-
tags:
6-
- 'v*.*.*'
5+
branches:
6+
- master
77

88
jobs:
99
release:
@@ -13,6 +13,8 @@ jobs:
1313

1414
steps:
1515
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
1618

1719
- name: Use Node.js 20
1820
uses: actions/setup-node@v4
@@ -29,13 +31,37 @@ jobs:
2931
- name: Unit tests
3032
run: npx jest --testPathPatterns=spec
3133

34+
- name: Get version
35+
id: version
36+
run: echo "value=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
37+
38+
- name: Check if version already published
39+
id: check
40+
run: |
41+
if npm view api_cloudflare_client@${{ steps.version.outputs.value }} version 2>/dev/null; then
42+
echo "exists=true" >> $GITHUB_OUTPUT
43+
else
44+
echo "exists=false" >> $GITHUB_OUTPUT
45+
fi
46+
47+
- name: Tag release
48+
if: steps.check.outputs.exists == 'false'
49+
run: |
50+
git config user.name "github-actions[bot]"
51+
git config user.email "github-actions[bot]@users.noreply.github.com"
52+
git tag -a "v${{ steps.version.outputs.value }}" -m "v${{ steps.version.outputs.value }}"
53+
git push origin "v${{ steps.version.outputs.value }}"
54+
3255
- name: Publish to npm
56+
if: steps.check.outputs.exists == 'false'
3357
run: npm publish
3458
env:
3559
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3660

3761
- name: Create GitHub Release
62+
if: steps.check.outputs.exists == 'false'
3863
uses: softprops/action-gh-release@v2
3964
with:
65+
tag_name: v${{ steps.version.outputs.value }}
4066
generate_release_notes: true
4167
body_path: CHANGELOG.md

0 commit comments

Comments
 (0)