File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ name : release
2
+ on :
3
+ push :
4
+ tags :
5
+ - " [0-9]+.[0-9]+.[0-9]+"
6
+ jobs :
7
+ release :
8
+ runs-on : ubuntu-latest
9
+ permissions :
10
+ contents : read
11
+ packages : write
12
+ steps :
13
+ - uses : actions/checkout@v3
14
+ - uses : actions/setup-node@v3
15
+ with :
16
+ node-version : " 22"
17
+ - run : node tools/release.mjs
18
+ env :
19
+ GITHUB_TOKEN : ${{ github.token }}
Original file line number Diff line number Diff line change
1
+ import fs from "node:fs" ;
2
+ import cp from "node:child_process" ;
3
+
4
+ function praseRef ( ref ) {
5
+ const m = ref . match ( / ^ r e f s \/ t a g s \/ ( .+ ?) $ / ) ;
6
+ if ( ! m ) throw new Error ( "no tags in ref: " + ref ) ;
7
+ return m [ 1 ] ;
8
+ }
9
+
10
+ // GHAでGHPRにnpmリリースする
11
+ async function main ( ) {
12
+ let ref = process . env [ "GITHUB_REF" ] ;
13
+ let token = process . env [ "GITHUB_TOKEN" ] ;
14
+ if ( ! ref ) throw new Error ( "no github ref" ) ;
15
+ if ( ! token ) throw new Error ( "no github token" ) ;
16
+ const tag = praseRef ( ref ) ;
17
+ const packageJson = JSON . parse ( await fs . promises . readFile ( "package.json" ) ) ;
18
+ packageJson [ "version" ] = tag ;
19
+ await fs . promises . writeFile ( "package.json" , JSON . stringify ( packageJson ) ) ;
20
+ const npmRc = "//npm.pkg.github.com/:_authToken=" + token ;
21
+ await fs . promises . writeFile ( ".npmrc" , npmRc ) ;
22
+ const p = cp . spawn ( "npm" , [ "publish" ] ) ;
23
+ await new Promise ( ( resolve , reject ) => {
24
+ p . stderr . pipe ( process . stderr ) ;
25
+ p . stdout . pipe ( process . stdout ) ;
26
+ p . on ( "close" , ( code ) => {
27
+ code === 0 ? resolve ( ) : reject ( code ) ;
28
+ } ) ;
29
+ } ) ;
30
+ console . log ( `📦 package ${ tag } released!` ) ;
31
+ }
32
+
33
+ main ( ) ;
You can’t perform that action at this time.
0 commit comments