Skip to content

Commit

Permalink
feature: preserve upload order (#500)
Browse files Browse the repository at this point in the history
* Preserve upload order

* Update README.md

* Fix typings and add a test

* fmt code

Signed-off-by: Rui Chen <[email protected]>

---------

Signed-off-by: Rui Chen <[email protected]>
Co-authored-by: Richard Davison <[email protected]>
Co-authored-by: Rui Chen <[email protected]>
  • Loading branch information
3 people authored Nov 11, 2024
1 parent 98daca2 commit d5f028c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
13 changes: 13 additions & 0 deletions __tests__/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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",
}),
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 22 additions & 15 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
4 changes: 4 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d5f028c

Please sign in to comment.