Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add input option overwrite_files. #343

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -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 |
Expand Down
11 changes: 11 additions & 0 deletions __tests__/util.test.ts
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

19 changes: 13 additions & 6 deletions src/github.ts
Expand Up @@ -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);
Expand Down
28 changes: 17 additions & 11 deletions src/main.ts
Expand Up @@ -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;
});
Expand Down
4 changes: 4 additions & 0 deletions src/util.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -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"
Expand Down