Mirror #10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: "Mirror" | |
run-name: "Mirror" | |
permissions: write-all | |
on: | |
workflow_dispatch: | |
push: | |
branches: [main] | |
paths: [.github/workflows/mirror.yml] | |
schedule: | |
- cron: "0 0 1 * *" # monthly | |
concurrency: | |
group: ${{ github.workflow_ref }} | |
cancel-in-progress: false | |
env: | |
GH_TOKEN: '${{ github.token }}' | |
GITHUB_TOKEN: '${{ github.token }}' | |
jobs: | |
mirror: | |
name: "Mirror" | |
runs-on: ubuntu-latest | |
steps: | |
- name: "Checkout" | |
uses: actions/checkout@v4 | |
- name: "Mirror" | |
run: | | |
while [ "${ENDPOINT}" ] | |
do | |
ENDPOINT="$(curl -sS "${ENDPOINT}" | tee "${TMP_FILE}" | jq --raw-output "${JQ_QUERY}")" | |
cat "${TMP_FILE}" | |
done | jq --slurp '[.[].results[]]' | tee "index.json" | jq --raw-output '.[].formats[]' | xargs -P256 -IURL wget --no-verbose --execute robots=off --random-wait --wait 10 --no-host-directories --force-directories URL | |
env: | |
ENDPOINT: 'https://gutendex.com/books/?languages=eo' | |
JQ_QUERY: '.next|tostring|sub("^null$"; ""; "i")' | |
TMP_FILE: '${{ runner.temp }}/results' | |
- name: "Add files" | |
run: git add . | |
- name: "Commit" | |
run: git commit --allow-empty --author="${GIT_COMMITTER_NAME} <${GIT_COMMITTER_EMAIL}>" --message="${MESSAGE}" | |
env: | |
GIT_COMMITTER_NAME: github-actions[bot] | |
GIT_COMMITTER_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com | |
MESSAGE: | | |
Automatic mirror update | |
- name: "Push" | |
run: git push |