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
This commit is contained in:
parent
b019a5bbb6
commit
98daca21d1
@ -6,6 +6,7 @@ import {
|
|||||||
parseInputFiles,
|
parseInputFiles,
|
||||||
unmatchedPatterns,
|
unmatchedPatterns,
|
||||||
uploadUrl,
|
uploadUrl,
|
||||||
|
alignAssetName,
|
||||||
} from "../src/util";
|
} from "../src/util";
|
||||||
import * as assert from "assert";
|
import * as assert from "assert";
|
||||||
|
|
||||||
@ -368,4 +369,20 @@ describe("util", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("replaceSpacesWithDots", () => {
|
||||||
|
it("replaces all spaces with dots", () => {
|
||||||
|
expect(alignAssetName("John Doe.bla")).toBe("John.Doe.bla");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("handles names with multiple spaces", () => {
|
||||||
|
expect(alignAssetName("John William Doe.bla")).toBe(
|
||||||
|
"John.William.Doe.bla",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns the same string if there are no spaces", () => {
|
||||||
|
expect(alignAssetName("JohnDoe")).toBe("JohnDoe");
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { GitHub } from "@actions/github/lib/utils";
|
import { GitHub } from "@actions/github/lib/utils";
|
||||||
import { Config, isTag, releaseBody } from "./util";
|
import { Config, isTag, releaseBody, alignAssetName } from "./util";
|
||||||
import { statSync, readFileSync } from "fs";
|
import { statSync, readFileSync } from "fs";
|
||||||
import { getType } from "mime";
|
import { getType } from "mime";
|
||||||
import { basename } from "path";
|
import { basename } from "path";
|
||||||
@ -166,7 +166,7 @@ export const upload = async (
|
|||||||
// 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.
|
// 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.
|
||||||
// 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
|
// 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
|
||||||
// see https://docs.github.com/en/rest/releases/assets?apiVersion=2022-11-28#upload-a-release-asset
|
// see https://docs.github.com/en/rest/releases/assets?apiVersion=2022-11-28#upload-a-release-asset
|
||||||
({ name: currentName }) => currentName == name.replace(" ", "."),
|
({ name: currentName }) => currentName == alignAssetName(name),
|
||||||
);
|
);
|
||||||
if (currentAsset) {
|
if (currentAsset) {
|
||||||
console.log(`♻️ Deleting previously uploaded asset ${name}...`);
|
console.log(`♻️ Deleting previously uploaded asset ${name}...`);
|
||||||
|
@ -105,3 +105,7 @@ export const unmatchedPatterns = (patterns: string[]): string[] => {
|
|||||||
export const isTag = (ref: string): boolean => {
|
export const isTag = (ref: string): boolean => {
|
||||||
return ref.startsWith("refs/tags/");
|
return ref.startsWith("refs/tags/");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const alignAssetName = (assetName: string): string => {
|
||||||
|
return assetName.replace(/ /g, ".");
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user