Skip to content

Commit

Permalink
Make strict typing
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick committed Jun 7, 2024
1 parent 3c54f6c commit e66e1df
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 42 deletions.
44 changes: 27 additions & 17 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31063,23 +31063,33 @@ function getDuration(durationable) {
}
throw new Error("unexpected value is specified in durations");
}
var FilterCondition = z2.object({
workflowFile: z2.string().endsWith(".yml"),
jobName: z2.string().min(1).optional(),
var workflowFile = z2.string().endsWith(".yml");
var matchAllJobs = z2.object({
workflowFile,
jobName: z2.undefined(),
// Preferring undefined over null for backward compatibility
jobMatchMode: z2.literal("all").default("all")
}).strict();
var matchPartialJobs = z2.object({
workflowFile,
jobName: z2.string().min(1),
jobMatchMode: z2.enum(["exact", "prefix"]).default("exact")
});
}).strict();
var FilterCondition = z2.union([matchAllJobs, matchPartialJobs]);
var SkipFilterCondition = FilterCondition.readonly();
var WaitFilterCondition = FilterCondition.extend(
{
optional: z2.boolean().default(false).readonly(),
// - Intentionally avoided to use enum for now. Only GitHub knows whole eventNames and the adding plans
// - Intentionally omitted in skip-list, let me know if you have the use-case
eventName: z2.string().min(1).optional(),
// Do not raise validation errors for the reasonability of max value.
// Even in equal_intervals mode, we can't enforce the possibility of the whole running time
startupGracePeriod: Durationable.default(defaultGrace)
}
).readonly();
var waitOptions = {
optional: z2.boolean().default(false).readonly(),
// - Intentionally avoided to use enum for now. Only GitHub knows whole eventNames and the adding plans
// - Intentionally omitted in skip-list, let me know if you have the use-case
eventName: z2.string().min(1).optional(),
// Do not raise validation errors for the reasonability of max value.
// Even in equal_intervals mode, we can't enforce the possibility of the whole running time
startupGracePeriod: Durationable.default(defaultGrace)
};
var WaitFilterCondition = z2.union([
matchAllJobs.extend(waitOptions).strict(),
matchPartialJobs.extend(waitOptions).strict()
]).readonly();
var WaitList = z2.array(WaitFilterCondition).readonly();
var SkipList = z2.array(SkipFilterCondition).readonly();
var retryMethods = z2.enum(["exponential_backoff", "equal_intervals"]);
Expand Down Expand Up @@ -32409,8 +32419,8 @@ function getSummaries(checks, trigger) {
(a2, b2) => join2(a2.workflowBasename, a2.jobName).localeCompare(join2(b2.workflowBasename, b2.jobName))
);
}
function matchPath({ workflowFile, jobName, jobMatchMode }, summary) {
if (workflowFile !== summary.workflowBasename) {
function matchPath({ workflowFile: workflowFile2, jobName, jobMatchMode }, summary) {
if (workflowFile2 !== summary.workflowBasename) {
return false;
}
if (!jobName) {
Expand Down
10 changes: 5 additions & 5 deletions src/report.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test('wait-list', async (t) => {
waitList: [
{
'workflowFile': 'lint.yml',
jobMatchMode: 'exact',
jobMatchMode: 'all',
'optional': false,
'eventName': 'pull_request',
startupGracePeriod: Temporal.Duration.from({ seconds: 10 }),
Expand All @@ -68,7 +68,7 @@ test('wait-list', async (t) => {
},
{
'workflowFile': 'THERE_ARE_NO_FILES_AS_THIS.yml',
jobMatchMode: 'exact',
jobMatchMode: 'all',
'optional': true,
startupGracePeriod: Temporal.Duration.from({ seconds: 10 }),
},
Expand Down Expand Up @@ -513,15 +513,15 @@ test('skip-list', async (t) => {
skipList: [
{
'workflowFile': 'itself.yml',
jobMatchMode: 'exact',
jobMatchMode: 'all',
},
{
'workflowFile': 'ci.yml',
jobMatchMode: 'exact',
jobMatchMode: 'all',
},
{
'workflowFile': 'ci-nix.yml',
jobMatchMode: 'exact',
jobMatchMode: 'all',
},
{
'workflowFile': 'merge-bot-pr.yml',
Expand Down
10 changes: 5 additions & 5 deletions src/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test('Options set some default values it cannot be defined in action.yml', () =>
...defaultOptions,
waitList: [{
workflowFile: 'ci.yml',
jobMatchMode: 'exact',
jobMatchMode: 'all',
optional: false,
startupGracePeriod: Temporal.Duration.from({ seconds: 10 }),
}],
Expand Down Expand Up @@ -123,7 +123,7 @@ test('wait-list have startupGracePeriod', async (t) => {
...defaultOptions,
waitList: [{
workflowFile: 'ci.yml',
jobMatchMode: 'exact',
jobMatchMode: 'all',
optional: false,
startupGracePeriod: Temporal.Duration.from({ minutes: 5 }),
}],
Expand Down Expand Up @@ -172,7 +172,7 @@ test('wait-list have startupGracePeriod', async (t) => {
...defaultOptions,
waitList: [{
workflowFile: 'ci.yml',
jobMatchMode: 'exact',
jobMatchMode: 'all',
optional: false,
startupGracePeriod: Temporal.Duration.from({ minutes: 1, seconds: 42 }),
}],
Expand Down Expand Up @@ -207,7 +207,7 @@ test('wait-list have startupGracePeriod', async (t) => {
initialDuration: Temporal.Duration.from({ seconds: 42 }),
waitList: [{
workflowFile: 'ci.yml',
jobMatchMode: 'exact',
jobMatchMode: 'all',
optional: false,
startupGracePeriod: Temporal.Duration.from({ seconds: 10 }),
}],
Expand All @@ -225,7 +225,7 @@ test('wait-list have startupGracePeriod', async (t) => {
initialDuration: Temporal.Duration.from({ seconds: 42 }),
waitList: [{
workflowFile: 'ci.yml',
jobMatchMode: 'exact',
jobMatchMode: 'all',
optional: false,
startupGracePeriod: Temporal.Duration.from({ seconds: 10 }),
}],
Expand Down
42 changes: 27 additions & 15 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,37 @@ export function getDuration(durationable: string | MyDurationLike): Duration {
throw new Error('unexpected value is specified in durations');
}

const FilterCondition = z.object({
workflowFile: z.string().endsWith('.yml'),
jobName: (z.string().min(1)).optional(),
const workflowFile = z.string().endsWith('.yml');
const matchAllJobs = z.object({
workflowFile: workflowFile,
jobName: z.undefined(), // Preferring undefined over null for backward compatibility
jobMatchMode: z.literal('all').default('all'),
}).strict();
const matchPartialJobs = z.object({
workflowFile: workflowFile,
jobName: z.string().min(1),
jobMatchMode: z.enum(['exact', 'prefix']).default('exact'),
});
}).strict();

const FilterCondition = z.union([matchAllJobs, matchPartialJobs]);
const SkipFilterCondition = FilterCondition.readonly();
const WaitFilterCondition = FilterCondition.extend(
{
optional: z.boolean().default(false).readonly(),

// - Intentionally avoided to use enum for now. Only GitHub knows whole eventNames and the adding plans
// - Intentionally omitted in skip-list, let me know if you have the use-case
eventName: z.string().min(1).optional(),
const waitOptions = {
optional: z.boolean().default(false).readonly(),

// Do not raise validation errors for the reasonability of max value.
// Even in equal_intervals mode, we can't enforce the possibility of the whole running time
startupGracePeriod: Durationable.default(defaultGrace),
},
).readonly();
// - Intentionally avoided to use enum for now. Only GitHub knows whole eventNames and the adding plans
// - Intentionally omitted in skip-list, let me know if you have the use-case
eventName: z.string().min(1).optional(),

// Do not raise validation errors for the reasonability of max value.
// Even in equal_intervals mode, we can't enforce the possibility of the whole running time
startupGracePeriod: Durationable.default(defaultGrace),
};

const WaitFilterCondition = z.union([
matchAllJobs.extend(waitOptions).strict(),
matchPartialJobs.extend(waitOptions).strict(),
]).readonly();
const WaitList = z.array(WaitFilterCondition).readonly();
const SkipList = z.array(SkipFilterCondition).readonly();
export type FilterCondition = z.infer<typeof FilterCondition>;
Expand Down

0 comments on commit e66e1df

Please sign in to comment.