Skip to content

Commit f106168

Browse files
committed
Mirror: apply several bug fixes
1 parent 229bd88 commit f106168

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

.github/workflows/mirror.yml

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ on:
66

77
env:
88
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9-
PULL_REPOSITORY: "${{ github.event.client_payload.pull_repository }}" # username/repository
10-
CDN_TAG: "${{ github.event.client_payload.cdn_tag }}" # folder on server
9+
PULL_REPOSITORY: "${{ github.event.client_payload.pull_repository || 'cli/cli' }}" # username/repository
10+
CDN_TAG: "${{ github.event.client_payload.cdn_tag || 'os' }}" # folder on server
1111
PULL_TAG: "" # leave empty for latest
1212

1313
jobs:
@@ -107,17 +107,40 @@ jobs:
107107
name: parts
108108
pattern: part*
109109
merge-multiple: true
110-
- name: "Make JSON"
110+
- name: "Clean older files on servers"
111111
id: json
112112
run: |
113113
LATEST=$(cat part*.json | jq -r '.[].tag' | sort | uniq)
114114
CDN_TAG=$(cat part*.json | jq -r '.[].cdn_tag' | sort | uniq)
115115
echo "Delete all except $LATEST on $CDN_TAG"
116116
tempfolder=$(mktemp -d)
117-
rsync --delete -e \
118-
"ssh -p 10023 -o StrictHostKeyChecking=accept-new" \
119-
-rvP ${tempfolder}/ "[email protected]:/storage/www/cache/${CDN_TAG}" --exclude=${LATEST}
120117
118+
# we use servers.json definitions that was build in main workflow
119+
# so we don't call API for every file
120+
for row in $( cat servers.json | jq -r '@base64'); do
121+
# Decode the base64 encoded JSON and extract values
122+
_jq() {
123+
echo ${row} | base64 --decode | jq -r ${1}
124+
}
125+
# Extract values from each item
126+
id=$(_jq '.id')
127+
name=$(_jq '.name')
128+
path=$(_jq '.custom_fields.path')
129+
port=$(_jq '.custom_fields.port')
130+
download_path_archive=$(_jq '.custom_fields.download_path_archive')
131+
download_path_debs=$(_jq '.custom_fields.download_path_debs')
132+
download_path_images=$(_jq '.custom_fields.download_path_images')
133+
known_hosts=$(_jq '.custom_fields.known_hosts')
134+
path=$(_jq '.custom_fields.path')
135+
port=$(_jq '.custom_fields.port')
136+
runners=$(_jq '.custom_fields.runners')
137+
username=$(_jq '.custom_fields.username')
138+
weight=$(_jq '.custom_fields.weight')
139+
# rsync
140+
rsync --delete -e \
141+
"ssh -p ${port} -o StrictHostKeyChecking=accept-new" \
142+
-rvP ${tempfolder}/ "${username}@${name}:${path}/cache/${CDN_TAG}" --exclude=${LATEST}
143+
done
121144
- uses: geekyeggo/delete-artifact@v5
122145
with:
123146
name: |

0 commit comments

Comments
 (0)