@@ -2,7 +2,7 @@ import { existsSync } from 'fs';
2
2
import { basename , dirname , resolve } from 'path' ;
3
3
4
4
import * as core from '@actions/core' ;
5
- import { context } from '@actions/github' ;
5
+ import { context , getOctokit } from '@actions/github' ;
6
6
import stringArgv from 'string-argv' ;
7
7
8
8
import { buildProject } from './build' ;
@@ -14,6 +14,10 @@ import { execCommand, getInfo, getTargetInfo } from './utils';
14
14
import type { Artifact , BuildOptions , InitOptions } from './types' ;
15
15
16
16
async function run ( ) : Promise < void > {
17
+ if ( process . env . GITHUB_TOKEN === undefined ) {
18
+ throw new Error ( 'GITHUB_TOKEN is required' ) ;
19
+ }
20
+
17
21
try {
18
22
const projectPath = resolve (
19
23
process . cwd ( ) ,
@@ -177,6 +181,27 @@ async function run(): Promise<void> {
177
181
}
178
182
}
179
183
184
+ // delete old release assets
185
+ const github = getOctokit ( process . env . GITHUB_TOKEN ) ;
186
+
187
+ const existingAssets = (
188
+ await github . rest . repos . listReleaseAssets ( {
189
+ owner : owner ,
190
+ repo : repo ,
191
+ release_id : releaseId ,
192
+ per_page : 50 ,
193
+ } )
194
+ ) . data ;
195
+
196
+ for ( const asset of existingAssets ) {
197
+ console . log ( `Deleting existing ${ asset . name } ...` ) ;
198
+ await github . rest . repos . deleteReleaseAsset ( {
199
+ owner : owner ,
200
+ repo : repo ,
201
+ asset_id : asset . id ,
202
+ } ) ;
203
+ }
204
+
180
205
await uploadReleaseAssets ( owner , repo , releaseId , artifacts ) ;
181
206
182
207
if ( includeUpdaterJson ) {
0 commit comments