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
5 changes: 5 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { FormatKind } from "./util/variant.ts";

export interface IContext {
output?: string;

// For an unknown reason, this one particular arg is coming through as 'c' instead of 'config'
// All of the other options are coming through as their full names.
// Therefore, we need to support both 'c' and 'config' for now.
c?: string;
config?: string;
githubDir: string;
hooks: {
Expand Down
94 changes: 70 additions & 24 deletions src/hooks/post.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parse } from "../../deps/semver.ts";
import { resolvesNext, stub } from "../../deps/std.ts";
import { assertEquals, resolvesNext, stub } from "../../deps/std.ts";
import { YAML } from "../../deps/yaml.ts";
import { IContext } from "../context.ts";
import { postVersionHook } from "./post.ts";
Expand All @@ -13,27 +13,73 @@ Deno.test("yml or yaml", async () => {
regexp: async () => await undefined,
},
};
stub(
Deno,
"stat",
resolvesNext<Deno.FileInfo>([
Object.assign(new Deno.errors.NotFound("not found")), // version.yml, nah
{
isFile: true,
} as Deno.FileInfo, // version.yaml, yah
]),
);
stub(
Deno,
"readTextFile",
resolvesNext([
"1.0.0",
YAML.stringify({
on: { post: [{ kind: "patch", file: "test/example.csproj" }] },
}),
]),
);
stub(context.hooks, "patch");
stub(context.hooks, "replace");
await postVersionHook(context, parse("1.0.0"), parse("1.2.3"));
const stubs = [
stub(
Deno,
"stat",
resolvesNext<Deno.FileInfo>([
Object.assign(new Deno.errors.NotFound("not found")), // version.yml, nah
{
isFile: true,
} as Deno.FileInfo, // version.yaml, yah
]),
),
stub(
Deno,
"readTextFile",
resolvesNext([
"1.0.0",
YAML.stringify({
on: { post: [{ kind: "patch", file: "test/example.csproj" }] },
}),
]),
),
stub(context.hooks, "patch"),
stub(context.hooks, "replace"),
];
try {
await postVersionHook(context, parse("1.0.0"), parse("1.2.3"));
} finally {
stubs.forEach((s) => s.restore());
}
});

Deno.test("custom config", async () => {
const context: IContext = {
config: ".github/version-test.yml",
githubDir: ".github",
hooks: {
patch: async () => await undefined,
replace: async () => await undefined,
regexp: async () => await undefined,
},
};
let configPath: string | URL = "";
const stubs = [
stub(
Deno,
"stat",
resolvesNext<Deno.FileInfo>([
{ isFile: true } as Deno.FileInfo,
]),
),
stub(
Deno,
"readTextFile",
async (path, _opts) => {
configPath = path;
return await YAML.stringify({
on: { post: [] },
});
},
),
stub(context.hooks, "patch"),
stub(context.hooks, "replace"),
];
try {
await postVersionHook(context, parse("1.0.0"), parse("1.2.3"));
assertEquals(configPath, ".github/version-test.yml");
} finally {
stubs.forEach((s) => s.restore());
}
});
5 changes: 3 additions & 2 deletions src/hooks/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ export async function postVersionHook(
}

async function getVersionConfig(context: IContext) {
const { config, githubDir } = context;
const paths = config ? [config] : [
const { c: configShorthand, config, githubDir } = context;
const configPath = config ?? configShorthand;
const paths = configPath ? [configPath] : [
[githubDir, "version.yml"].filter((p) => p).join("/"),
[githubDir, "version.yaml"].filter((p) => p).join("/"),
];
Expand Down
2 changes: 2 additions & 0 deletions test/node/.github/version-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
on:
post: []
Loading