1
- name : remote ssh command
2
- on : [push]
1
+ name : testing main branch
3
2
4
- env :
5
- FOO : " BAR"
6
- BAR : " FOO"
3
+ on : [push]
7
4
8
5
jobs :
9
- testing01 :
10
- name : default flag testing
6
+ default-user-name-password :
11
7
runs-on : ubuntu-latest
12
8
steps :
13
- - name : checkout
9
+ - name : Checkout code
14
10
uses : actions/checkout@v4
15
11
16
- - name : correct password but wrong key
17
- uses : ./
18
- with :
19
- host : ${{ secrets.HOST }}
20
- username : ${{ secrets.USERNAME }}
21
- password : ${{ secrets.PASSWORD }}
22
- key : " 1234"
23
- port : ${{ secrets.PORT }}
24
- script : whoami
12
+ - name : create new ssh server
13
+ run : |
14
+ docker run -d \
15
+ --name=openssh-server \
16
+ --hostname=openssh-server \
17
+ -p 2222:2222 \
18
+ -e SUDO_ACCESS=false \
19
+ -e PASSWORD_ACCESS=true \
20
+ -e USER_PASSWORD=password \
21
+ -e USER_NAME=linuxserver.io \
22
+ --restart unless-stopped \
23
+ lscr.io/linuxserver/openssh-server:latest
24
+ docker exec openssh-server sh -c "hostname -i" > ip.txt
25
+ echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
26
+ cat ip.txt >> $GITHUB_ENV
27
+ echo "EOF" >> $GITHUB_ENV
28
+ echo "======= container ip address ========="
29
+ cat ip.txt
30
+ echo "======================================"
31
+ sleep 2
25
32
26
- - name : wrong password but correct key
33
+ - name : ssh by username and password
27
34
uses : ./
28
35
with :
29
- host : ${{ secrets.HOST }}
30
- username : ${{ secrets.USERNAME }}
31
- password : " abcdef"
32
- key : ${{ secrets.KEY }}
33
- port : ${{ secrets.PORT }}
36
+ host : ${{ env.REMOTE_HOST }}
37
+ username : linuxserver.io
38
+ password : password
39
+ port : 2222
34
40
script : whoami
35
41
36
- - name : executing remote ssh commands using password
42
+ check-ssh-key :
43
+ runs-on : ubuntu-latest
44
+ steps :
45
+ - name : Checkout code
46
+ uses : actions/checkout@v4
47
+
48
+ - name : add public key to env
49
+ run : |
50
+ echo "PUBLIC_KEY<<EOF" >> $GITHUB_ENV
51
+ cat testdata/.ssh/id_rsa.pub >> $GITHUB_ENV
52
+ echo "EOF" >> $GITHUB_ENV
53
+ echo "======= public key ========="
54
+ cat testdata/.ssh/id_rsa.pub
55
+ echo "============================"
56
+ echo "PRIVATE_KEY<<EOF" >> $GITHUB_ENV
57
+ cat testdata/.ssh/id_rsa >> $GITHUB_ENV
58
+ echo "EOF" >> $GITHUB_ENV
59
+ echo "======= private key ========="
60
+ cat testdata/.ssh/id_rsa
61
+ echo "============================"
62
+
63
+ - name : create new ssh server
64
+ run : |
65
+ docker run -d \
66
+ --name=openssh-server \
67
+ --hostname=openssh-server \
68
+ -p 2222:2222 \
69
+ -e PUBLIC_KEY="${{ env.PUBLIC_KEY }}" \
70
+ -e SUDO_ACCESS=false \
71
+ -e PASSWORD_ACCESS=true \
72
+ -e USER_PASSWORD=password \
73
+ -e USER_NAME=linuxserver.io \
74
+ --restart unless-stopped \
75
+ lscr.io/linuxserver/openssh-server:latest
76
+ docker exec openssh-server sh -c "hostname -i" > ip.txt
77
+ echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
78
+ cat ip.txt >> $GITHUB_ENV
79
+ echo "EOF" >> $GITHUB_ENV
80
+ echo "======= container ip address ========="
81
+ cat ip.txt
82
+ echo "======================================"
83
+ sleep 2
84
+
85
+ - name : ssh by private key
37
86
uses : ./
38
87
with :
39
- host : ${{ secrets.HOST }}
40
- username : ${{ secrets.USERNAME }}
41
- password : ${{ secrets.PASSWORD }}
42
- port : ${{ secrets.PORT }}
88
+ host : ${{ env.REMOTE_HOST }}
89
+ username : linuxserver.io
90
+ key : ${{ env.PRIVATE_KEY }}
91
+ port : 2222
43
92
script : whoami
44
93
45
- - name : executing remote ssh commands using ssh key
94
+ - name : wrong password but correct key
46
95
uses : ./
47
96
with :
48
- host : ${{ secrets.HOST }}
49
- username : ${{ secrets.USERNAME }}
50
- key : ${{ secrets.KEY }}
51
- port : ${{ secrets.PORT }}
97
+ host : ${{ env.REMOTE_HOST }}
98
+ username : linuxserver.io
99
+ password : " abcdef"
100
+ key : ${{ env.PRIVATE_KEY }}
101
+ port : 2222
52
102
script : whoami
53
103
54
- - name : multiple command
104
+ - name : correct password but wrong key
55
105
uses : ./
56
106
with :
57
- host : ${{ secrets.HOST }}
58
- username : ${{ secrets.USERNAME }}
59
- key : ${{ secrets.KEY }}
60
- port : ${{ secrets.PORT }}
61
- script : |
62
- whoami
63
- ls -al
107
+ host : ${{ env.REMOTE_HOST }}
108
+ username : linuxserver.io
109
+ password : password
110
+ key : password
111
+ port : 2222
112
+ script : whoami
64
113
65
114
- name : stop script if command error
66
115
uses : ./
67
116
continue-on-error : true
68
117
with :
69
- host : ${{ secrets.HOST }}
70
- username : ${{ secrets.USERNAME }}
71
- key : ${{ secrets.KEY }}
72
- port : ${{ secrets.PORT }}
118
+ host : ${{ env.REMOTE_HOST }}
119
+ username : linuxserver.io
120
+ password : password
121
+ key : password
122
+ port : 2222
73
123
script_stop : true
74
124
sync : true
75
125
debug : true
76
126
script : |
77
127
mkdir abc/def
78
128
ls -al
79
129
130
+ support-key-passphrase :
131
+ runs-on : ubuntu-latest
132
+ steps :
133
+ - name : Checkout code
134
+ uses : actions/checkout@v4
135
+
136
+ - name : add public key to env
137
+ run : |
138
+ echo "PUBLIC_KEY<<EOF" >> $GITHUB_ENV
139
+ cat testdata/.ssh/id_passphrase.pub >> $GITHUB_ENV
140
+ echo "EOF" >> $GITHUB_ENV
141
+ echo "======= public key ========="
142
+ cat testdata/.ssh/id_passphrase.pub
143
+ echo "============================"
144
+ echo "PRIVATE_KEY<<EOF" >> $GITHUB_ENV
145
+ cat testdata/.ssh/id_passphrase >> $GITHUB_ENV
146
+ echo "EOF" >> $GITHUB_ENV
147
+ echo "======= private key ========="
148
+ cat testdata/.ssh/id_passphrase
149
+ echo "============================"
150
+
151
+ - name : create new ssh server
152
+ run : |
153
+ docker run -d \
154
+ --name=openssh-server \
155
+ --hostname=openssh-server \
156
+ -p 2222:2222 \
157
+ -e PUBLIC_KEY="${{ env.PUBLIC_KEY }}" \
158
+ -e SUDO_ACCESS=false \
159
+ -e PASSWORD_ACCESS=true \
160
+ -e USER_PASSWORD=password \
161
+ -e USER_NAME=linuxserver.io \
162
+ --restart unless-stopped \
163
+ lscr.io/linuxserver/openssh-server:latest
164
+ docker exec openssh-server sh -c "hostname -i" > ip.txt
165
+ echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
166
+ cat ip.txt >> $GITHUB_ENV
167
+ echo "EOF" >> $GITHUB_ENV
168
+ echo "======= container ip address ========="
169
+ cat ip.txt
170
+ echo "======================================"
171
+ sleep 2
172
+
80
173
- name : ssh key passphrase
81
174
uses : ./
82
175
with :
83
- host : ${{ secrets.HOST }}
84
- username : ${{ secrets.USERNAME }}
85
- key : ${{ secrets.SSH2 }}
86
- port : ${{ secrets.PORT }}
87
- passphrase : ${{ secrets.PASSPHRASE }}
176
+ host : ${{ env.REMOTE_HOST }}
177
+ username : linuxserver.io
178
+ key : ${{ env.PRIVATE_KEY }}
179
+ port : 2222
180
+ passphrase : 1234
88
181
script : |
89
182
whoami
90
183
ls -al
91
184
92
- - name : use insecure cipher
185
+ - name : missing ssh key passphrase
93
186
uses : ./
187
+ continue-on-error : true
94
188
with :
95
- host : ${{ secrets.HOST }}
96
- username : ${{ secrets.USERNAME }}
97
- password : ${{ secrets.PASSWORD }}
98
- port : ${{ secrets.PORT }}
189
+ host : ${{ env.REMOTE_HOST }}
190
+ username : linuxserver.io
191
+ key : ${{ env.PRIVATE_KEY }}
192
+ port : 2222
99
193
script : |
100
- ls \
101
- -lah
102
- use_insecure_cipher : true
194
+ whoami
195
+ ls -al
103
196
104
197
# https://github.com/appleboy/ssh-action/issues/75#issuecomment-668314271
105
198
- name : Multiline SSH commands interpreted as single lines
106
199
uses : ./
107
200
with :
108
- host : ${{ secrets.HOST }}
109
- username : ${{ secrets.USERNAME }}
110
- password : ${{ secrets.PASSWORD }}
111
- port : ${{ secrets.PORT }}
201
+ host : ${{ env.REMOTE_HOST }}
202
+ username : linuxserver.io
203
+ key : ${{ env.PRIVATE_KEY }}
204
+ port : 2222
205
+ passphrase : 1234
112
206
script_stop : true
113
207
script : |
114
208
ls \
115
209
-lah
116
210
use_insecure_cipher : true
117
211
212
+ multiple-server :
213
+ runs-on : ubuntu-latest
214
+ steps :
215
+ - name : Checkout code
216
+ uses : actions/checkout@v4
217
+
218
+ - name : add public key to env
219
+ run : |
220
+ echo "PUBLIC_KEY<<EOF" >> $GITHUB_ENV
221
+ cat testdata/.ssh/id_passphrase.pub >> $GITHUB_ENV
222
+ echo "EOF" >> $GITHUB_ENV
223
+ echo "======= public key ========="
224
+ cat testdata/.ssh/id_passphrase.pub
225
+ echo "============================"
226
+ echo "PRIVATE_KEY<<EOF" >> $GITHUB_ENV
227
+ cat testdata/.ssh/id_passphrase >> $GITHUB_ENV
228
+ echo "EOF" >> $GITHUB_ENV
229
+ echo "======= private key ========="
230
+ cat testdata/.ssh/id_passphrase
231
+ echo "============================"
232
+
233
+ - name : create new ssh server
234
+ run : |
235
+ docker run -d \
236
+ --name=openssh-server-01 \
237
+ --hostname=openssh-server-01 \
238
+ -p 2222:2222 \
239
+ -e PUBLIC_KEY="${{ env.PUBLIC_KEY }}" \
240
+ -e SUDO_ACCESS=false \
241
+ -e PASSWORD_ACCESS=true \
242
+ -e USER_PASSWORD=password \
243
+ -e USER_NAME=linuxserver.io \
244
+ --restart unless-stopped \
245
+ lscr.io/linuxserver/openssh-server:latest
246
+ docker exec openssh-server-01 sh -c "hostname -i" > ip01.txt
247
+ echo "REMOTE_HOST_01<<EOF" >> $GITHUB_ENV
248
+ cat ip01.txt >> $GITHUB_ENV
249
+ echo "EOF" >> $GITHUB_ENV
250
+ echo "======= container ip address ========="
251
+ cat ip01.txt
252
+ echo "======================================"
253
+
254
+ docker run -d \
255
+ --name=openssh-server-02 \
256
+ --hostname=openssh-server-02 \
257
+ -p 2223:2222 \
258
+ -e PUBLIC_KEY="${{ env.PUBLIC_KEY }}" \
259
+ -e SUDO_ACCESS=false \
260
+ -e PASSWORD_ACCESS=true \
261
+ -e USER_PASSWORD=password \
262
+ -e USER_NAME=linuxserver.io \
263
+ --restart unless-stopped \
264
+ lscr.io/linuxserver/openssh-server:latest
265
+ docker exec openssh-server-02 sh -c "hostname -i" > ip02.txt
266
+ echo "REMOTE_HOST_02<<EOF" >> $GITHUB_ENV
267
+ cat ip02.txt >> $GITHUB_ENV
268
+ echo "EOF" >> $GITHUB_ENV
269
+ echo "======= container ip address ========="
270
+ cat ip02.txt
271
+ echo "======================================"
272
+
273
+ sleep 2
274
+
118
275
# https://github.com/appleboy/ssh-action/issues/85
119
276
- name : Deployment to multiple hosts with different ports
120
277
uses : ./
121
278
with :
122
- host : " ${{ secrets.HOST }}:${{ secrets.PORT }}"
123
- username : ${{ secrets.USERNAME }}
124
- password : ${{ secrets.PASSWORD }}
125
- port : 1024
279
+ host : " ${{ env.REMOTE_HOST_01 }}:2222, ${{ env.REMOTE_HOST_02 }}:2222 "
280
+ username : linuxserver.io
281
+ key : ${{ env.PRIVATE_KEY }}
282
+ passphrase : 1234
126
283
script_stop : true
127
284
script : |
128
- ls \
129
- -lah
130
- use_insecure_cipher : true
285
+ whoami
131
286
132
- # - name: SSH ED25519 Private Key
133
- # uses: ./
134
- # with:
135
- # host: ${{ secrets.TUNNEL_HOST }}
136
- # username: ${{ secrets.TUNNEL_USERNAME }}
137
- # key: ${{ secrets.ID_ED25519 }}
138
- # port: ${{ secrets.TUNNEL_PORT }}
139
- # script: whoami
140
-
141
- testing02 :
142
- name : testing with envs
287
+ support-ed25519-key :
143
288
runs-on : ubuntu-latest
144
289
steps :
145
- - name : checkout
290
+ - name : Checkout code
146
291
uses : actions/checkout@v4
147
292
293
+ - name : add public key to env
294
+ run : |
295
+ echo "PUBLIC_KEY<<EOF" >> $GITHUB_ENV
296
+ cat testdata/.ssh/id_ed25519.pub >> $GITHUB_ENV
297
+ echo "EOF" >> $GITHUB_ENV
298
+ echo "======= public key ========="
299
+ cat testdata/.ssh/id_ed25519.pub
300
+ echo "============================"
301
+ echo "PRIVATE_KEY<<EOF" >> $GITHUB_ENV
302
+ cat testdata/.ssh/id_ed25519 >> $GITHUB_ENV
303
+ echo "EOF" >> $GITHUB_ENV
304
+ echo "======= private key ========="
305
+ cat testdata/.ssh/id_ed25519
306
+ echo "============================"
307
+
308
+ - name : create new ssh server
309
+ run : |
310
+ docker run -d \
311
+ --name=openssh-server \
312
+ --hostname=openssh-server \
313
+ -p 2222:2222 \
314
+ -e PUBLIC_KEY="${{ env.PUBLIC_KEY }}" \
315
+ -e SUDO_ACCESS=false \
316
+ -e PASSWORD_ACCESS=true \
317
+ -e USER_PASSWORD=password \
318
+ -e USER_NAME=linuxserver.io \
319
+ --restart unless-stopped \
320
+ lscr.io/linuxserver/openssh-server:latest
321
+ docker exec openssh-server sh -c "hostname -i" > ip.txt
322
+ echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
323
+ cat ip.txt >> $GITHUB_ENV
324
+ echo "EOF" >> $GITHUB_ENV
325
+ echo "======= container ip address ========="
326
+ cat ip.txt
327
+ echo "======================================"
328
+ sleep 2
329
+
330
+ - name : testing id_ed25519 key
331
+ uses : ./
332
+ with :
333
+ host : ${{ env.REMOTE_HOST }}
334
+ username : linuxserver.io
335
+ key : ${{ env.PRIVATE_KEY }}
336
+ port : 2222
337
+ script : |
338
+ whoami
339
+ ls -al
340
+
341
+ testing-with-env :
342
+ runs-on : ubuntu-latest
343
+ steps :
344
+ - name : Checkout code
345
+ uses : actions/checkout@v4
346
+
347
+ - name : add public key to env
348
+ run : |
349
+ echo "PUBLIC_KEY<<EOF" >> $GITHUB_ENV
350
+ cat testdata/.ssh/id_ed25519.pub >> $GITHUB_ENV
351
+ echo "EOF" >> $GITHUB_ENV
352
+ echo "======= public key ========="
353
+ cat testdata/.ssh/id_ed25519.pub
354
+ echo "============================"
355
+ echo "PRIVATE_KEY<<EOF" >> $GITHUB_ENV
356
+ cat testdata/.ssh/id_ed25519 >> $GITHUB_ENV
357
+ echo "EOF" >> $GITHUB_ENV
358
+ echo "======= private key ========="
359
+ cat testdata/.ssh/id_ed25519
360
+ echo "============================"
361
+
362
+ - name : create new ssh server
363
+ run : |
364
+ docker run -d \
365
+ --name=openssh-server \
366
+ --hostname=openssh-server \
367
+ -p 2222:2222 \
368
+ -e PUBLIC_KEY="${{ env.PUBLIC_KEY }}" \
369
+ -e SUDO_ACCESS=true \
370
+ -e PASSWORD_ACCESS=true \
371
+ -e USER_NAME=linuxserver.io \
372
+ --restart unless-stopped \
373
+ lscr.io/linuxserver/openssh-server:latest
374
+ docker exec openssh-server sh -c "hostname -i" > ip.txt
375
+ echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
376
+ cat ip.txt >> $GITHUB_ENV
377
+ echo "EOF" >> $GITHUB_ENV
378
+ echo "======= container ip address ========="
379
+ cat ip.txt
380
+ echo "======================================"
381
+ sleep 2
382
+
383
+ - name : testing id_ed25519 key
384
+ uses : ./
385
+ with :
386
+ host : ${{ env.REMOTE_HOST }}
387
+ username : linuxserver.io
388
+ key : ${{ env.PRIVATE_KEY }}
389
+ port : 2222
390
+ script : |
391
+ whoami
392
+ ls -al
393
+
148
394
- name : pass environment
149
395
uses : ./
150
396
env :
151
397
FOO : " BAR"
152
398
with :
153
- host : ${{ secrets.HOST }}
154
- username : ${{ secrets.USERNAME }}
155
- key : ${{ secrets.KEY }}
156
- port : ${{ secrets.PORT }}
399
+ host : ${{ env.REMOTE_HOST }}
400
+ username : linuxserver.io
401
+ key : ${{ env.PRIVATE_KEY }}
402
+ port : 2222
157
403
envs : FOO
158
404
script : |
159
405
echo "I am $FOO, thanks"
@@ -167,28 +413,27 @@ jobs:
167
413
SHA : ${{ github.sha }}
168
414
PORT : ${{ secrets.PORT }}
169
415
with :
170
- host : ${{ secrets.HOST }}
171
- username : ${{ secrets.USERNAME }}
172
- key : ${{ secrets.KEY }}
173
- port : ${{ secrets.PORT }}
416
+ host : ${{ env.REMOTE_HOST }}
417
+ username : linuxserver.io
418
+ key : ${{ env.PRIVATE_KEY }}
419
+ port : 2222
174
420
envs : FOO,BAR,SHA,PORT
175
421
script : |
176
422
echo "I am $FOO, thanks"
177
423
echo "I am $BAR, thanks"
178
424
echo "sha: $SHA"
179
425
echo "port: $PORT"
180
- sh test.sh
181
426
182
427
- name : custom envs format
183
428
uses : ./
184
429
env :
185
430
FOO : " BAR"
186
431
AAA : " BBB"
187
432
with :
188
- host : ${{ secrets.HOST }}
189
- username : ${{ secrets.USERNAME }}
190
- key : ${{ secrets.KEY }}
191
- port : ${{ secrets.PORT }}
433
+ host : ${{ env.REMOTE_HOST }}
434
+ username : linuxserver.io
435
+ key : ${{ env.PRIVATE_KEY }}
436
+ port : 2222
192
437
envs : FOO,BAR,AAA
193
438
envs_format : export TEST_{NAME}={VALUE}
194
439
script : |
@@ -203,79 +448,24 @@ jobs:
203
448
INPUT_FOO : " BAR"
204
449
INPUT_AAA : " BBB"
205
450
with :
206
- host : ${{ secrets.HOST }}
207
- username : ${{ secrets.USERNAME }}
208
- key : ${{ secrets.KEY }}
209
- port : ${{ secrets.PORT }}
451
+ host : ${{ env.REMOTE_HOST }}
452
+ username : linuxserver.io
453
+ key : ${{ env.PRIVATE_KEY }}
454
+ port : 2222
210
455
allenvs : true
211
456
script : |
212
457
echo "I am $INPUT_FOO, thanks"
213
458
echo "I am $INPUT_AAA, thanks"
214
459
echo "$GITHUB_BASE_REF"
215
460
echo "$GITHUB_REF"
216
461
217
- testing03 :
218
- name : git clone and pull
219
- runs-on : ubuntu-latest
220
- steps :
221
- - name : checkout
222
- uses : actions/checkout@v4
223
-
224
- - name : clone private repository
225
- uses : ./
226
- with :
227
- host : ${{ secrets.HOST }}
228
- username : ${{ secrets.USERNAME }}
229
- key : ${{ secrets.KEY }}
230
- port : ${{ secrets.PORT }}
231
- script_stop : true
232
- script : |
233
- git clone https://appleboy:${{ secrets.TEST_TOKEN }}@github.com/go-training/self-runner.git test_repository
234
- rm -rf test_repository
235
-
236
- testing04 :
237
- name : docker login and pull
238
- runs-on : ubuntu-latest
239
- steps :
240
- - name : checkout
241
- uses : actions/checkout@v4
242
-
243
- - name : login GitHub Container Registry
244
- uses : ./
245
- with :
246
- host : ${{ secrets.HOST }}
247
- username : ${{ secrets.USERNAME }}
248
- key : ${{ secrets.KEY }}
249
- port : ${{ secrets.PORT }}
250
- script_stop : true
251
- script : |
252
- echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u github.actor --password-stdin
253
-
254
- - name : login DockerHub Container Registry
255
- uses : ./
256
- with :
257
- host : ${{ secrets.HOST }}
258
- username : ${{ secrets.USERNAME }}
259
- key : ${{ secrets.KEY }}
260
- port : ${{ secrets.PORT }}
261
- script_stop : true
262
- script : |
263
- echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
264
-
265
- testing05 :
266
- name : switch user
267
- runs-on : ubuntu-latest
268
- steps :
269
- - name : checkout
270
- uses : actions/checkout@v4
271
-
272
462
- name : switch to root user
273
463
uses : ./
274
464
with :
275
- host : ${{ secrets.HOST }}
276
- username : ${{ secrets.USERNAME }}
277
- key : ${{ secrets.KEY }}
278
- port : ${{ secrets.PORT }}
465
+ host : ${{ env.REMOTE_HOST }}
466
+ username : linuxserver.io
467
+ key : ${{ env.PRIVATE_KEY }}
468
+ port : 2222
279
469
script_stop : true
280
470
request_pty : true
281
471
command_timeout : 30s
0 commit comments