Skip to content

Commit ba36add

Browse files
committed
Update action to use zx
1 parent d12c16f commit ba36add

115 files changed

Lines changed: 1585 additions & 7116 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
# `deploy all`.
1919
# Required.
2020
dep: deploy
21-
22-
# Option to skip over the SSH setup/configuration
23-
# Self hosted runners don't need the SSH configuration or the SSH agent to be started
24-
self-hosted: false
21+
22+
# Config options for the Deployer. Same as the `-o` flag in the CLI.
23+
# Optional.
24+
options:
25+
keep_releases: 7
2526

2627
# Private key for connecting to remote hosts. To generate private key:
2728
# `ssh-keygen -o -t rsa -C 'action@deployer.org'`.
@@ -41,6 +42,12 @@
4142
# Optional.
4243
ssh-config: |
4344
...
45+
46+
# Option to skip over the SSH setup/configuration.
47+
# Self-hosted runners don't need the SSH configuration or the SSH agent
48+
# to be started.
49+
# Optional.
50+
skip-ssh-setup: false
4451

4552
# Deployer version to download from deployer.org.
4653
# First, the action will check for Deployer binary at those paths:

action.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ inputs:
88
required: true
99
description: The command.
1010

11-
self-hosted:
11+
options:
1212
required: false
13-
default: 'false'
14-
description: Whether the action is running on a self-hosted runner.
13+
default: ''
14+
description: List of options for the Deployer.
1515

1616
private-key:
1717
required: false
@@ -28,6 +28,11 @@ inputs:
2828
default: ''
2929
description: The SSH configuration
3030

31+
skip-ssh-setup:
32+
required: false
33+
default: 'false'
34+
description: Whether the SSH setup should be skipped.
35+
3136
deployer-version:
3237
required: false
3338
default: ''

index.js

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
const core = require('@actions/core')
2-
const fs = require('fs')
3-
const execa = require('execa')
1+
import core from '@actions/core'
2+
import { $, fs } from 'zx'
43

54
void async function main() {
65
try {
@@ -12,8 +11,8 @@ void async function main() {
1211
}()
1312

1413
async function ssh() {
15-
if (core.getBooleanInput('self-hosted')) {
16-
return;
14+
if (core.getBooleanInput('skip-ssh-setup')) {
15+
return
1716
}
1817

1918
let sshHomeDir = `${process.env['HOME']}/.ssh`
@@ -23,13 +22,16 @@ async function ssh() {
2322
}
2423

2524
let authSock = '/tmp/ssh-auth.sock'
26-
execa.sync('ssh-agent', ['-a', authSock])
25+
await $`ssh-agent -a ${authSock}`
2726
core.exportVariable('SSH_AUTH_SOCK', authSock)
2827

2928
let privateKey = core.getInput('private-key')
3029
if (privateKey !== '') {
3130
privateKey = privateKey.replace('/\r/g', '').trim() + '\n'
32-
execa.sync('ssh-add', ['-'], {input: privateKey})
31+
let p = $`ssh-add -`
32+
p.stdin.write(privateKey)
33+
p.stdin.end()
34+
await p
3335
}
3436

3537
const knownHosts = core.getInput('known-hosts')
@@ -52,51 +54,66 @@ async function dep() {
5254
let dep = core.getInput('deployer-binary')
5355

5456
if (dep === '')
55-
for (let c of ['vendor/bin/deployer.phar', 'vendor/bin/dep', 'deployer.phar']) {
56-
if (fs.existsSync(c)) {
57-
dep = c
58-
console.log(`Using "${c}".`)
59-
break
57+
for (let c of ['vendor/bin/deployer.phar', 'vendor/bin/dep', 'deployer.phar']) {
58+
if (fs.existsSync(c)) {
59+
dep = c
60+
console.log(`Using "${c}".`)
61+
break
62+
}
6063
}
61-
}
6264

6365
if (dep === '') {
6466
let version = core.getInput('deployer-version')
65-
if (version === '') {
66-
console.log(`Downloading "https://deployer.org/deployer.phar".`)
67-
execa.commandSync('curl -LO https://deployer.org/deployer.phar')
68-
} else {
69-
version = version.replace(/^v/, '')
70-
let {stdout} = execa.commandSync(`curl -L https://deployer.org/manifest.json`)
71-
let manifest = JSON.parse(stdout)
72-
let url
73-
for (let asset of manifest) {
74-
if (asset.version === version) {
75-
url = asset.url
76-
break
77-
}
67+
if (version === '' && fs.existsSync('composer.lock')) {
68+
let lock = JSON.parse(fs.readFileSync('composer.lock', 'utf8'))
69+
if (lock['packages']) {
70+
version = lock['packages']
71+
.find(p => p.name === 'deployer/deployer')
72+
.version
7873
}
79-
if (url === null) {
80-
console.error(`The version "${version}"" does not exist in the "https://deployer.org/manifest.json" file."`)
81-
} else {
82-
console.log(`Downloading "${url}".`)
83-
execa.commandSync(`curl -LO ${url}`)
74+
if (version === '' && lock['packages-dev']) {
75+
version = lock['packages-dev']
76+
.find(p => p.name === 'deployer/deployer')
77+
.version
78+
}
79+
}
80+
if (version === '') {
81+
throw new Error('Deployer binary not found. Please specify deployer-binary or deployer-version.')
82+
}
83+
version = version.replace(/^v/, '')
84+
let manifest = JSON.parse((await $`curl -L https://deployer.org/manifest.json`).stdout)
85+
let url
86+
for (let asset of manifest) {
87+
if (asset.version === version) {
88+
url = asset.url
89+
break
8490
}
8591
}
86-
execa.commandSync('sudo chmod +x deployer.phar')
92+
if (url === null) {
93+
console.error(`The version "${version}"" does not exist in the "https://deployer.org/manifest.json" file."`)
94+
} else {
95+
console.log(`Downloading "${url}".`)
96+
await $`curl -LO ${url}`
97+
}
98+
99+
await $`sudo chmod +x deployer.phar`
87100
dep = 'deployer.phar'
88101
}
89102

90103
let cmd = core.getInput('dep')
91-
let ansi = core.getBooleanInput('ansi') ? '--ansi' : '--no-ansi';
92-
let verbosity = core.getInput('verbosity');
93-
94-
let p = execa.command(`php ${dep} --no-interaction ${ansi} ${verbosity} ${cmd}`)
95-
p.stdout.pipe(process.stdout)
96-
p.stderr.pipe(process.stderr)
104+
let ansi = core.getBooleanInput('ansi') ? '--ansi' : '--no-ansi'
105+
let verbosity = core.getInput('verbosity')
106+
let options = []
107+
try {
108+
for (let [key, value] in Object.entries(JSON.parse(core.getInput('options')))) {
109+
options.push('-o', `${key}=${value}`)
110+
}
111+
} catch (e) {
112+
console.error('Invalid JSON in options')
113+
}
97114

98115
try {
99-
await p
116+
await $`php ${dep} --no-interaction ${ansi} ${verbosity} ${cmd} ${options}`
100117
} catch (err) {
101118
core.setFailed(`Failed: dep ${cmd}`)
102119
}

0 commit comments

Comments
 (0)