10
10
- ' build/**'
11
11
release :
12
12
types : [created]
13
+ workflow_dispatch :
14
+ inputs :
15
+ force_publish :
16
+ description : ' Force publish even if version exists'
17
+ required : false
18
+ type : boolean
19
+ default : false
13
20
14
21
jobs :
15
22
publish :
16
23
runs-on : ubuntu-latest
24
+ permissions :
25
+ contents : write
26
+ packages : write
17
27
steps :
18
28
- uses : actions/checkout@v3
29
+ with :
30
+ fetch-depth : 0
19
31
20
32
- name : Use Node.js
21
33
uses : actions/setup-node@v3
24
36
cache : ' npm'
25
37
registry-url : ' https://registry.npmjs.org'
26
38
39
+ - name : Setup Git
40
+ run : |
41
+ git config user.name "GitHub Actions Bot"
42
+ git config user.email "[email protected] "
43
+
27
44
- name : Install dependencies
28
45
run : npm ci
29
46
52
69
echo "Version ${{ steps.extract_version.outputs.version }} doesn't exist yet"
53
70
fi
54
71
continue-on-error : true
72
+
73
+ # Auto bump version if it already exists and force_publish is true or triggered by push
74
+ - name : Auto bump version if needed
75
+ id : auto_bump
76
+ if : |
77
+ (steps.version_check.outputs.exists == 'true') &&
78
+ ((github.event_name == 'push') || (github.event_name == 'workflow_dispatch' && inputs.force_publish))
79
+ run : |
80
+ echo "Auto-bumping version because version ${{ steps.extract_version.outputs.version }} already exists"
81
+ npm version patch -m "Auto bump version to %s [skip ci]"
82
+ echo "new_version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
83
+
84
+ # Get final version to use
85
+ - name : Determine final version
86
+ id : final_version
87
+ run : |
88
+ if [[ "${{ steps.auto_bump.outputs.new_version }}" != "" ]]; then
89
+ echo "version=${{ steps.auto_bump.outputs.new_version }}" >> $GITHUB_OUTPUT
90
+ echo "Using auto-bumped version: ${{ steps.auto_bump.outputs.new_version }}"
91
+ else
92
+ echo "version=${{ steps.extract_version.outputs.version }}" >> $GITHUB_OUTPUT
93
+ echo "Using original version: ${{ steps.extract_version.outputs.version }}"
94
+ fi
95
+
96
+ # Push changes if version was bumped
97
+ - name : Push changes if version was bumped
98
+ if : steps.auto_bump.outputs.new_version != ''
99
+ run : |
100
+ git push
101
+ git push --tags
102
+
103
+ # Create GitHub release if version was bumped or if the version doesn't exist (for manual releases)
104
+ - name : Create GitHub Release
105
+ if : |
106
+ (steps.auto_bump.outputs.new_version != '') ||
107
+ (steps.version_check.outputs.exists == 'false')
108
+ uses : softprops/action-gh-release@v1
109
+ with :
110
+ tag_name : v${{ steps.final_version.outputs.version }}
111
+ name : Release v${{ steps.final_version.outputs.version }}
112
+ generate_release_notes : true
113
+ env :
114
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
55
115
56
116
- name : Publish to npm
57
- if : steps.version_check.outputs.exists != 'true'
117
+ if : |
118
+ (steps.version_check.outputs.exists == 'false') ||
119
+ (steps.auto_bump.outputs.new_version != '')
58
120
run : npm publish
59
121
env :
60
122
NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
0 commit comments