diff --git a/README.md b/README.md index 647a0fb..9121a79 100644 --- a/README.md +++ b/README.md @@ -2,42 +2,34 @@ ```yaml - name: Deploy - uses: deployphp/action@1 + uses: deployphp/action@v1 with: private-key: ${{ secrets.PRIVATE_KEY }} - dep: deploy all + dep: deploy ``` ## Inputs See [action.yaml](action.yaml). -## Deployer version - -First, the action will check for Deployer binary at those paths: -- `vendor/bin/dep` -- `deployer.phar` - -If the binary not found, phar version will be downloaded from -[deployer.org](https://deployer.org/download). - ## Example ```yaml -deploy: - name: Deploy to prod - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Setup PHP - uses: shivammathur/setup-php@master - with: - php-version: 7.4 - - name: Deploy - uses: deployphp/action@master - with: - private-key: ${{ secrets.PRIVATE_KEY }} - known-hosts: ${{ secrets.KNOWN_HOSTS }} - ssh-config: ${{ secrets.SSH_CONFIG }} - dep: deploy prod -v +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.0' + + - name: Deploy + uses: deployphp/action@v1 + with: + private-key: ${{ secrets.PRIVATE_KEY }} + dep: deploy ``` diff --git a/action.yaml b/action.yaml index c3eb8ef..d75655e 100644 --- a/action.yaml +++ b/action.yaml @@ -31,7 +31,20 @@ inputs: required: false default: '' description: > - The SSH configuration. + The SSH configuration. Content of `~/.ssh/config` file. + + deployer-version: + required: false + default: '' + description: > + Deployer version to download from deployer.org. + + First, the action will check for Deployer binary at those paths: + - `vendor/bin/dep` + - `deployer.phar` + + If the binary not found, phar version will be downloaded from + [deployer.org](https://deployer.org/download). runs: using: 'node12' diff --git a/index.js b/index.js index 8b644c0..e648771 100644 --- a/index.js +++ b/index.js @@ -12,10 +12,10 @@ void async function main() { }() async function ssh() { - let ssh = `${process.env['HOME']}/.ssh` + let sshHomeDir = `${process.env['HOME']}/.ssh` - if (!fs.existsSync(ssh)) { - fs.mkdirSync(ssh) + if (!fs.existsSync(sshHomeDir)) { + fs.mkdirSync(sshHomeDir) } let authSock = '/tmp/ssh-auth.sock' @@ -27,17 +27,17 @@ async function ssh() { const knownHosts = core.getInput('known-hosts') if (knownHosts !== '') { - fs.appendFileSync(`${ssh}/known_hosts`, knownHosts) - fs.chmodSync(`${ssh}/known_hosts`, '600') + fs.appendFileSync(`${sshHomeDir}/known_hosts`, knownHosts) + fs.chmodSync(`${sshHomeDir}/known_hosts`, '600') } else { - fs.appendFileSync(`${ssh}/config`, `StrictHostKeyChecking no`) - fs.chmodSync(`${ssh}/config`, '600') + fs.appendFileSync(`${sshHomeDir}/config`, `StrictHostKeyChecking no`) + fs.chmodSync(`${sshHomeDir}/config`, '600') } - const sshConfig = core.getInput('ssh-config') + let sshConfig = core.getInput('ssh-config') if (sshConfig !== '') { - fs.writeFileSync(`${ssh}/config`, sshConfig) - fs.chmodSync(`${ssh}/config`, '600') + fs.writeFileSync(`${sshHomeDir}/config`, sshConfig) + fs.chmodSync(`${sshHomeDir}/config`, '600') } } @@ -51,12 +51,20 @@ async function dep() { } if (!dep) { - execa.commandSync('curl -LO https://deployer.org/deployer.phar') + let version = core.getInput('deployer-version') + if (version === '') { + execa.commandSync('curl -LO https://deployer.org/deployer.phar') + } else { + if (!/^v/.test(version)) { + version = 'v' + version + } + execa.commandSync(`curl -LO https://deployer.org/releases/${version}/deployer.phar`) + } execa.commandSync('sudo chmod +x deployer.phar') dep = 'deployer.phar' } - let p = execa.command(`php ${dep} ${core.getInput('dep')}`) + let p = execa.command(`php ${dep} --ansi -v ${core.getInput('dep')}`) p.stdout.pipe(process.stdout) p.stderr.pipe(process.stderr) try {