52 lines
2.1 KiB
YAML
52 lines
2.1 KiB
YAML
on:
|
|
workflow_dispatch:
|
|
|
|
schedule:
|
|
- cron: '0 */4 * * *'
|
|
|
|
jobs:
|
|
mirror-main:
|
|
name: Mirror main apks downstream
|
|
runs-on: x86_64
|
|
container:
|
|
image: alpine:latest
|
|
env:
|
|
upstream: https://dl-cdn.alpinelinux.org/alpine/edge/main
|
|
downstream: https://ayakael.net/api/packages/alpine/alpine/edge/main
|
|
steps:
|
|
- name: Environment setup
|
|
run: apk add grep coreutils gawk curl wget
|
|
- 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: |
|
|
! apk --allow-untrusted --update-cache --repositories-file /dev/null --repository $downstream update
|
|
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: |
|
|
wc -l missing | awk '{print $1}' > total
|
|
read total < total
|
|
count=1
|
|
while read pkgs; do
|
|
echo "[ $count / $total ] Sending $pkgs"
|
|
# github actions doesn't do double pipe error suppression, use !
|
|
! wget -q $upstream/x86_64/$pkgs.apk
|
|
# if it doesn't exist, it is because it failed to download.
|
|
if [ -f $pkgs.apk ]; then
|
|
result=`curl -s --user ${{ vars.CODE_FORGEJO_USER }}:${{ secrets.CODE_FORGEJO_TOKEN }} --upload-file $pkgs.apk $downstream`
|
|
if [ -n "$result" ]; then
|
|
echo $result
|
|
fi
|
|
rm -f $pkgs.apk
|
|
else
|
|
echo "Error: Couldn't download $pkgs"
|
|
fi
|
|
count=$(( count + 1 ))
|
|
done < missing
|