Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ The following are optional as `step.with` keys
| `prerelease` | Boolean | Indicator of whether or not is a prerelease |
| `preserve_order` | Boolean | Indicator of whether order of files should be preserved when uploading assets |
| `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_name` |
| `fail_on_unmatched_files` | Boolean | Indicator of whether to fail if any of the `files` globs match nothing |
Expand Down
12 changes: 12 additions & 0 deletions __tests__/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe("util", () => {
input_prerelease: false,
input_preserve_order: undefined,
input_files: [],
input_overwrite_files: undefined,
input_name: undefined,
input_tag_name: undefined,
input_target_commitish: undefined,
Expand All @@ -72,6 +73,7 @@ describe("util", () => {
input_prerelease: false,
input_preserve_order: undefined,
input_files: [],
input_overwrite_files: undefined,
input_name: undefined,
input_tag_name: undefined,
input_target_commitish: undefined,
Expand All @@ -94,6 +96,7 @@ describe("util", () => {
input_prerelease: false,
input_preserve_order: undefined,
input_files: [],
input_overwrite_files: undefined,
input_name: undefined,
input_tag_name: undefined,
input_target_commitish: undefined,
Expand Down Expand Up @@ -128,6 +131,7 @@ describe("util", () => {
input_prerelease: undefined,
input_preserve_order: undefined,
input_files: [],
input_overwrite_files: undefined,
input_name: undefined,
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
Expand All @@ -154,6 +158,7 @@ describe("util", () => {
input_draft: undefined,
input_prerelease: undefined,
input_files: [],
input_overwrite_files: undefined,
input_preserve_order: undefined,
input_name: undefined,
input_tag_name: undefined,
Expand Down Expand Up @@ -182,6 +187,7 @@ describe("util", () => {
input_files: [],
input_preserve_order: undefined,
input_name: undefined,
input_overwrite_files: undefined,
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: undefined,
Expand All @@ -208,6 +214,7 @@ describe("util", () => {
input_prerelease: undefined,
input_preserve_order: undefined,
input_files: [],
input_overwrite_files: undefined,
input_name: undefined,
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
Expand Down Expand Up @@ -239,6 +246,7 @@ describe("util", () => {
input_prerelease: true,
input_preserve_order: true,
input_files: [],
input_overwrite_files: undefined,
input_name: undefined,
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
Expand Down Expand Up @@ -267,6 +275,7 @@ describe("util", () => {
input_prerelease: true,
input_preserve_order: undefined,
input_files: [],
input_overwrite_files: undefined,
input_name: undefined,
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
Expand Down Expand Up @@ -294,6 +303,7 @@ describe("util", () => {
input_prerelease: true,
input_preserve_order: undefined,
input_files: [],
input_overwrite_files: undefined,
input_name: undefined,
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
Expand Down Expand Up @@ -321,6 +331,7 @@ describe("util", () => {
input_preserve_order: undefined,
input_files: [],
input_name: undefined,
input_overwrite_files: undefined,
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: undefined,
Expand All @@ -346,6 +357,7 @@ describe("util", () => {
input_prerelease: undefined,
input_preserve_order: 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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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 true"
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
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,19 @@ export const upload = async (
({ name: currentName }) => currentName == alignAssetName(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
24 changes: 14 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { setFailed, setOutput } from "@actions/core";
import { getOctokit } from "@actions/github";
import { GitHubReleaser, release, upload } from "./github";
import {
paths,
parseConfig,
isTag,
parseConfig,
paths,
unmatchedPatterns,
uploadUrl,
} from "./util";
import { release, upload, GitHubReleaser } from "./github";
import { getOctokit } from "@actions/github";
import { setFailed, setOutput } from "@actions/core";

import { env } from "process";

Expand Down Expand Up @@ -86,19 +86,23 @@ async function run() {
path,
currentAssets,
);
delete json.uploader;
if (json) {
delete json.uploader;
}
return json;
};

let assets;
let results: (any | null)[];
if (!config.input_preserve_order) {
assets = await Promise.all(files.map(uploadFile));
results = await Promise.all(files.map(uploadFile));
} else {
assets = [];
results = [];
for (const path of files) {
assets.push(await uploadFile(path));
results.push(await uploadFile(path));
}
}

const assets = results.filter(Boolean);
setOutput("assets", assets);
}
console.log(`🎉 Release ready at ${rel.html_url}`);
Expand Down
4 changes: 4 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
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_preserve_order?: boolean;
input_prerelease?: boolean;
Expand Down Expand Up @@ -62,6 +63,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_preserve_order: env.INPUT_PRESERVE_ORDER
? env.INPUT_PRESERVE_ORDER == "true"
Expand Down