-
Notifications
You must be signed in to change notification settings - Fork 41
/
action.ts
77 lines (69 loc) · 2.73 KB
/
action.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { flags, SfdxCommand } from '@salesforce/command';
import { dump } from 'js-yaml';
import fs = require('fs-extra');
const getRandomInt = (min, max) => {
const roundedMin = Math.ceil(min);
const roundedMax = Math.floor(max);
return Math.floor(Math.random() * (roundedMax - roundedMin)) + roundedMin; // The maximum is exclusive and the minimum is inclusive
};
export default class GithubAction extends SfdxCommand {
public static description = 'adds an action to test your repo against https://github.com/mshanemc/deploy-to-sfdx using github actions';
public static examples = [
`sfdx shane:github:action
// tests against both prod and prerel(gs0) deployers
`
];
protected static requiresProject = true;
protected static flagsConfig = {
skipprod: flags.boolean({ char: 'p', description: 'omit the production deployer' }),
skipprerel: flags.boolean({ char: 'r', description: 'omit the pre-release deployer' })
};
public async run(): Promise<any> {
const outputFilename = `.github/workflows/deployer.yml`;
await fs.outputFile(outputFilename, dump(this.testyaml(), { indent: 4, noCompatMode: true })); // yaml for github actions
this.ux.log(`created ${outputFilename}`);
return outputFilename;
}
public testyaml() {
const production = {
'runs-on': 'ubuntu-latest',
name: 'production deployer end-to-end test',
steps: [
{
name: 'production',
id: 'production',
uses: 'mshanemc/deployer-check-javascript-action@master'
}
]
};
const prerelease = {
'runs-on': 'ubuntu-latest',
name: 'prerelease deployer end-to-end test',
steps: [
{
name: 'prerelease',
id: 'prerelease',
uses: 'mshanemc/deployer-check-javascript-action@master',
with: { 'deployer-url': 'https://deployer-prerelease.herokuapp.com' }
}
]
};
const output: any = {
name: 'deployer-test',
on: {
pull_request: null,
push: { branches: ['master'] },
// schedule: [{ cron: `"${getRandomInt(0, 60)} ${getRandomInt(0, 24)} * * ${getRandomInt(0, 7)}"` }]
schedule: [{ cron: `*/31 ${getRandomInt(0, 24)} * * ${getRandomInt(0, 7)}` }]
},
jobs: {}
};
if (!this.flags.skipprod) {
output.jobs.production = production;
}
if (!this.flags.skipprerel) {
output.jobs.prerelease = prerelease;
}
return output;
}
}