mirrorer/.forgejo/workflows/sync-community.yml

53 lines
2.1 KiB
YAML
Raw Permalink Normal View History

2024-10-16 02:46:03 +00:00
on:
workflow_dispatch:
2024-10-24 00:54:48 +00:00
schedule:
2024-10-23 19:42:18 +00:00
- cron: '0 */4 * * *'
2024-10-16 02:46:03 +00:00
jobs:
mirror-community:
name: Mirror community apks downstream
runs-on: x86_64
container:
image: alpine:latest
env:
upstream: https://dl-cdn.alpinelinux.org/alpine/edge/community
2024-10-16 11:37:50 +00:00
downstream: https://ayakael.net/api/packages/alpine/alpine/edge/community
2024-10-16 02:46:03 +00:00
steps:
- name: Environment setup
2024-10-21 12:31:54 +00:00
run: apk add grep coreutils gawk curl wget
2024-10-16 02:46:03 +00:00
- name: Fetch info from upstream
run: |
apk --allow-untrusted --update-cache --repositories-file /dev/null --repository $upstream update
apk --allow-untrusted --update-cache --repositories-file /dev/null --repository $upstream list | grep -v installed | awk '{print $1, $2}' | sort > upstream
- name: Fetch info from downstream
run: |
2024-10-23 12:37:41 +00:00
! apk --allow-untrusted --update-cache --repositories-file /dev/null --repository $downstream update
2024-10-16 02:46:03 +00:00
apk --allow-untrusted --update-cache --repositories-file /dev/null --repository $downstream list | grep -v installed | awk '{print $1, $2}' | sort > downstream
- name: Missing apks detection
run: |
comm -23 upstream downstream | awk '{print $1}' > missing
echo "Missing apks:"
cat missing
- name: Send missing packages downstream
run: |
2024-10-21 12:38:39 +00:00
wc -l missing | awk '{print $1}' > total
read total < total
2024-10-21 14:35:05 +00:00
count=1
2024-10-16 02:46:03 +00:00
while read pkgs; do
2024-10-21 12:36:03 +00:00
echo "[ $count / $total ] Sending $pkgs"
2024-10-23 12:37:41 +00:00
# github actions doesn't do double pipe error suppression, use !
2024-10-23 12:33:30 +00:00
! wget -q $upstream/x86_64/$pkgs.apk
2024-10-22 23:32:33 +00:00
# if it doesn't exist, it is because it failed to download.
if [ -f $pkgs.apk ]; then
2024-10-21 14:37:58 +00:00
result=`curl -s --user ${{ vars.CODE_FORGEJO_USER }}:${{ secrets.CODE_FORGEJO_TOKEN }} --upload-file $pkgs.apk $downstream`
2024-10-21 14:42:31 +00:00
if [ -n "$result" ]; then
2024-10-21 14:41:35 +00:00
echo $result
fi
2024-10-21 12:30:07 +00:00
rm -f $pkgs.apk
else
echo "Error: Couldn't download $pkgs"
fi
2024-10-21 14:35:05 +00:00
count=$(( count + 1 ))
2024-10-16 02:46:03 +00:00
done < missing