Skip to content

Commit 9d44ad8

Browse files
committed
remove old release assets
1 parent 27ae46b commit 9d44ad8

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { existsSync } from 'fs';
22
import { basename, dirname, resolve } from 'path';
33

44
import * as core from '@actions/core';
5-
import { context } from '@actions/github';
5+
import { context, getOctokit } from '@actions/github';
66
import stringArgv from 'string-argv';
77

88
import { buildProject } from './build';
@@ -14,6 +14,10 @@ import { execCommand, getInfo, getTargetInfo } from './utils';
1414
import type { Artifact, BuildOptions, InitOptions } from './types';
1515

1616
async function run(): Promise<void> {
17+
if (process.env.GITHUB_TOKEN === undefined) {
18+
throw new Error('GITHUB_TOKEN is required');
19+
}
20+
1721
try {
1822
const projectPath = resolve(
1923
process.cwd(),
@@ -177,6 +181,27 @@ async function run(): Promise<void> {
177181
}
178182
}
179183

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+
180205
await uploadReleaseAssets(owner, repo, releaseId, artifacts);
181206

182207
if (includeUpdaterJson) {

0 commit comments

Comments
 (0)