Skip to content

Commit

Permalink
main: parse requirements yaml and run appropriate commands
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidd6 committed Dec 9, 2020
1 parent 19d1b2c commit 9a7cbd2
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const core = require('@actions/core')
const exec = require('@actions/exec')
const yaml = require('yaml')
const fs = require('fs')
const os = require('os')

Expand All @@ -25,8 +26,17 @@ async function main() {
}

if (requirements) {
await exec.exec("ansible-galaxy", ["role", "install", "-r", requirements])
await exec.exec("ansible-galaxy", ["collection", "install", "-r", requirements])
const requirementsContent = fs.readFileSync(requirements, 'utf8')
const requirementsObject = yaml.parse(requirementsContent)

if (Array.isArray(requirementsObject)) {
await exec.exec("ansible-galaxy", ["install", "-r", requirements])
} else {
if (requirementsObject.roles)
await exec.exec("ansible-galaxy", ["role", "install", "-r", requirements])
if (requirementsObject.collections)
await exec.exec("ansible-galaxy", ["collection", "install", "-r", requirements])
}
}

if (key) {
Expand Down

0 comments on commit 9a7cbd2

Please sign in to comment.