This commit is contained in:
Adriano dos Santos Fernandes 2024-02-23 22:57:53 +00:00 committed by GitHub
commit 34ae880148
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 52 additions and 19 deletions

View file

@ -174,6 +174,7 @@ The following are optional as `step.with` keys
| `draft` | Boolean | Indicator of whether or not this release is a draft | | `draft` | Boolean | Indicator of whether or not this release is a draft |
| `prerelease` | Boolean | Indicator of whether or not is a prerelease | | `prerelease` | Boolean | Indicator of whether or not is a prerelease |
| `files` | String | Newline-delimited globs of paths to assets to upload for release | | `files` | String | Newline-delimited globs of paths to assets to upload for release |
| `overwrite_files` | Boolean | Indicator of whether files should be overwritten when they already exist. Defaults to true |
| `name` | String | Name of the release. defaults to tag name | | `name` | String | Name of the release. defaults to tag name |
| `tag_name` | String | Name of a tag. defaults to `github.ref` | | `tag_name` | String | Name of a tag. defaults to `github.ref` |
| `fail_on_unmatched_files` | Boolean | Indicator of whether to fail if any of the `files` globs match nothing | | `fail_on_unmatched_files` | Boolean | Indicator of whether to fail if any of the `files` globs match nothing |

View file

@ -47,6 +47,7 @@ describe("util", () => {
input_draft: false, input_draft: false,
input_prerelease: false, input_prerelease: false,
input_files: [], input_files: [],
input_overwrite_files: undefined,
input_name: undefined, input_name: undefined,
input_tag_name: undefined, input_tag_name: undefined,
input_target_commitish: undefined, input_target_commitish: undefined,
@ -67,6 +68,7 @@ describe("util", () => {
input_draft: false, input_draft: false,
input_prerelease: false, input_prerelease: false,
input_files: [], input_files: [],
input_overwrite_files: undefined,
input_name: undefined, input_name: undefined,
input_tag_name: undefined, input_tag_name: undefined,
input_target_commitish: undefined, input_target_commitish: undefined,
@ -87,6 +89,7 @@ describe("util", () => {
input_draft: false, input_draft: false,
input_prerelease: false, input_prerelease: false,
input_files: [], input_files: [],
input_overwrite_files: undefined,
input_name: undefined, input_name: undefined,
input_tag_name: undefined, input_tag_name: undefined,
input_target_commitish: undefined, input_target_commitish: undefined,
@ -119,6 +122,7 @@ describe("util", () => {
input_draft: undefined, input_draft: undefined,
input_prerelease: undefined, input_prerelease: undefined,
input_files: [], input_files: [],
input_overwrite_files: undefined,
input_name: undefined, input_name: undefined,
input_tag_name: undefined, input_tag_name: undefined,
input_fail_on_unmatched_files: false, input_fail_on_unmatched_files: false,
@ -144,6 +148,7 @@ describe("util", () => {
input_draft: undefined, input_draft: undefined,
input_prerelease: undefined, input_prerelease: undefined,
input_files: [], input_files: [],
input_overwrite_files: undefined,
input_name: undefined, input_name: undefined,
input_tag_name: undefined, input_tag_name: undefined,
input_fail_on_unmatched_files: false, input_fail_on_unmatched_files: false,
@ -168,6 +173,7 @@ describe("util", () => {
input_draft: undefined, input_draft: undefined,
input_prerelease: undefined, input_prerelease: undefined,
input_files: [], input_files: [],
input_overwrite_files: undefined,
input_name: undefined, input_name: undefined,
input_tag_name: undefined, input_tag_name: undefined,
input_fail_on_unmatched_files: false, input_fail_on_unmatched_files: false,
@ -193,6 +199,7 @@ describe("util", () => {
input_draft: undefined, input_draft: undefined,
input_prerelease: undefined, input_prerelease: undefined,
input_files: [], input_files: [],
input_overwrite_files: undefined,
input_name: undefined, input_name: undefined,
input_tag_name: undefined, input_tag_name: undefined,
input_fail_on_unmatched_files: false, input_fail_on_unmatched_files: false,
@ -221,6 +228,7 @@ describe("util", () => {
input_draft: false, input_draft: false,
input_prerelease: true, input_prerelease: true,
input_files: [], input_files: [],
input_overwrite_files: undefined,
input_name: undefined, input_name: undefined,
input_tag_name: undefined, input_tag_name: undefined,
input_fail_on_unmatched_files: false, input_fail_on_unmatched_files: false,
@ -247,6 +255,7 @@ describe("util", () => {
input_draft: false, input_draft: false,
input_prerelease: true, input_prerelease: true,
input_files: [], input_files: [],
input_overwrite_files: undefined,
input_name: undefined, input_name: undefined,
input_tag_name: undefined, input_tag_name: undefined,
input_fail_on_unmatched_files: false, input_fail_on_unmatched_files: false,
@ -272,6 +281,7 @@ describe("util", () => {
input_draft: false, input_draft: false,
input_prerelease: true, input_prerelease: true,
input_files: [], input_files: [],
input_overwrite_files: undefined,
input_name: undefined, input_name: undefined,
input_tag_name: undefined, input_tag_name: undefined,
input_fail_on_unmatched_files: false, input_fail_on_unmatched_files: false,
@ -296,6 +306,7 @@ describe("util", () => {
input_draft: undefined, input_draft: undefined,
input_prerelease: undefined, input_prerelease: undefined,
input_files: [], input_files: [],
input_overwrite_files: undefined,
input_name: undefined, input_name: undefined,
input_tag_name: undefined, input_tag_name: undefined,
input_fail_on_unmatched_files: false, input_fail_on_unmatched_files: false,

View file

@ -24,6 +24,10 @@ inputs:
files: files:
description: "Newline-delimited list of path globs for asset files to upload" description: "Newline-delimited list of path globs for asset files to upload"
required: false required: false
overwrite_files:
description: "Overwrite existing files with the same name. Defaults to false"
required: false
default: 'true'
fail_on_unmatched_files: fail_on_unmatched_files:
description: "Fails if any of the `files` globs match nothing. Defaults to false" description: "Fails if any of the `files` globs match nothing. Defaults to false"
required: false required: false

4
dist/index.js vendored

File diff suppressed because one or more lines are too long

View file

@ -149,12 +149,19 @@ export const upload = async (
({ name: currentName }) => currentName == name ({ name: currentName }) => currentName == name
); );
if (currentAsset) { if (currentAsset) {
console.log(`♻️ Deleting previously uploaded asset ${name}...`); if (config.input_overwrite_files === false) {
await github.rest.repos.deleteReleaseAsset({ console.log(
asset_id: currentAsset.id || 1, `Asset ${name} already exists and overwrite_files is false...`
owner, );
repo, return null;
}); } else {
console.log(`♻️ Deleting previously uploaded asset ${name}...`);
await github.rest.repos.deleteReleaseAsset({
asset_id: currentAsset.id || 1,
owner,
repo,
});
}
} }
console.log(`⬆️ Uploading ${name}...`); console.log(`⬆️ Uploading ${name}...`);
const endpoint = new URL(url); const endpoint = new URL(url);

View file

@ -67,17 +67,23 @@ async function run() {
} }
const currentAssets = rel.assets; const currentAssets = rel.assets;
const assets = await Promise.all( const assets = await Promise.all(
files.map(async (path) => { files
const json = await upload( .map(async (path) => {
config, const json = await upload(
gh, config,
uploadUrl(rel.upload_url), gh,
path, uploadUrl(rel.upload_url),
currentAssets path,
); currentAssets
delete json.uploader; );
return json;
}) if (json) {
delete json.uploader;
}
return json;
})
.filter((json) => json !== null)
).catch((error) => { ).catch((error) => {
throw error; throw error;
}); });

View file

@ -12,6 +12,7 @@ export interface Config {
input_body?: string; input_body?: string;
input_body_path?: string; input_body_path?: string;
input_files?: string[]; input_files?: string[];
input_overwrite_files?: boolean;
input_draft?: boolean; input_draft?: boolean;
input_prerelease?: boolean; input_prerelease?: boolean;
input_fail_on_unmatched_files?: boolean; input_fail_on_unmatched_files?: boolean;
@ -60,6 +61,9 @@ export const parseConfig = (env: Env): Config => {
input_body: env.INPUT_BODY, input_body: env.INPUT_BODY,
input_body_path: env.INPUT_BODY_PATH, input_body_path: env.INPUT_BODY_PATH,
input_files: parseInputFiles(env.INPUT_FILES || ""), input_files: parseInputFiles(env.INPUT_FILES || ""),
input_overwrite_files: env.INPUT_OVERWRITE_FILES
? env.INPUT_OVERWRITE_FILES == "true"
: undefined,
input_draft: env.INPUT_DRAFT ? env.INPUT_DRAFT === "true" : undefined, input_draft: env.INPUT_DRAFT ? env.INPUT_DRAFT === "true" : undefined,
input_prerelease: env.INPUT_PRERELEASE input_prerelease: env.INPUT_PRERELEASE
? env.INPUT_PRERELEASE == "true" ? env.INPUT_PRERELEASE == "true"