@@ -25,7 +25,7 @@ async function runOnce() {
2525 core . info ( `name: ${ name } ` ) ;
2626 core . info ( `token: ${ token } ` ) ;
2727
28- const octokit = new github . GitHub ( token ) ;
28+ const octokit = github . getOctokit ( token ) ;
2929
3030 // For the `dev` release we may need to update the tag to point to the new
3131 // commit on this branch. All other names should already have tags associated
@@ -43,20 +43,10 @@ async function runOnce() {
4343
4444 if ( tag === null || tag . data . object . sha !== sha ) {
4545 core . info ( `updating existing tag or creating new one` ) ;
46- // Delete the previous release for this tag, if any
47- try {
48- core . info ( `fetching release for ${ name } ` ) ;
49- const release = await octokit . repos . getReleaseByTag ( { owner, repo, tag : name } ) ;
50- core . info ( `deleting release ${ release . data . id } ` ) ;
51- await octokit . repos . deleteRelease ( { owner, repo, release_id : release . data . id } ) ;
52- } catch ( e ) {
53- // ignore, there may not have been a release
54- console . log ( "ERROR: " , JSON . stringify ( e , null , 2 ) ) ;
55- }
5646
5747 try {
5848 core . info ( `updating dev tag` ) ;
59- await octokit . git . updateRef ( {
49+ await octokit . rest . git . updateRef ( {
6050 owner,
6151 repo,
6252 ref : 'tags/dev' ,
@@ -80,6 +70,13 @@ async function runOnce() {
8070 // tag by this point.
8171 }
8272 }
73+
74+ console . log ( "double-checking tag is correct" ) ;
75+ tag = await octokit . request ( "GET /repos/:owner/:repo/git/refs/tags/:name" , { owner, repo, name } ) ;
76+ if ( tag . data . object . sha !== sha ) {
77+ console . log ( "tag: " , JSON . stringify ( tag . data , null , 2 ) ) ;
78+ throw new Error ( "tag didn't work" ) ;
79+ }
8380 } else {
8481 core . info ( `existing tag works` ) ;
8582 }
@@ -91,12 +88,12 @@ async function runOnce() {
9188 let release = null ;
9289 try {
9390 core . info ( `fetching release` ) ;
94- release = await octokit . repos . getReleaseByTag ( { owner, repo, tag : name } ) ;
91+ release = await octokit . rest . repos . getReleaseByTag ( { owner, repo, tag : name } ) ;
9592 } catch ( e ) {
9693 console . log ( "ERROR: " , JSON . stringify ( e , null , 2 ) ) ;
9794 core . info ( `creating a release` ) ;
9895 try {
99- release = await octokit . repos . createRelease ( {
96+ release = await octokit . rest . repos . createRelease ( {
10097 owner,
10198 repo,
10299 tag_name : name ,
@@ -105,19 +102,30 @@ async function runOnce() {
105102 } catch ( e ) {
106103 console . log ( "ERROR: " , JSON . stringify ( e , null , 2 ) ) ;
107104 core . info ( `fetching one more time` ) ;
108- release = await octokit . repos . getReleaseByTag ( { owner, repo, tag : name } ) ;
105+ release = await octokit . rest . repos . getReleaseByTag ( { owner, repo, tag : name } ) ;
109106 }
110107 }
111108 console . log ( "found release: " , JSON . stringify ( release . data , null , 2 ) ) ;
112109
113110 // Upload all the relevant assets for this release as just general blobs.
114111 for ( const file of glob . sync ( files ) ) {
115112 const size = fs . statSync ( file ) . size ;
113+ const name = path . basename ( file ) ;
114+ for ( const asset of release . data . assets ) {
115+ if ( asset . name !== name )
116+ continue ;
117+ console . log ( `deleting prior asset ${ asset . id } ` ) ;
118+ await octokit . rest . repos . deleteReleaseAsset ( {
119+ owner,
120+ repo,
121+ asset_id : asset . id ,
122+ } ) ;
123+ }
116124 core . info ( `upload ${ file } ` ) ;
117- await octokit . repos . uploadReleaseAsset ( {
125+ await octokit . rest . repos . uploadReleaseAsset ( {
118126 data : fs . createReadStream ( file ) ,
119127 headers : { 'content-length' : size , 'content-type' : 'application/octet-stream' } ,
120- name : path . basename ( file ) ,
128+ name,
121129 url : release . data . upload_url ,
122130 } ) ;
123131 }
0 commit comments