diff --git a/README.md b/README.md index 17e6e9190..e854a2fb1 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,7 @@ The following are optional as `step.with` keys | `body_path` | String | Path to load text communicating notable changes in this release | | `draft` | Boolean | Indicator of whether or not this release is a draft | | `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 | | `name` | String | Name of the release. defaults to tag name | | `tag_name` | String | Name of a tag. defaults to `github.ref` | diff --git a/__tests__/util.test.ts b/__tests__/util.test.ts index 9f7ffdf20..bc1dfc383 100644 --- a/__tests__/util.test.ts +++ b/__tests__/util.test.ts @@ -47,6 +47,7 @@ describe("util", () => { input_body_path: undefined, input_draft: false, input_prerelease: false, + input_preserve_order: undefined, input_files: [], input_name: undefined, input_tag_name: undefined, @@ -68,6 +69,7 @@ describe("util", () => { input_body_path: "__tests__/release.txt", input_draft: false, input_prerelease: false, + input_preserve_order: undefined, input_files: [], input_name: undefined, input_tag_name: undefined, @@ -89,6 +91,7 @@ describe("util", () => { input_body_path: "__tests__/release.txt", input_draft: false, input_prerelease: false, + input_preserve_order: undefined, input_files: [], input_name: undefined, input_tag_name: undefined, @@ -122,6 +125,7 @@ describe("util", () => { input_body_path: undefined, input_draft: undefined, input_prerelease: undefined, + input_preserve_order: undefined, input_files: [], input_name: undefined, input_tag_name: undefined, @@ -149,6 +153,7 @@ describe("util", () => { input_draft: undefined, input_prerelease: undefined, input_files: [], + input_preserve_order: undefined, input_name: undefined, input_tag_name: undefined, input_fail_on_unmatched_files: false, @@ -174,6 +179,7 @@ describe("util", () => { input_draft: undefined, input_prerelease: undefined, input_files: [], + input_preserve_order: undefined, input_name: undefined, input_tag_name: undefined, input_fail_on_unmatched_files: false, @@ -199,6 +205,7 @@ describe("util", () => { input_body_path: undefined, input_draft: undefined, input_prerelease: undefined, + input_preserve_order: undefined, input_files: [], input_name: undefined, input_tag_name: undefined, @@ -216,6 +223,7 @@ describe("util", () => { parseConfig({ INPUT_DRAFT: "false", INPUT_PRERELEASE: "true", + INPUT_PRESERVE_ORDER: "true", GITHUB_TOKEN: "env-token", INPUT_TOKEN: "input-token", }), @@ -228,6 +236,7 @@ describe("util", () => { input_body_path: undefined, input_draft: false, input_prerelease: true, + input_preserve_order: true, input_files: [], input_name: undefined, input_tag_name: undefined, @@ -255,6 +264,7 @@ describe("util", () => { input_body_path: undefined, input_draft: false, input_prerelease: true, + input_preserve_order: undefined, input_files: [], input_name: undefined, input_tag_name: undefined, @@ -281,6 +291,7 @@ describe("util", () => { input_body_path: undefined, input_draft: false, input_prerelease: true, + input_preserve_order: undefined, input_files: [], input_name: undefined, input_tag_name: undefined, @@ -306,6 +317,7 @@ describe("util", () => { input_body_path: undefined, input_draft: undefined, input_prerelease: undefined, + input_preserve_order: undefined, input_files: [], input_name: undefined, input_tag_name: undefined, @@ -331,6 +343,7 @@ describe("util", () => { input_body_path: undefined, input_draft: undefined, input_prerelease: undefined, + input_preserve_order: undefined, input_files: [], input_name: undefined, input_tag_name: undefined, diff --git a/action.yml b/action.yml index 580a57e32..f9b520627 100644 --- a/action.yml +++ b/action.yml @@ -21,6 +21,9 @@ inputs: prerelease: description: "Identify the release as a prerelease. Defaults to false" required: false + preserve_order: + description: "Preserver the order of the artifacts when uploading" + required: false files: description: "Newline-delimited list of path globs for asset files to upload" required: false diff --git a/src/main.ts b/src/main.ts index 9c2b720ef..2168f13b4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -73,21 +73,28 @@ 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; - }), - ).catch((error) => { - throw error; - }); + + const uploadFile = async (path) => { + const json = await upload( + config, + gh, + uploadUrl(rel.upload_url), + path, + currentAssets, + ); + delete json.uploader; + return json; + }; + + let assets; + if (!config.input_preserve_order) { + assets = await Promise.all(files.map(uploadFile)); + } else { + assets = []; + for (const path of files) { + assets.push(await uploadFile(path)); + } + } setOutput("assets", assets); } console.log(`🎉 Release ready at ${rel.html_url}`); diff --git a/src/util.ts b/src/util.ts index b2018286a..20d5c2df1 100644 --- a/src/util.ts +++ b/src/util.ts @@ -13,6 +13,7 @@ export interface Config { input_body_path?: string; input_files?: string[]; input_draft?: boolean; + input_preserve_order?: boolean; input_prerelease?: boolean; input_fail_on_unmatched_files?: boolean; input_target_commitish?: string; @@ -62,6 +63,9 @@ export const parseConfig = (env: Env): Config => { input_body_path: env.INPUT_BODY_PATH, input_files: parseInputFiles(env.INPUT_FILES || ""), input_draft: env.INPUT_DRAFT ? env.INPUT_DRAFT === "true" : undefined, + input_preserve_order: env.INPUT_PRESERVE_ORDER + ? env.INPUT_PRESERVE_ORDER == "true" + : undefined, input_prerelease: env.INPUT_PRERELEASE ? env.INPUT_PRERELEASE == "true" : undefined,