Files
mirror/.github/workflows/rootfs-sync.yml
2022-06-14 13:20:07 +02:00

157 lines
4.5 KiB
YAML

name: Rootfs sync
on:
# schedule:
# - cron: '0 */24 * * *'
workflow_dispatch:
jobs:
Prepare:
runs-on: ubuntu-20.04
continue-on-error: true
if: ${{ github.repository_owner == 'armbian' }}
steps:
- name: Cut the job into n chunks
run: |
mkdir -p temp
rsync --exclude '*.current' rsync://rsync.armbian.com/dl/_rootfs/ | awk '{ print $5}' | tail -n +3 | shuf > temp/rootfs.chunk
split -d --number=l/40 --additional-suffix=.chunk --suffix-length=2 temp/rootfs.chunk temp/rootfs-
- name: Cache Gradle packages
uses: actions/cache@v2
env:
cache-name: cache-build
with:
path: temp
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.run_id }}
Cache: # short name because GH will expand with the matrix values
needs: [ Prepare ]
runs-on: ubuntu-20.04
continue-on-error: true
timeout-minutes: 480
strategy:
max-parallel: 1
fail-fast: false
matrix:
include:
- part: "00"
- part: "01"
- part: "02"
- part: "03"
- part: "04"
- part: "05"
- part: "06"
- part: "07"
- part: "08"
- part: "09"
- part: "10"
- part: "11"
- part: "12"
- part: "13"
- part: "14"
- part: "15"
- part: "16"
- part: "17"
- part: "18"
- part: "19"
- part: "20"
- part: "21"
- part: "22"
- part: "23"
- part: "24"
- part: "25"
- part: "26"
- part: "27"
- part: "28"
- part: "29"
- part: "30"
- part: "31"
- part: "32"
- part: "33"
- part: "34"
- part: "35"
- part: "36"
- part: "37"
- part: "38"
- part: "39"
steps:
- name: Install depen
run: sudo apt-get -y install parallel jq axel
- name: Cache Gradle packages
uses: actions/cache@v2
env:
cache-name: cache-build
with:
path: temp
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ github.run_id }}
- name: Download part
run: |
set +e
mkdir -p download
GITURL="${{ github.repository }}"
CHUNK="${{ matrix.part }}"
FILES=$(cat temp/rootfs-${CHUNK}.chunk)
MIRRORS=$(curl -sq http://redirect.armbian.com/mirrors | jq -Mr '.' | grep http | grep -v github | tr -d \"," " | sort | uniq)
for FILE in ${FILES[@]}
do
echo "Checking $FILE"
PARALLEL=$(
for k in ${MIRRORS[@]}
do
echo "${k}_rootfs/${FILE}"
done | parallel --halt now,fail=1 --jobs 32 wget -q --spider --timeout=15 --tries=3 --retry-connrefused {} 2>&1 >/dev/null)
if [[ -n "${PARALLEL}" ]]; then
REMOVE=$(echo $PARALLEL | egrep -o 'https?://[^ ]+/' | sed "s/_rootfs.*//" | sort | uniq)
for l in ${REMOVE[@]}; do
[[ "${DEBUG}" == yes ]] && echo "Removing mirror: $l"
echo "Error,$l,$FILE" >> mirror.log
done
fi
if ! wget -q --spider --timeout=15 --tries=3 --retry-connrefused https://github.com/${GITURL}/releases/download/_rootfs/${FILE} ; then
rsync -av rsync://rsync.armbian.com/dl/_rootfs/${FILE} download/
[[ $(ls -1 download | wc -l) -gt 0 ]] && echo "UPLOAD=true" >> $GITHUB_ENV
fi
done
ls -1 download
- name: Upload artefacts
if: ${{ env.UPLOAD == 'true' }}
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.UPLOAD }}
file: download/*
tag: "_rootfs"
overwrite: true
file_glob: true
- if: failure()
run: |
echo "REUPLOAD=true" >> $GITHUB_ENV
sleep 1800
- name: Upload artefacts
if: ${{ env.REUPLOAD == 'true' }}
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.UPLOAD }}
file: download/*
tag: "_rootfs"
overwrite: true
file_glob: true
- name: Upload logs
uses: actions/upload-artifact@v2
with:
name: logs
path: mirror.log