Skip to content

Commit 4e66609

Browse files
committed
Add option to sync incoming folders
1 parent 270c167 commit 4e66609

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

.github/workflows/repository-sync.yml

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@ 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

12-
concurrency:
13-
group: pipeline
14-
cancel-in-progress: false
16+
#concurrency:
17+
# group: pipeline
18+
# cancel-in-progress: false
1519

1620
jobs:
1721

@@ -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&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,11 +94,32 @@ 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
94-
echo "Synching $target" >> $GITHUB_STEP_SUMMARY
95-
rsync -ar --checksum --progress -e "ssh -p ${SERVER_PORT} -o StrictHostKeyChecking=accept-new" /outgoing/repository/public/ ${SERVER_USERNAME}@${{ matrix.node }}:${SERVER_PATH}/apt
96-
# delete at the end
97-
rsync -ar --checksum --progress --delete -e "ssh -p ${SERVER_PORT} -o StrictHostKeyChecking=accept-new" /outgoing/repository/public/ ${SERVER_USERNAME}@${{ matrix.node }}:${SERVER_PATH}/apt
97+
#if [[ "$target" == "debs" && "${DATEDIFF}" -gt 36000 || "${{ github.event.inputs.forced_sync }}" == "true" ]]; then
98+
# echo "Synching $target" >> $GITHUB_STEP_SUMMARY
99+
# rsync -ar --checksum --progress -e "ssh -p ${SERVER_PORT} -o StrictHostKeyChecking=accept-new" /outgoing/repository/public/ ${SERVER_USERNAME}@${{ matrix.node }}:${SERVER_PATH}/apt
100+
# # delete at the end
101+
# rsync -ar --checksum --progress --delete -e "ssh -p ${SERVER_PORT} -o StrictHostKeyChecking=accept-new" /outgoing/repository/public/ ${SERVER_USERNAME}@${{ matrix.node }}:${SERVER_PATH}/apt
102+
#fi
103+
if [[ "$target" == "images" && "${{ github.event.inputs.move_images }}" == "true" ]]; then
104+
ssh -p ${SERVER_PORT} -o StrictHostKeyChecking=accept-new ${SERVER_USERNAME}@${{ matrix.node }} \
105+
"
106+
MOVING_PATHS=\$(find $SERVER_PATH/incoming/*/* -maxdepth 0 -type d 2>/dev/null | sed -r 's/^.*\/(.*)\$/\1/')
107+
for folder in \$MOVING_PATHS; do
108+
# move archive to old archive
109+
mkdir -p $SERVER_PATH/oldarchive/\$folder/archive/
110+
[[ -d $SERVER_PATH/archive/\$folder/archive/ ]] && mv $SERVER_PATH/archive/\$folder/archive/* $SERVER_PATH/oldarchive/\$folder/archive/
111+
# move current to archive
112+
mkdir -p $SERVER_PATH/archive/\$folder/archive/
113+
if [[ -d $SERVER_PATH/dl/\$folder/archive/ ]]; then
114+
mv $SERVER_PATH/dl/\$folder/archive/* $SERVER_PATH/archive/\$folder/archive/
115+
[[ $? -eq 0 && -n \"${SERVER_PATH}\" ]] && rm -rf $SERVER_PATH/dl/\$folder/
116+
fi
117+
done
118+
# move incoming to current
119+
if [[ -n \"\$MOVING_PATHS\" ]]; then
120+
mv ${SERVER_PATH}/incoming/*/* --target-directory=${SERVER_PATH}/dl
121+
fi
122+
"
98123
fi
99124
done
100125

0 commit comments

Comments
 (0)