Skip to content

Commit 98daca2

Browse files
authored
feat: add support for release assets with multiple spaces within the name (#518)
* extracted the asset name alignment to utils, added unit tests * fixed formatting issues
1 parent b019a5b commit 98daca2

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

__tests__/util.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
parseInputFiles,
77
unmatchedPatterns,
88
uploadUrl,
9+
alignAssetName,
910
} from "../src/util";
1011
import * as assert from "assert";
1112

@@ -368,4 +369,20 @@ describe("util", () => {
368369
);
369370
});
370371
});
372+
373+
describe("replaceSpacesWithDots", () => {
374+
it("replaces all spaces with dots", () => {
375+
expect(alignAssetName("John Doe.bla")).toBe("John.Doe.bla");
376+
});
377+
378+
it("handles names with multiple spaces", () => {
379+
expect(alignAssetName("John William Doe.bla")).toBe(
380+
"John.William.Doe.bla",
381+
);
382+
});
383+
384+
it("returns the same string if there are no spaces", () => {
385+
expect(alignAssetName("JohnDoe")).toBe("JohnDoe");
386+
});
387+
});
371388
});

src/github.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { GitHub } from "@actions/github/lib/utils";
2-
import { Config, isTag, releaseBody } from "./util";
2+
import { Config, isTag, releaseBody, alignAssetName } from "./util";
33
import { statSync, readFileSync } from "fs";
44
import { getType } from "mime";
55
import { basename } from "path";
@@ -166,7 +166,7 @@ export const upload = async (
166166
// note: GitHub renames asset filenames that have special characters, non-alphanumeric characters, and leading or trailing periods. The "List release assets" endpoint lists the renamed filenames.
167167
// due to this renaming we need to be mindful when we compare the file name we're uploading with a name github may already have rewritten for logical comparison
168168
// see https://docs.github.com/en/rest/releases/assets?apiVersion=2022-11-28#upload-a-release-asset
169-
({ name: currentName }) => currentName == name.replace(" ", "."),
169+
({ name: currentName }) => currentName == alignAssetName(name),
170170
);
171171
if (currentAsset) {
172172
console.log(`♻️ Deleting previously uploaded asset ${name}...`);

src/util.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,7 @@ export const unmatchedPatterns = (patterns: string[]): string[] => {
105105
export const isTag = (ref: string): boolean => {
106106
return ref.startsWith("refs/tags/");
107107
};
108+
109+
export const alignAssetName = (assetName: string): string => {
110+
return assetName.replace(/ /g, ".");
111+
};

0 commit comments

Comments
 (0)