Skip to content

Commit d2128a5

Browse files
committed
Add option to sync incoming folders
1 parent 6943ffc commit d2128a5

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

.github/workflows/repository-sync.yml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
type: boolean
99
description: "Force synchronization"
1010
default: false
11+
move_images:
12+
type: boolean
13+
description: "Move images from incoming to /dl"
14+
default: false
1115

1216
concurrency:
1317
group: pipeline
@@ -41,7 +45,7 @@ jobs:
4145
run: |
4246
echo 'JSON_CONTENT<<EOF' >> $GITHUB_OUTPUT
4347
curl -H "Authorization: Token ${{ secrets.NETBOX_TOKEN }}" -H "Accept: application/json; indent=4" \
44-
"https://stuff.armbian.com/netbox/api/virtualization/virtual-machines/?limit=500&name__empty=false&device_role=Mirror&tag=push&tag=debs&status=failed&status=active" \
48+
"https://stuff.armbian.com/netbox/api/virtualization/virtual-machines/?limit=500&name__empty=false&device_role=Mirror&tag=push&tag=images&tag=debs&status=active" \
4549
| jq '.results[] | .name' | grep -v null | sed "s/\"//g" | jq -cnR '[inputs | select(length>0)]' | jq >> $GITHUB_OUTPUT
4650
echo 'EOF' >> $GITHUB_OUTPUT
4751
@@ -90,12 +94,37 @@ jobs:
9094
DATEDIFF=$(echo `stat -c%Y /outgoing/repository/public/armbian.key` - `date --date="$REMOTE_DATE" +%s` | bc)
9195
echo $DATEDIFF
9296
ssh-keygen -f "${HOME}/.ssh/known_hosts" -R "${{ matrix.node }}"
93-
if [[ "$target" == "debs" && "${DATEDIFF}" -gt 36000 || "${{ github.event.inputs.forced_sync }}" == "true" ]]; then
97+
98+
# sync packages
99+
if [[ "$target" == "debs" && "${DATEDIFF}" -gt 36000 || "${{ github.event.inputs.forced_sync }}" == "true" ]]; then
94100
echo "Synching $target" >> $GITHUB_STEP_SUMMARY
95101
rsync -ar --checksum --progress -e "ssh -p ${SERVER_PORT} -o StrictHostKeyChecking=accept-new" /outgoing/repository/public/ ${SERVER_USERNAME}@${{ matrix.node }}:${SERVER_PATH}/apt
96102
# delete at the end
97103
rsync -ar --checksum --progress --delete -e "ssh -p ${SERVER_PORT} -o StrictHostKeyChecking=accept-new" /outgoing/repository/public/ ${SERVER_USERNAME}@${{ matrix.node }}:${SERVER_PATH}/apt
98104
fi
105+
106+
# move images from incoming to stable download and push old to archive and from archive to oldarchive
107+
if [[ "$target" == "images" && "${{ github.event.inputs.move_images }}" == "true" ]]; then
108+
ssh -p ${SERVER_PORT} -o StrictHostKeyChecking=accept-new ${SERVER_USERNAME}@${{ matrix.node }} \
109+
"
110+
MOVING_PATHS=\$(find $SERVER_PATH/incoming/*/* -maxdepth 0 -type d 2>/dev/null | sed -r 's/^.*\/(.*)\$/\1/')
111+
for folder in \$MOVING_PATHS; do
112+
# move archive to old archive
113+
mkdir -p $SERVER_PATH/oldarchive/\$folder/archive/
114+
[[ -d $SERVER_PATH/archive/\$folder/archive/ ]] && mv $SERVER_PATH/archive/\$folder/archive/* $SERVER_PATH/oldarchive/\$folder/archive/
115+
# move current to archive
116+
mkdir -p $SERVER_PATH/archive/\$folder/archive/
117+
if [[ -d $SERVER_PATH/dl/\$folder/archive/ ]]; then
118+
mv $SERVER_PATH/dl/\$folder/archive/* $SERVER_PATH/archive/\$folder/archive/
119+
[[ $? -eq 0 && -n \"${SERVER_PATH}\" ]] && rm -rf $SERVER_PATH/dl/\$folder/
120+
fi
121+
done
122+
# move incoming to current
123+
if [[ -n \"\$MOVING_PATHS\" ]]; then
124+
mv ${SERVER_PATH}/incoming/*/* --target-directory=${SERVER_PATH}/dl
125+
fi
126+
"
127+
fi
99128
done
100129
101130
dispatch:

0 commit comments

Comments
 (0)