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

feat: preserve upload order #500

Merged
merged 5 commits into from
Nov 11, 2024
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 @@ -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 @@ -46,6 +46,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 @@ -67,6 +68,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 @@ -88,6 +90,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 @@ -121,6 +124,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 @@ -148,6 +152,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 @@ -173,6 +178,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 @@ -198,6 +204,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 @@ -215,6 +222,7 @@ describe("util", () => {
parseConfig({
INPUT_DRAFT: "false",
INPUT_PRERELEASE: "true",
INPUT_PRESERVE_ORDER: "true",
GITHUB_TOKEN: "env-token",
INPUT_TOKEN: "input-token",
}),
Expand All @@ -227,6 +235,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 @@ -254,6 +263,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 @@ -280,6 +290,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 @@ -305,6 +316,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 @@ -330,6 +342,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