Skip to content
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
4,571 changes: 2,195 additions & 2,376 deletions dist/main.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/main.js.map

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"ajv": "^8.20.0",
"compare-versions": "^6.1.1",
"github-slugger": "^2.0.0",
"js-yaml": "^4.2.0",
"js-yaml": "^5.0.0",
"mdast-util-gfm": "^3.1.0",
"mdast-util-to-markdown": "^2.1.2",
"mdast-util-to-string": "^4.0.0",
Expand Down
16 changes: 7 additions & 9 deletions src/config/reading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ export async function readConfig({
return group("Reading release configuration", async () => {
const yaml = await readConfigFile();

let base: Config;

if (typeof yaml === "undefined") {
info("No configuration found at .github/github-release-from-tag.yml");
base = validateConfig({});
} else {
base = parseConfig(yaml);
}

const base = parseConfig(yaml);
const overrides = getConfigOverrides(getInput, base);
let checksum: ChecksumConfig,
discussion: DiscussionConfig,
Expand Down Expand Up @@ -136,13 +140,9 @@ function getConfigOverrides(
return Object.keys(overrides).length > 0 ? overrides : undefined;
}

function parseConfig(yaml: string | undefined): Config {
if (!yaml) return validateConfig({});

let parsed;

function parseConfig(yaml: string): Config {
try {
parsed = load(yaml);
return validateConfig(load(yaml));
} catch (error) {
const message = isError(error)
? JSON.stringify(error.message)
Expand All @@ -153,8 +153,6 @@ function parseConfig(yaml: string | undefined): Config {
`Parsing of release configuration failed with ${message}. Provided value: ${original}`,
);
}

return validateConfig(parsed == null ? {} : parsed);
}

function parseAssets(getInput: GetInputFn): AssetConfig[] {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# yaml-language-server: $schema=https://ghalactic.github.io/github-release-from-tag/schema/config.v6.schema.json
{}
37 changes: 10 additions & 27 deletions test/suite/unit/read-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ describe("readConfig()", () => {
expect(actual).toEqual(expected);
});

it("returns a default config the config file is empty", async () => {
chdir(join(fixturesPath, "empty"));
it("returns a default config when no config file exists", async () => {
chdir(join(fixturesPath, "none"));
const actual = await readConfig({ getInput, group, info });

const expected = {
Expand All @@ -109,29 +109,12 @@ describe("readConfig()", () => {
expect(actual).toEqual(expected);
});

it("returns a default config when no config file exists", async () => {
chdir(join(fixturesPath, "none"));
const actual = await readConfig({ getInput, group, info });

const expected = {
assets: [],
checksum: {
generateAssets: true,
},
discussion: {
category: "",
reactions: [],
},
draft: false,
generateReleaseNotes: false,
makeLatest: IF_NEW,
reactions: [],
summary: {
enabled: true,
},
};
it("throws when the config file is empty", async () => {
chdir(join(fixturesPath, "empty"));

expect(actual).toEqual(expected);
await expect(() => readConfig({ getInput, group, info })).rejects.toThrow(
"Parsing of release configuration failed",
);
});

it("throws an error if the config file contains invalid YAML", async () => {
Expand Down Expand Up @@ -194,7 +177,7 @@ describe("readConfig()", () => {
});

it("fills in checksum defaults when using action input overrides", async () => {
chdir(join(fixturesPath, "empty"));
chdir(join(fixturesPath, "empty-object"));

const getInput = (name: string) =>
name === "checksumGenerateAssets" ? "false" : "";
Expand All @@ -210,7 +193,7 @@ describe("readConfig()", () => {
});

it("fills in discussions defaults when using action input overrides", async () => {
chdir(join(fixturesPath, "empty"));
chdir(join(fixturesPath, "empty-object"));

const getInput = (name: string) =>
name === "discussionReactions" ? "eyes,+1" : "";
Expand All @@ -227,7 +210,7 @@ describe("readConfig()", () => {
});

it("fills in summary defaults when using action input overrides", async () => {
chdir(join(fixturesPath, "empty"));
chdir(join(fixturesPath, "empty-object"));

const getInput = (name: string) =>
name === "summaryEnabled" ? "false" : "";
Expand Down