feature: preserve upload order (#500)
* Preserve upload order * Update README.md * Fix typings and add a test * fmt code Signed-off-by: Rui Chen <rui@chenrui.dev> --------- Signed-off-by: Rui Chen <rui@chenrui.dev> Co-authored-by: Richard Davison <ridaviso@amazon.com> Co-authored-by: Rui Chen <rui@chenrui.dev>
This commit is contained in:
parent
98daca21d1
commit
d5f028c822
@ -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 |
|
| `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 |
|
| `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 |
|
||||||
|
| `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 |
|
| `files` | String | Newline-delimited globs of paths to assets to upload for release |
|
||||||
| `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` |
|
||||||
|
@ -47,6 +47,7 @@ describe("util", () => {
|
|||||||
input_body_path: undefined,
|
input_body_path: undefined,
|
||||||
input_draft: false,
|
input_draft: false,
|
||||||
input_prerelease: false,
|
input_prerelease: false,
|
||||||
|
input_preserve_order: undefined,
|
||||||
input_files: [],
|
input_files: [],
|
||||||
input_name: undefined,
|
input_name: undefined,
|
||||||
input_tag_name: undefined,
|
input_tag_name: undefined,
|
||||||
@ -68,6 +69,7 @@ describe("util", () => {
|
|||||||
input_body_path: "__tests__/release.txt",
|
input_body_path: "__tests__/release.txt",
|
||||||
input_draft: false,
|
input_draft: false,
|
||||||
input_prerelease: false,
|
input_prerelease: false,
|
||||||
|
input_preserve_order: undefined,
|
||||||
input_files: [],
|
input_files: [],
|
||||||
input_name: undefined,
|
input_name: undefined,
|
||||||
input_tag_name: undefined,
|
input_tag_name: undefined,
|
||||||
@ -89,6 +91,7 @@ describe("util", () => {
|
|||||||
input_body_path: "__tests__/release.txt",
|
input_body_path: "__tests__/release.txt",
|
||||||
input_draft: false,
|
input_draft: false,
|
||||||
input_prerelease: false,
|
input_prerelease: false,
|
||||||
|
input_preserve_order: undefined,
|
||||||
input_files: [],
|
input_files: [],
|
||||||
input_name: undefined,
|
input_name: undefined,
|
||||||
input_tag_name: undefined,
|
input_tag_name: undefined,
|
||||||
@ -122,6 +125,7 @@ describe("util", () => {
|
|||||||
input_body_path: undefined,
|
input_body_path: undefined,
|
||||||
input_draft: undefined,
|
input_draft: undefined,
|
||||||
input_prerelease: undefined,
|
input_prerelease: undefined,
|
||||||
|
input_preserve_order: undefined,
|
||||||
input_files: [],
|
input_files: [],
|
||||||
input_name: undefined,
|
input_name: undefined,
|
||||||
input_tag_name: undefined,
|
input_tag_name: undefined,
|
||||||
@ -149,6 +153,7 @@ describe("util", () => {
|
|||||||
input_draft: undefined,
|
input_draft: undefined,
|
||||||
input_prerelease: undefined,
|
input_prerelease: undefined,
|
||||||
input_files: [],
|
input_files: [],
|
||||||
|
input_preserve_order: 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,
|
||||||
@ -174,6 +179,7 @@ describe("util", () => {
|
|||||||
input_draft: undefined,
|
input_draft: undefined,
|
||||||
input_prerelease: undefined,
|
input_prerelease: undefined,
|
||||||
input_files: [],
|
input_files: [],
|
||||||
|
input_preserve_order: 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,
|
||||||
@ -199,6 +205,7 @@ describe("util", () => {
|
|||||||
input_body_path: undefined,
|
input_body_path: undefined,
|
||||||
input_draft: undefined,
|
input_draft: undefined,
|
||||||
input_prerelease: undefined,
|
input_prerelease: undefined,
|
||||||
|
input_preserve_order: undefined,
|
||||||
input_files: [],
|
input_files: [],
|
||||||
input_name: undefined,
|
input_name: undefined,
|
||||||
input_tag_name: undefined,
|
input_tag_name: undefined,
|
||||||
@ -216,6 +223,7 @@ describe("util", () => {
|
|||||||
parseConfig({
|
parseConfig({
|
||||||
INPUT_DRAFT: "false",
|
INPUT_DRAFT: "false",
|
||||||
INPUT_PRERELEASE: "true",
|
INPUT_PRERELEASE: "true",
|
||||||
|
INPUT_PRESERVE_ORDER: "true",
|
||||||
GITHUB_TOKEN: "env-token",
|
GITHUB_TOKEN: "env-token",
|
||||||
INPUT_TOKEN: "input-token",
|
INPUT_TOKEN: "input-token",
|
||||||
}),
|
}),
|
||||||
@ -228,6 +236,7 @@ describe("util", () => {
|
|||||||
input_body_path: undefined,
|
input_body_path: undefined,
|
||||||
input_draft: false,
|
input_draft: false,
|
||||||
input_prerelease: true,
|
input_prerelease: true,
|
||||||
|
input_preserve_order: true,
|
||||||
input_files: [],
|
input_files: [],
|
||||||
input_name: undefined,
|
input_name: undefined,
|
||||||
input_tag_name: undefined,
|
input_tag_name: undefined,
|
||||||
@ -255,6 +264,7 @@ describe("util", () => {
|
|||||||
input_body_path: undefined,
|
input_body_path: undefined,
|
||||||
input_draft: false,
|
input_draft: false,
|
||||||
input_prerelease: true,
|
input_prerelease: true,
|
||||||
|
input_preserve_order: undefined,
|
||||||
input_files: [],
|
input_files: [],
|
||||||
input_name: undefined,
|
input_name: undefined,
|
||||||
input_tag_name: undefined,
|
input_tag_name: undefined,
|
||||||
@ -281,6 +291,7 @@ describe("util", () => {
|
|||||||
input_body_path: undefined,
|
input_body_path: undefined,
|
||||||
input_draft: false,
|
input_draft: false,
|
||||||
input_prerelease: true,
|
input_prerelease: true,
|
||||||
|
input_preserve_order: undefined,
|
||||||
input_files: [],
|
input_files: [],
|
||||||
input_name: undefined,
|
input_name: undefined,
|
||||||
input_tag_name: undefined,
|
input_tag_name: undefined,
|
||||||
@ -306,6 +317,7 @@ describe("util", () => {
|
|||||||
input_body_path: undefined,
|
input_body_path: undefined,
|
||||||
input_draft: undefined,
|
input_draft: undefined,
|
||||||
input_prerelease: undefined,
|
input_prerelease: undefined,
|
||||||
|
input_preserve_order: undefined,
|
||||||
input_files: [],
|
input_files: [],
|
||||||
input_name: undefined,
|
input_name: undefined,
|
||||||
input_tag_name: undefined,
|
input_tag_name: undefined,
|
||||||
@ -331,6 +343,7 @@ describe("util", () => {
|
|||||||
input_body_path: undefined,
|
input_body_path: undefined,
|
||||||
input_draft: undefined,
|
input_draft: undefined,
|
||||||
input_prerelease: undefined,
|
input_prerelease: undefined,
|
||||||
|
input_preserve_order: undefined,
|
||||||
input_files: [],
|
input_files: [],
|
||||||
input_name: undefined,
|
input_name: undefined,
|
||||||
input_tag_name: undefined,
|
input_tag_name: undefined,
|
||||||
|
@ -21,6 +21,9 @@ inputs:
|
|||||||
prerelease:
|
prerelease:
|
||||||
description: "Identify the release as a prerelease. Defaults to false"
|
description: "Identify the release as a prerelease. Defaults to false"
|
||||||
required: false
|
required: false
|
||||||
|
preserve_order:
|
||||||
|
description: "Preserver the order of the artifacts when uploading"
|
||||||
|
required: false
|
||||||
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
|
||||||
|
37
src/main.ts
37
src/main.ts
@ -73,21 +73,28 @@ async function run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const currentAssets = rel.assets;
|
const currentAssets = rel.assets;
|
||||||
const assets = await Promise.all(
|
|
||||||
files.map(async (path) => {
|
const uploadFile = async (path) => {
|
||||||
const json = await upload(
|
const json = await upload(
|
||||||
config,
|
config,
|
||||||
gh,
|
gh,
|
||||||
uploadUrl(rel.upload_url),
|
uploadUrl(rel.upload_url),
|
||||||
path,
|
path,
|
||||||
currentAssets,
|
currentAssets,
|
||||||
);
|
);
|
||||||
delete json.uploader;
|
delete json.uploader;
|
||||||
return json;
|
return json;
|
||||||
}),
|
};
|
||||||
).catch((error) => {
|
|
||||||
throw error;
|
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);
|
setOutput("assets", assets);
|
||||||
}
|
}
|
||||||
console.log(`🎉 Release ready at ${rel.html_url}`);
|
console.log(`🎉 Release ready at ${rel.html_url}`);
|
||||||
|
@ -13,6 +13,7 @@ export interface Config {
|
|||||||
input_body_path?: string;
|
input_body_path?: string;
|
||||||
input_files?: string[];
|
input_files?: string[];
|
||||||
input_draft?: boolean;
|
input_draft?: boolean;
|
||||||
|
input_preserve_order?: boolean;
|
||||||
input_prerelease?: boolean;
|
input_prerelease?: boolean;
|
||||||
input_fail_on_unmatched_files?: boolean;
|
input_fail_on_unmatched_files?: boolean;
|
||||||
input_target_commitish?: string;
|
input_target_commitish?: string;
|
||||||
@ -62,6 +63,9 @@ export const parseConfig = (env: Env): Config => {
|
|||||||
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_draft: env.INPUT_DRAFT ? env.INPUT_DRAFT === "true" : undefined,
|
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
|
input_prerelease: env.INPUT_PRERELEASE
|
||||||
? env.INPUT_PRERELEASE == "true"
|
? env.INPUT_PRERELEASE == "true"
|
||||||
: undefined,
|
: undefined,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user