mirror of
https://github.com/softprops/action-gh-release.git
synced 2025-05-10 18:44:19 +00:00
Add input option overwrite_files.
This commit is contained in:
parent
c9b46fe7aa
commit
40ca4763d5
7 changed files with 52 additions and 19 deletions
|
@ -174,6 +174,7 @@ The following are optional as `step.with` keys
|
|||
| `draft` | Boolean | Indicator of whether or not this release is a draft |
|
||||
| `prerelease` | Boolean | Indicator of whether or not is a prerelease |
|
||||
| `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 |
|
||||
| `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 |
|
||||
|
|
|
@ -47,6 +47,7 @@ describe("util", () => {
|
|||
input_draft: false,
|
||||
input_prerelease: false,
|
||||
input_files: [],
|
||||
input_overwrite_files: undefined,
|
||||
input_name: undefined,
|
||||
input_tag_name: undefined,
|
||||
input_target_commitish: undefined,
|
||||
|
@ -67,6 +68,7 @@ describe("util", () => {
|
|||
input_draft: false,
|
||||
input_prerelease: false,
|
||||
input_files: [],
|
||||
input_overwrite_files: undefined,
|
||||
input_name: undefined,
|
||||
input_tag_name: undefined,
|
||||
input_target_commitish: undefined,
|
||||
|
@ -87,6 +89,7 @@ describe("util", () => {
|
|||
input_draft: false,
|
||||
input_prerelease: false,
|
||||
input_files: [],
|
||||
input_overwrite_files: undefined,
|
||||
input_name: undefined,
|
||||
input_tag_name: undefined,
|
||||
input_target_commitish: undefined,
|
||||
|
@ -119,6 +122,7 @@ describe("util", () => {
|
|||
input_draft: undefined,
|
||||
input_prerelease: undefined,
|
||||
input_files: [],
|
||||
input_overwrite_files: undefined,
|
||||
input_name: undefined,
|
||||
input_tag_name: undefined,
|
||||
input_fail_on_unmatched_files: false,
|
||||
|
@ -144,6 +148,7 @@ describe("util", () => {
|
|||
input_draft: undefined,
|
||||
input_prerelease: undefined,
|
||||
input_files: [],
|
||||
input_overwrite_files: undefined,
|
||||
input_name: undefined,
|
||||
input_tag_name: undefined,
|
||||
input_fail_on_unmatched_files: false,
|
||||
|
@ -168,6 +173,7 @@ describe("util", () => {
|
|||
input_draft: undefined,
|
||||
input_prerelease: undefined,
|
||||
input_files: [],
|
||||
input_overwrite_files: undefined,
|
||||
input_name: undefined,
|
||||
input_tag_name: undefined,
|
||||
input_fail_on_unmatched_files: false,
|
||||
|
@ -193,6 +199,7 @@ describe("util", () => {
|
|||
input_draft: undefined,
|
||||
input_prerelease: undefined,
|
||||
input_files: [],
|
||||
input_overwrite_files: undefined,
|
||||
input_name: undefined,
|
||||
input_tag_name: undefined,
|
||||
input_fail_on_unmatched_files: false,
|
||||
|
@ -221,6 +228,7 @@ describe("util", () => {
|
|||
input_draft: false,
|
||||
input_prerelease: true,
|
||||
input_files: [],
|
||||
input_overwrite_files: undefined,
|
||||
input_name: undefined,
|
||||
input_tag_name: undefined,
|
||||
input_fail_on_unmatched_files: false,
|
||||
|
@ -247,6 +255,7 @@ describe("util", () => {
|
|||
input_draft: false,
|
||||
input_prerelease: true,
|
||||
input_files: [],
|
||||
input_overwrite_files: undefined,
|
||||
input_name: undefined,
|
||||
input_tag_name: undefined,
|
||||
input_fail_on_unmatched_files: false,
|
||||
|
@ -272,6 +281,7 @@ describe("util", () => {
|
|||
input_draft: false,
|
||||
input_prerelease: true,
|
||||
input_files: [],
|
||||
input_overwrite_files: undefined,
|
||||
input_name: undefined,
|
||||
input_tag_name: undefined,
|
||||
input_fail_on_unmatched_files: false,
|
||||
|
@ -296,6 +306,7 @@ describe("util", () => {
|
|||
input_draft: undefined,
|
||||
input_prerelease: undefined,
|
||||
input_files: [],
|
||||
input_overwrite_files: undefined,
|
||||
input_name: undefined,
|
||||
input_tag_name: undefined,
|
||||
input_fail_on_unmatched_files: false,
|
||||
|
|
|
@ -24,6 +24,10 @@ inputs:
|
|||
files:
|
||||
description: "Newline-delimited list of path globs for asset files to upload"
|
||||
required: false
|
||||
overwrite_files:
|
||||
description: "Overwrite existing files with the same name. Defaults to false"
|
||||
required: false
|
||||
default: 'true'
|
||||
fail_on_unmatched_files:
|
||||
description: "Fails if any of the `files` globs match nothing. Defaults to false"
|
||||
required: false
|
||||
|
|
4
dist/index.js
vendored
4
dist/index.js
vendored
File diff suppressed because one or more lines are too long
|
@ -149,12 +149,19 @@ export const upload = async (
|
|||
({ name: currentName }) => currentName == name
|
||||
);
|
||||
if (currentAsset) {
|
||||
console.log(`♻️ Deleting previously uploaded asset ${name}...`);
|
||||
await github.rest.repos.deleteReleaseAsset({
|
||||
asset_id: currentAsset.id || 1,
|
||||
owner,
|
||||
repo,
|
||||
});
|
||||
if (config.input_overwrite_files === false) {
|
||||
console.log(
|
||||
`Asset ${name} already exists and overwrite_files is false...`
|
||||
);
|
||||
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}...`);
|
||||
const endpoint = new URL(url);
|
||||
|
|
28
src/main.ts
28
src/main.ts
|
@ -67,17 +67,23 @@ async function run() {
|
|||
}
|
||||
const currentAssets = rel.assets;
|
||||
const assets = await Promise.all(
|
||||
files.map(async (path) => {
|
||||
const json = await upload(
|
||||
config,
|
||||
gh,
|
||||
uploadUrl(rel.upload_url),
|
||||
path,
|
||||
currentAssets
|
||||
);
|
||||
delete json.uploader;
|
||||
return json;
|
||||
})
|
||||
files
|
||||
.map(async (path) => {
|
||||
const json = await upload(
|
||||
config,
|
||||
gh,
|
||||
uploadUrl(rel.upload_url),
|
||||
path,
|
||||
currentAssets
|
||||
);
|
||||
|
||||
if (json) {
|
||||
delete json.uploader;
|
||||
}
|
||||
|
||||
return json;
|
||||
})
|
||||
.filter((json) => json !== null)
|
||||
).catch((error) => {
|
||||
throw error;
|
||||
});
|
||||
|
|
|
@ -12,6 +12,7 @@ export interface Config {
|
|||
input_body?: string;
|
||||
input_body_path?: string;
|
||||
input_files?: string[];
|
||||
input_overwrite_files?: boolean;
|
||||
input_draft?: boolean;
|
||||
input_prerelease?: boolean;
|
||||
input_fail_on_unmatched_files?: boolean;
|
||||
|
@ -60,6 +61,9 @@ export const parseConfig = (env: Env): Config => {
|
|||
input_body: env.INPUT_BODY,
|
||||
input_body_path: env.INPUT_BODY_PATH,
|
||||
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_prerelease: env.INPUT_PRERELEASE
|
||||
? env.INPUT_PRERELEASE == "true"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue