Created
March 31, 2019 13:43
-
-
Save amir-arad/770df681303ea031b2ee16caa6cdff51 to your computer and use it in GitHub Desktop.
generate github actions workflow automatically for yarn monorepo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var fs = require('fs'); | |
var path = require('path'); | |
const moduleNames = fs.readdirSync(path.resolve(__dirname, '..', 'modules'), {withFileTypes:true}).filter(n => n.isDirectory()).map(n => n.name); | |
fs.writeFileSync(path.join(__dirname, 'main.workflow'), repoScript(moduleNames)); | |
function repoScript(moduleNames) { | |
return ` | |
workflow "Build, Lint and Test" { | |
on = "push" | |
resolves = [${moduleNames.map(moduleName => `"Lint_${moduleName}", "Test_${moduleName}"`)}] | |
} | |
action "Install" { | |
uses = "amir-arad/actions-yarn@master" | |
args = "install" | |
} | |
${moduleNames.map(moduleScript).join('')} | |
`; | |
} | |
function moduleScript(moduleName) { | |
return ` | |
action "Lint_${moduleName}" { | |
needs = "Install" | |
uses = "amir-arad/actions-yarn@master" | |
args = "workspace @starwards/${moduleName} lint" | |
} | |
action "Test_${moduleName}" { | |
needs = "Install" | |
uses = "amir-arad/actions-yarn@master" | |
args = "workspace @starwards/${moduleName} test" | |
} | |
`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment