From fc595c1c24fb06a5e57877c24a03ab4cea10fd7b Mon Sep 17 00:00:00 2001 From: Sam Lanning Date: Fri, 14 May 2021 11:44:08 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Allow=20for=20action=20to=20be?= =?UTF-8?q?=20run=20in=20cron=20workflows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/main/index.js | 3 ++- src/index.ts | 5 ++++- test/cron-workflow.spec.ts | 41 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 test/cron-workflow.spec.ts diff --git a/dist/main/index.js b/dist/main/index.js index 6f9c8d6..2b5f559 100644 --- a/dist/main/index.js +++ b/dist/main/index.js @@ -4052,7 +4052,8 @@ var runAction = function (_a) { log.error("::error ::" + msg); return new Error(msg); }; - if (!(env.GITHUB_EVENT_NAME === 'push')) return [3 /*break*/, 3]; + if (!(env.GITHUB_EVENT_NAME === 'push' || + env.GITHUB_EVENT_NAME === 'schedule')) return [3 /*break*/, 3]; dir = env.FOLDER ? path.join(cwd, env.FOLDER) : cwd; return [4 /*yield*/, libyear_1.runLibyear(dir)]; case 2: diff --git a/src/index.ts b/src/index.ts index 4e77842..3b37895 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,7 +23,10 @@ export const runAction = async ({ return new Error(msg); }; - if (env.GITHUB_EVENT_NAME === 'push') { + if ( + env.GITHUB_EVENT_NAME === 'push' || + env.GITHUB_EVENT_NAME === 'schedule' + ) { const dir = env.FOLDER ? path.join(cwd, env.FOLDER) : cwd; const report = await runLibyear(dir); diff --git a/test/cron-workflow.spec.ts b/test/cron-workflow.spec.ts new file mode 100644 index 0000000..984900c --- /dev/null +++ b/test/cron-workflow.spec.ts @@ -0,0 +1,41 @@ +import { loadSpec } from './spec'; +import { getResultsTable, getTotals } from '../src/libyear'; + +import { runAction } from './util'; + +describe('cron-workflow', () => { + it('basic-config', async () => { + const run = await runAction({ + eventJson: {}, + eventName: 'schedule', + logToConsole: false, + copySpec: { + spec: '001', + }, + }); + + const spec = await loadSpec('001'); + const specTotals = getTotals(spec); + + // Ensure that table is printed out + expect(run.stdout).toMatch( + `TABLE: ${JSON.stringify(getResultsTable(spec))}` + ); + + // Ensure that variables are set + for (const metric of ['drift', 'pulse'] as const) { + expect(specTotals.get(metric)).toBeTruthy(); + expect(run.stdout).toMatch( + `::set-output name=${metric}::${Number(specTotals.get(metric)).toFixed( + 2 + )}` + ); + } + for (const metric of ['releases', 'major', 'minor', 'patch'] as const) { + expect(specTotals.get(metric)).toBeTruthy(); + expect(run.stdout).toMatch( + `::set-output name=${metric}::${specTotals.get(metric)}` + ); + } + }); +});