Skip to content

Commit

Permalink
Directly use Temporal.Duration in zod schema (#825)
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick authored Jun 2, 2024
1 parent 6db58d9 commit 471c225
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 97 deletions.
8 changes: 3 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31041,7 +31041,7 @@ var MyDurationLike = z2.object({
microseconds: z2.number().optional(),
nanoseconds: z2.number().optional()
}).strict().readonly();
var Durationable = z2.union([z2.string().duration(), MyDurationLike]);
var Durationable = z2.union([z2.string().duration(), MyDurationLike]).transform((item) => getDuration(item));
function isDurationLike(my) {
for (const [_2, value] of Object.entries(my)) {
if (value === void 0) {
Expand Down Expand Up @@ -31069,7 +31069,7 @@ var WaitFilterCondition = FilterCondition.extend(
eventName: z2.string().min(1).optional(),
// Do not raise validation errors for the reasonability of value range.
// Even in equal_intervals mode, we can't enforce the possibility of the whole running time
startupGracePeriod: Durationable.default({ seconds: 10 })
startupGracePeriod: Durationable.default(mr.Duration.from({ seconds: 10 }))
}
).readonly();
var WaitList = z2.array(WaitFilterCondition).readonly();
Expand Down Expand Up @@ -32389,9 +32389,7 @@ function seekWaitList(summaries, waitList, elapsed) {
})
);
const unmatches = seeker.filter((result) => !result.found && !result.optional);
const unstarted = unmatches.filter(
(result) => mr.Duration.compare(elapsed, getDuration(result.startupGracePeriod)) === -1
);
const unstarted = unmatches.filter((result) => mr.Duration.compare(elapsed, result.startupGracePeriod) === -1);
return { filtered, unmatches, unstarted };
}
function judge(summaries) {
Expand Down
123 changes: 60 additions & 63 deletions src/report.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'node:test';
import assert from 'node:assert';
import { checks8679817057, checks92810686811WaitSuccessPolling1 } from './snapshot.ts';
import { Report, Summary, generateReport, getSummaries } from './report.ts';
import { omit } from './util.ts';
import { jsonEqual, omit } from './util.ts';
import { Temporal } from 'temporal-polyfill';

const exampleSummary = Object.freeze(
Expand Down Expand Up @@ -46,18 +46,18 @@ test('wait-list', async (t) => {
'workflowFile': 'lint.yml',
'optional': false,
'eventName': 'pull_request',
startupGracePeriod: { seconds: 10 },
startupGracePeriod: Temporal.Duration.from({ seconds: 10 }),
},
{
'workflowFile': 'merge-bot-pr.yml',
'jobName': 'dependabot',
'optional': true,
startupGracePeriod: { seconds: 10 },
startupGracePeriod: Temporal.Duration.from({ seconds: 10 }),
},
{
'workflowFile': 'THERE_ARE_NO_FILES_AS_THIS.yml',
'optional': true,
startupGracePeriod: { seconds: 10 },
startupGracePeriod: Temporal.Duration.from({ seconds: 10 }),
},
],
skipList: [],
Expand Down Expand Up @@ -92,62 +92,63 @@ test('wait-list', async (t) => {
'workflowFile': 'GH-820-graceperiod.yml',
'jobName': 'quickstarter-success',
'optional': false,
'startupGracePeriod': { seconds: 10 },
'startupGracePeriod': Temporal.Duration.from({ seconds: 10 }),
},
{
'workflowFile': 'GH-820-graceperiod.yml',
'jobName': 'slowstarter-success',
'optional': false,
'startupGracePeriod': { seconds: 60 },
'startupGracePeriod': Temporal.Duration.from({ seconds: 60 }),
},
],
skipList: [],
shouldSkipSameWorkflow: false,
},
);

assert.deepStrictEqual(omit<Report, 'summaries'>(report, ['summaries']), {
done: false,
logs: [
{
message: 'some jobs still in progress',
severity: 'info',
resource: [
{
isAcceptable: false,
isCompleted: false,
checkRunUrl: 'https://github.com/kachick/wait-other-jobs/actions/runs/9281068681/job/25536443631',
checkSuiteConclusion: null,
checkSuiteStatus: 'QUEUED',
eventName: 'pull_request',
isSameWorkflow: false,
jobName: 'quickstarter-success',
runConclusion: null,
runDatabaseId: 25536443631,
runStatus: 'QUEUED',
severity: 'warning',
workflowBasename: 'GH-820-graceperiod.yml',
},
],
},
{
message: 'Some expected jobs were not started',
resource: [
{
found: false,
jobName: 'slowstarter-success',
optional: false,
startupGracePeriod: {
seconds: 60,
jsonEqual(
omit<Report, 'summaries'>(report, ['summaries']),
{
done: false,
logs: [
{
message: 'some jobs still in progress',
severity: 'info',
resource: [
{
isAcceptable: false,
isCompleted: false,
checkRunUrl: 'https://github.com/kachick/wait-other-jobs/actions/runs/9281068681/job/25536443631',
checkSuiteConclusion: null,
checkSuiteStatus: 'QUEUED',
eventName: 'pull_request',
isSameWorkflow: false,
jobName: 'quickstarter-success',
runConclusion: null,
runDatabaseId: 25536443631,
runStatus: 'QUEUED',
severity: 'warning',
workflowBasename: 'GH-820-graceperiod.yml',
},
workflowFile: 'GH-820-graceperiod.yml',
},
],
severity: 'warning',
},
],
ok: true,
});
],
},
{
message: 'Some expected jobs were not started',
resource: [
{
found: false,
jobName: 'slowstarter-success',
optional: false,
startupGracePeriod: 'PT60S',
workflowFile: 'GH-820-graceperiod.yml',
},
],
severity: 'warning',
},
],
ok: true,
},
);
});

