Skip to content

Commit

Permalink
remove old release assets
Browse files Browse the repository at this point in the history
  • Loading branch information
Puyodead1 committed Dec 22, 2023
1 parent 27ae46b commit 9d44ad8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

27 changes: 26 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { existsSync } from 'fs';
import { basename, dirname, resolve } from 'path';

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

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

async function run(): Promise<void> {
if (process.env.GITHUB_TOKEN === undefined) {
throw new Error('GITHUB_TOKEN is required');
}

try {
const projectPath = resolve(
process.cwd(),
Expand Down Expand Up @@ -177,6 +181,27 @@ async function run(): Promise<void> {
}
}

// delete old release assets
const github = getOctokit(process.env.GITHUB_TOKEN);

const existingAssets = (
await github.rest.repos.listReleaseAssets({
owner: owner,
repo: repo,
release_id: releaseId,
per_page: 50,
})
).data;

for (const asset of existingAssets) {
console.log(`Deleting existing ${asset.name}...`);
await github.rest.repos.deleteReleaseAsset({
owner: owner,
repo: repo,
asset_id: asset.id,
});
}

await uploadReleaseAssets(owner, repo, releaseId, artifacts);

if (includeUpdaterJson) {
Expand Down

0 comments on commit 9d44ad8

Please sign in to comment.