File tree Expand file tree Collapse file tree 2 files changed +62
-3
lines changed Expand file tree Collapse file tree 2 files changed +62
-3
lines changed Original file line number Diff line number Diff line change @@ -5,10 +5,10 @@ name: Publish Node.js Package
5
5
6
6
on :
7
7
release :
8
- types : [created]
8
+ types : [" created" ]
9
9
workflow_dispatch :
10
10
inputs :
11
- release-type :
11
+ release-version :
12
12
required : true
13
13
14
14
jobs :
21
21
node-version : 16
22
22
- run : |
23
23
npm install
24
+
24
25
publish-gpr :
25
26
needs : build
26
27
runs-on : ubuntu-latest
34
35
node-version : 16
35
36
registry-url : " https://registry.npmjs.org"
36
37
scope : " @layer5"
37
- - run : npm publish --verbose
38
+
39
+ - name : Run npm release
40
+ run : npm run release ${{ github.event.inputs.release-version || github.event.release.tag_name }}
41
+ if : github.event_name == 'workflow_dispatch' || github.event_name == 'release'
42
+
38
43
env :
39
44
NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
45
+
46
+ - name : Commit and push version change
47
+ uses : stefanzweifel/git-auto-commit-action@v4
48
+ with :
49
+ commit_user_name : l5io
50
+ commit_user_email : ci@layer5.io
51
+ commit_author : ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
52
+ commit_options : " --signoff"
53
+ commit_message : " [Release]: Bump version to ${{ github.event.inputs.release-version || github.event.release.tag_name }}"
Original file line number Diff line number Diff line change
1
+ const fs = require ( "fs" ) ;
2
+ const path = require ( "path" ) ;
3
+ // for building and release the package
4
+
5
+ // bump version
6
+ const bump = ( version ) => {
7
+ const packagePath = path . resolve ( __dirname , "package.json" ) ;
8
+ const package = require ( packagePath ) ;
9
+ package . version = version ;
10
+ fs . writeFileSync ( packagePath , JSON . stringify ( package , null , 2 ) ) ;
11
+ console . log ( "bumped version to " + version ) ;
12
+ } ;
13
+
14
+ // build
15
+ const build = ( ) => {
16
+ // nothing here yet
17
+ } ;
18
+
19
+ const publish = ( ) => {
20
+ // publish to npm
21
+ const execSync = require ( "child_process" ) . execSync ;
22
+ execSync ( "npm publish --verbose" , { stdio : [ 0 , 1 , 2 ] } ) ;
23
+ console . log ( "published to npm" ) ;
24
+ } ;
25
+
26
+ // main
27
+ const main = ( ) => {
28
+ const args = process . argv . slice ( 2 ) ;
29
+ const version = args [ 0 ] ;
30
+ if ( ! version ) {
31
+ console . error ( "version is required" ) ;
32
+ process . exit ( 1 ) ;
33
+ }
34
+ try {
35
+ bump ( version ) ;
36
+ build ( ) ;
37
+ publish ( ) ;
38
+ console . log ( "done" ) ;
39
+ } catch ( e ) {
40
+ console . error ( e ) ;
41
+ process . exit ( 1 ) ;
42
+ }
43
+ } ;
44
+
45
+ main ( ) ;
You can’t perform that action at this time.
0 commit comments