Add deployer-version

This commit is contained in:
Anton Medvedev 2021-10-15 23:07:42 +02:00
parent fe854546be
commit 77ac0bfc15
3 changed files with 53 additions and 40 deletions

@ -2,42 +2,34 @@
```yaml ```yaml
- name: Deploy - name: Deploy
uses: deployphp/action@1 uses: deployphp/action@v1
with: with:
private-key: ${{ secrets.PRIVATE_KEY }} private-key: ${{ secrets.PRIVATE_KEY }}
dep: deploy all dep: deploy
``` ```
## Inputs ## Inputs
See [action.yaml](action.yaml). 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 ## Example
```yaml ```yaml
deploy: jobs:
name: Deploy to prod deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1 steps:
- name: Setup PHP - uses: actions/checkout@v2
uses: shivammathur/setup-php@master
with: - name: Setup PHP
php-version: 7.4 uses: shivammathur/setup-php@v2
- name: Deploy with:
uses: deployphp/action@master php-version: '8.0'
with:
private-key: ${{ secrets.PRIVATE_KEY }} - name: Deploy
known-hosts: ${{ secrets.KNOWN_HOSTS }} uses: deployphp/action@v1
ssh-config: ${{ secrets.SSH_CONFIG }} with:
dep: deploy prod -v private-key: ${{ secrets.PRIVATE_KEY }}
dep: deploy
``` ```

@ -31,7 +31,20 @@ inputs:
required: false required: false
default: '' default: ''
description: > 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: runs:
using: 'node12' using: 'node12'

@ -12,10 +12,10 @@ void async function main() {
}() }()
async function ssh() { async function ssh() {
let ssh = `${process.env['HOME']}/.ssh` let sshHomeDir = `${process.env['HOME']}/.ssh`
if (!fs.existsSync(ssh)) { if (!fs.existsSync(sshHomeDir)) {
fs.mkdirSync(ssh) fs.mkdirSync(sshHomeDir)
} }
let authSock = '/tmp/ssh-auth.sock' let authSock = '/tmp/ssh-auth.sock'
@ -27,17 +27,17 @@ async function ssh() {
const knownHosts = core.getInput('known-hosts') const knownHosts = core.getInput('known-hosts')
if (knownHosts !== '') { if (knownHosts !== '') {
fs.appendFileSync(`${ssh}/known_hosts`, knownHosts) fs.appendFileSync(`${sshHomeDir}/known_hosts`, knownHosts)
fs.chmodSync(`${ssh}/known_hosts`, '600') fs.chmodSync(`${sshHomeDir}/known_hosts`, '600')
} else { } else {
fs.appendFileSync(`${ssh}/config`, `StrictHostKeyChecking no`) fs.appendFileSync(`${sshHomeDir}/config`, `StrictHostKeyChecking no`)
fs.chmodSync(`${ssh}/config`, '600') fs.chmodSync(`${sshHomeDir}/config`, '600')
} }
const sshConfig = core.getInput('ssh-config') let sshConfig = core.getInput('ssh-config')
if (sshConfig !== '') { if (sshConfig !== '') {
fs.writeFileSync(`${ssh}/config`, sshConfig) fs.writeFileSync(`${sshHomeDir}/config`, sshConfig)
fs.chmodSync(`${ssh}/config`, '600') fs.chmodSync(`${sshHomeDir}/config`, '600')
} }
} }
@ -51,12 +51,20 @@ async function dep() {
} }
if (!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') execa.commandSync('sudo chmod +x deployer.phar')
dep = '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.stdout.pipe(process.stdout)
p.stderr.pipe(process.stderr) p.stderr.pipe(process.stderr)
try { try {