Skip to content

Commit 8b1596c

Browse files
authored
Merge pull request #7 from s0/cron
🐛 Allow for action to be run in cron workflows
2 parents c975f4a + fc595c1 commit 8b1596c

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

dist/main/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4052,7 +4052,8 @@ var runAction = function (_a) {
40524052
log.error("::error ::" + msg);
40534053
return new Error(msg);
40544054
};
4055-
if (!(env.GITHUB_EVENT_NAME === 'push')) return [3 /*break*/, 3];
4055+
if (!(env.GITHUB_EVENT_NAME === 'push' ||
4056+
env.GITHUB_EVENT_NAME === 'schedule')) return [3 /*break*/, 3];
40564057
dir = env.FOLDER ? path.join(cwd, env.FOLDER) : cwd;
40574058
return [4 /*yield*/, libyear_1.runLibyear(dir)];
40584059
case 2:

src/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ export const runAction = async ({
2323
return new Error(msg);
2424
};
2525

26-
if (env.GITHUB_EVENT_NAME === 'push') {
26+
if (
27+
env.GITHUB_EVENT_NAME === 'push' ||
28+
env.GITHUB_EVENT_NAME === 'schedule'
29+
) {
2730
const dir = env.FOLDER ? path.join(cwd, env.FOLDER) : cwd;
2831
const report = await runLibyear(dir);
2932

test/cron-workflow.spec.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { loadSpec } from './spec';
2+
import { getResultsTable, getTotals } from '../src/libyear';
3+
4+
import { runAction } from './util';
5+
6+
describe('cron-workflow', () => {
7+
it('basic-config', async () => {
8+
const run = await runAction({
9+
eventJson: {},
10+
eventName: 'schedule',
11+
logToConsole: false,
12+
copySpec: {
13+
spec: '001',
14+
},
15+
});
16+
17+
const spec = await loadSpec('001');
18+
const specTotals = getTotals(spec);
19+
20+
// Ensure that table is printed out
21+
expect(run.stdout).toMatch(
22+
`TABLE: ${JSON.stringify(getResultsTable(spec))}`
23+
);
24+
25+
// Ensure that variables are set
26+
for (const metric of ['drift', 'pulse'] as const) {
27+
expect(specTotals.get(metric)).toBeTruthy();
28+
expect(run.stdout).toMatch(
29+
`::set-output name=${metric}::${Number(specTotals.get(metric)).toFixed(
30+
2
31+
)}`
32+
);
33+
}
34+
for (const metric of ['releases', 'major', 'minor', 'patch'] as const) {
35+
expect(specTotals.get(metric)).toBeTruthy();
36+
expect(run.stdout).toMatch(
37+
`::set-output name=${metric}::${specTotals.get(metric)}`
38+
);
39+
}
40+
});
41+
});

0 commit comments

Comments
 (0)