-
Notifications
You must be signed in to change notification settings - Fork 0
76 lines (68 loc) · 2.14 KB
/
remote-sync.yml
File metadata and controls
76 lines (68 loc) · 2.14 KB
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
name: Sync Folders to Server
on:
workflow_call:
inputs:
host:
required: true
type: string
username:
required: true
type: string
folder:
required: true
type: string
paths:
required: false
type: string
default: |
[
{"from": "languages", "to": "/languages/"},
{"from": "mu-plugins", "to": "/mu-plugins/"},
{"from": "plugins", "to": "/plugins/"},
{"from": "themes", "to": "/themes/"}
]
description: "JSON array of {from: '', to: '', exclude: ''} objects"
artifact_name:
type: string
required: false
default: ''
secrets:
ssh-key:
required: true
jobs:
deploy:
runs-on: ubuntu-latest
strategy:
matrix:
sync_pair: ${{ fromJson(inputs.paths) }}
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Download Build Artifacts
if: ${{ inputs.artifact_name != '' }}
uses: actions/download-artifact@v4
with:
name: ${{ inputs.artifact_name }}
path: .
- name: Setup SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.ssh-key }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -t rsa ${{ inputs.host }} >> ~/.ssh/known_hosts
- name: Sync ${{ matrix.sync_pair.from }}
run: |
if [ ! -d "./${{ matrix.sync_pair.from }}" ] && [ ! -f "./${{ matrix.sync_pair.from }}" ]; then
echo "Source ${{ matrix.sync_pair.from }} not found. Skip."
exit 0
fi
EXCLUDE_ARGS=""
if [ -n "${{ matrix.sync_pair.exclude }}" ]; then
for item in ${{ matrix.sync_pair.exclude }}; do
EXCLUDE_ARGS="$EXCLUDE_ARGS --exclude=$item"
done
fi
CLEAN_FOLDER=$(echo "${{ inputs.folder }}" | sed 's:/*$::')
rsync -rvz $EXCLUDE_ARGS -e "ssh -i ~/.ssh/id_rsa" \
"./${{ matrix.sync_pair.from }}/" \
${{ inputs.username }}@${{ inputs.host }}:"$CLEAN_FOLDER${{ matrix.sync_pair.to }}"