Skip to content

Commit 77ac0bf

Browse files
committed
Add deployer-version
1 parent fe85454 commit 77ac0bf

File tree

3 files changed

+53
-40
lines changed

3 files changed

+53
-40
lines changed

README.md

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,34 @@
22

33
```yaml
44
- name: Deploy
5-
uses: deployphp/action@1
5+
uses: deployphp/action@v1
66
with:
77
private-key: ${{ secrets.PRIVATE_KEY }}
8-
dep: deploy all
8+
dep: deploy
99
```
1010
1111
## Inputs
1212
1313
See [action.yaml](action.yaml).
1414
15-
## Deployer version
16-
17-
First, the action will check for Deployer binary at those paths:
18-
- `vendor/bin/dep`
19-
- `deployer.phar`
20-
21-
If the binary not found, phar version will be downloaded from
22-
[deployer.org](https://deployer.org/download).
23-
2415
## Example
2516
2617
```yaml
27-
deploy:
28-
name: Deploy to prod
29-
runs-on: ubuntu-latest
30-
steps:
31-
- uses: actions/checkout@v1
32-
- name: Setup PHP
33-
uses: shivammathur/setup-php@master
34-
with:
35-
php-version: 7.4
36-
- name: Deploy
37-
uses: deployphp/action@master
38-
with:
39-
private-key: ${{ secrets.PRIVATE_KEY }}
40-
known-hosts: ${{ secrets.KNOWN_HOSTS }}
41-
ssh-config: ${{ secrets.SSH_CONFIG }}
42-
dep: deploy prod -v
18+
jobs:
19+
deploy:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- uses: actions/checkout@v2
24+
25+
- name: Setup PHP
26+
uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: '8.0'
29+
30+
- name: Deploy
31+
uses: deployphp/action@v1
32+
with:
33+
private-key: ${{ secrets.PRIVATE_KEY }}
34+
dep: deploy
4335
```

action.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,20 @@ inputs:
3131
required: false
3232
default: ''
3333
description: >
34-
The SSH configuration.
34+
The SSH configuration. Content of `~/.ssh/config` file.
35+
36+
deployer-version:
37+
required: false
38+
default: ''
39+
description: >
40+
Deployer version to download from deployer.org.
41+
42+
First, the action will check for Deployer binary at those paths:
43+
- `vendor/bin/dep`
44+
- `deployer.phar`
45+
46+
If the binary not found, phar version will be downloaded from
47+
[deployer.org](https://deployer.org/download).
3548
3649
runs:
3750
using: 'node12'

index.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ void async function main() {
1212
}()
1313

1414
async function ssh() {
15-
let ssh = `${process.env['HOME']}/.ssh`
15+
let sshHomeDir = `${process.env['HOME']}/.ssh`
1616

17-
if (!fs.existsSync(ssh)) {
18-
fs.mkdirSync(ssh)
17+
if (!fs.existsSync(sshHomeDir)) {
18+
fs.mkdirSync(sshHomeDir)
1919
}
2020

2121
let authSock = '/tmp/ssh-auth.sock'
@@ -27,17 +27,17 @@ async function ssh() {
2727

2828
const knownHosts = core.getInput('known-hosts')
2929
if (knownHosts !== '') {
30-
fs.appendFileSync(`${ssh}/known_hosts`, knownHosts)
31-
fs.chmodSync(`${ssh}/known_hosts`, '600')
30+
fs.appendFileSync(`${sshHomeDir}/known_hosts`, knownHosts)
31+
fs.chmodSync(`${sshHomeDir}/known_hosts`, '600')
3232
} else {
33-
fs.appendFileSync(`${ssh}/config`, `StrictHostKeyChecking no`)
34-
fs.chmodSync(`${ssh}/config`, '600')
33+
fs.appendFileSync(`${sshHomeDir}/config`, `StrictHostKeyChecking no`)
34+
fs.chmodSync(`${sshHomeDir}/config`, '600')
3535
}
3636

37-
const sshConfig = core.getInput('ssh-config')
37+
let sshConfig = core.getInput('ssh-config')
3838
if (sshConfig !== '') {
39-
fs.writeFileSync(`${ssh}/config`, sshConfig)
40-
fs.chmodSync(`${ssh}/config`, '600')
39+
fs.writeFileSync(`${sshHomeDir}/config`, sshConfig)
40+
fs.chmodSync(`${sshHomeDir}/config`, '600')
4141
}
4242
}
4343

@@ -51,12 +51,20 @@ async function dep() {
5151
}
5252

5353
if (!dep) {
54-
execa.commandSync('curl -LO https://deployer.org/deployer.phar')
54+
let version = core.getInput('deployer-version')
55+
if (version === '') {
56+
execa.commandSync('curl -LO https://deployer.org/deployer.phar')
57+
} else {
58+
if (!/^v/.test(version)) {
59+
version = 'v' + version
60+
}
61+
execa.commandSync(`curl -LO https://deployer.org/releases/${version}/deployer.phar`)
62+
}
5563
execa.commandSync('sudo chmod +x deployer.phar')
5664
dep = 'deployer.phar'
5765
}
5866

59-
let p = execa.command(`php ${dep} ${core.getInput('dep')}`)
67+
let p = execa.command(`php ${dep} --ansi -v ${core.getInput('dep')}`)
6068
p.stdout.pipe(process.stdout)
6169
p.stderr.pipe(process.stderr)
6270
try {

0 commit comments

Comments
 (0)