Skip to content

Commit

Permalink
Parse options as YAML string
Browse files Browse the repository at this point in the history
  • Loading branch information
richardhj committed Jun 30, 2024
1 parent 2804049 commit 1bf4a66
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
sub-directory: "..."

# Config options for the Deployer. Same as the `-o` flag in the CLI.
# The | is very important here!
# Optional.
options:
options: |
keep_releases: 7
# Private key for connecting to remote hosts. To generate private key:
Expand Down
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import core from '@actions/core'
import { $, fs, cd } from 'zx'
import * as yaml from 'js-yaml'

void async function main() {
try {
Expand Down Expand Up @@ -113,16 +114,16 @@ async function dep() {

let ansi = core.getBooleanInput('ansi') ? '--ansi' : '--no-ansi'
let verbosity = core.getInput('verbosity')
let options = []
const options = []
try {
let optionsArg = core.getInput('options')
if (optionsArg !== '') {
for (let [key, value] in Object.entries(JSON.parse(optionsArg))) {
for (let [key, value] in Object.entries(yaml.load(optionsArg))) {
options.push('-o', `${key}=${value}`)
}
}
} catch (e) {
console.error('Invalid JSON in options')
console.error('Invalid YAML in options')
}

let phpBin = 'php'
Expand All @@ -132,7 +133,7 @@ async function dep() {
}

try {
await $`${phpBin} ${dep} ${cmd} ${recipe} --no-interaction ${ansi} ${verbosity} ${options}`
await $`${phpBin} ${dep} ${cmd} ${recipe} --no-interaction ${ansi} ${verbosity} ${options.join(' ')}`
} catch (err) {
core.setFailed(`Failed: dep ${cmd}`)
}
Expand Down
16 changes: 16 additions & 0 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"type": "module",
"dependencies": {
"@actions/core": "^1.10.0",
"js-yaml": "^4.1.0",
"zx": "^7.2.1"
},
"engines": {
Expand Down

0 comments on commit 1bf4a66

Please sign in to comment.