Skip to content

Commit

Permalink
Merge pull request #7 from s0/cron
Browse files Browse the repository at this point in the history
🐛 Allow for action to be run in cron workflows
  • Loading branch information
s0 committed May 14, 2021
2 parents c975f4a + fc595c1 commit 8b1596c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
3 changes: 2 additions & 1 deletion dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
41 changes: 41 additions & 0 deletions test/cron-workflow.spec.ts
Original file line number Diff line number Diff line change
@@ -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)}`
);
}
});
});

0 comments on commit 8b1596c

Please sign in to comment.