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
54void async function main ( ) {
65 try {
@@ -12,8 +11,8 @@ void async function main() {
1211} ( )
1312
1413async 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