await t.test('slowstarting job has been expired to the given period', (_t) => {
Expand All @@ -162,21 +163,21 @@ test('wait-list', async (t) => {
'workflowFile': 'GH-820-graceperiod.yml',
'jobName': 'quickstarter-success',
'optional': false,
'startupGracePeriod': { seconds: 10 },
'startupGracePeriod': Temporal.Duration.from({ seconds: 10 }),
},
{
'workflowFile': 'GH-820-graceperiod.yml',
'jobName': 'slowstarter-success',
'optional': false,
'startupGracePeriod': grace.toString(),
'startupGracePeriod': grace,
},
],
skipList: [],
shouldSkipSameWorkflow: false,
},
);

assert.deepStrictEqual(omit<Report, 'summaries'>(report, ['summaries']), {
jsonEqual(omit<Report, 'summaries'>(report, ['summaries']), {
done: false,
logs: [
{
Expand Down Expand Up @@ -229,21 +230,21 @@ test('wait-list', async (t) => {
'workflowFile': 'GH-820-graceperiod.yml',
'jobName': 'quickstarter-success',
'optional': false,
'startupGracePeriod': { seconds: 10 },
'startupGracePeriod': Temporal.Duration.from({ seconds: 10 }),
},
{
'workflowFile': 'GH-820-graceperiod.yml',
'jobName': 'slowstarter-success',
'optional': false,
'startupGracePeriod': { seconds: 60 },
'startupGracePeriod': Temporal.Duration.from({ seconds: 60 }),
},
],
skipList: [],
shouldSkipSameWorkflow: false,
},
);

assert.deepStrictEqual(omit<Report, 'summaries'>(report, ['summaries']), {
jsonEqual(omit<Report, 'summaries'>(report, ['summaries']), {
done: false,
logs: [
{
Expand Down Expand Up @@ -274,9 +275,7 @@ test('wait-list', async (t) => {
found: false,
jobName: 'slowstarter-success',
optional: false,
startupGracePeriod: {
seconds: 60,
},
startupGracePeriod: 'PT60S',
workflowFile: 'GH-820-graceperiod.yml',
},
],
Expand Down Expand Up @@ -312,27 +311,27 @@ test('wait-list', async (t) => {
'workflowFile': 'ci.yml',
'jobName': 'quickstarter-success',
'optional': false,
'startupGracePeriod': { minutes: 5 },
'startupGracePeriod': Temporal.Duration.from({ minutes: 5 }),
},
{
'workflowFile': 'ci.yml',
'jobName': 'quickstarter-fail',
'optional': false,
'startupGracePeriod': { minutes: 5 },
'startupGracePeriod': Temporal.Duration.from({ minutes: 5 }),
},
{
'workflowFile': 'ci.yml',
'jobName': 'slowstarter-missing',
'optional': false,
'startupGracePeriod': { minutes: 5 },
'startupGracePeriod': Temporal.Duration.from({ minutes: 5 }),
},
],
skipList: [],
shouldSkipSameWorkflow: false,
},
);

assert.deepStrictEqual(omit<Report, 'summaries'>(report, ['summaries']), {
jsonEqual(omit<Report, 'summaries'>(report, ['summaries']), {
done: false,
logs: [
{
Expand Down Expand Up @@ -363,9 +362,7 @@ test('wait-list', async (t) => {
found: false,
jobName: 'slowstarter-missing',
optional: false,
startupGracePeriod: {
minutes: 5,
},
startupGracePeriod: 'PT5M',
workflowFile: 'ci.yml',
},
],
Expand Down
6 changes: 2 additions & 4 deletions src/report.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CheckRun, CheckSuite, WorkflowRun } from '@octokit/graphql-schema';
import { Check, Options, Trigger, WaitList, getDuration } from './schema.ts';
import { Check, Options, Trigger, WaitList } from './schema.ts';
import { join, relative } from 'path';
import { Temporal } from 'temporal-polyfill';
import { groupBy } from './util.ts';
Expand Down Expand Up @@ -93,9 +93,7 @@ function seekWaitList(
);

const unmatches = seeker.filter((result) => (!(result.found)) && (!(result.optional)));
const unstarted = unmatches.filter((result) =>
Temporal.Duration.compare(elapsed, getDuration(result.startupGracePeriod)) === -1
);
const unstarted = unmatches.filter((result) => Temporal.Duration.compare(elapsed, result.startupGracePeriod) === -1);

return { filtered, unmatches, unstarted };
}
Expand Down
Loading

0 comments on commit 471c225

Please sign in to comment.