-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
88 lines (84 loc) · 2.67 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: 'Cleanup old releases from target server'
description: 'SSH into the target server and delete old releases leaving only newest ones. Provide absolute path and the number of releases to retain'
inputs:
ssh_user:
description: 'SSH user account'
required: true
ssh_host:
description: 'SSH host server'
required: true
ssh_key:
description: 'SSH private key'
required: true
ssh_user_jumphost:
description: 'SSH user account for jumphost'
required: false
default: ''
ssh_host_jumphost:
description: 'SSH host server for jumphost'
required: false
default: ''
cleanup_dir:
description: 'Absolute path to directory where releases are stored'
required: true
pattern:
description: 'Directory naming pattern to cleanup'
default: '*release-*'
retain:
description: 'Number of newest releases to retain. Older will be deleted'
default: 5
runs:
using: "composite"
steps:
- name: 'Configure SSH'
if: ${{ inputs.ssh_host_jumphost == '' }}
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/server.key
chmod 600 ~/.ssh/server.key
cat > ~/.ssh/config <<END
Host server
HostName $SSH_HOST
User $SSH_USER
IdentityFile ~/.ssh/server.key
StrictHostKeyChecking no
END
env:
SSH_USER: ${{ inputs.ssh_user }}
SSH_HOST: ${{ inputs.ssh_host }}
SSH_KEY: ${{ inputs.ssh_key }}
shell: bash
- name: 'Configure SSH'
if: ${{ inputs.ssh_host_jumphost != '' }}
run: |
mkdir -p ~/.ssh/
echo "$SSH_KEY" > ~/.ssh/server.key
chmod 600 ~/.ssh/server.key
cat > ~/.ssh/config <<END
Host jumphost
HostName $SSH_HOST_JUMPHOST
User $SSH_USER_JUMPHOST
IdentityFile ~/.ssh/server.key
StrictHostKeyChecking no
LogLevel QUIET
Host server
HostName $SSH_HOST
User $SSH_USER
IdentityFile ~/.ssh/server.key
StrictHostKeyChecking no
ProxyJump jumphost
END
env:
SSH_USER: ${{ inputs.ssh_user }}
SSH_HOST: ${{ inputs.ssh_host }}
SSH_KEY: ${{ inputs.ssh_key }}
SSH_USER_JUMPHOST: ${{ inputs.ssh_user_jumphost }}
SSH_HOST_JUMPHOST: ${{ inputs.ssh_host_jumphost }}
shell: bash
- name: 'Download and run the cleanup script'
run: >
ssh server 'cd ${{ inputs.cleanup_dir }}
&& curl -o cleanup.sh https://raw.githubusercontent.com/eaudeweb/drupal-cleanup-action/1.x/cleanup.sh
&& chmod +x cleanup.sh
&& ./cleanup.sh "${{ inputs.pattern }}" ${{ inputs.retain }}'
shell: bash