Skip to content

Sync hostfiles

Sync hostfiles #310

Workflow file for this run

name: Sync hostfiles
on:
schedule:
- cron: '17 * * * *'
workflow_dispatch:
concurrency:
group: sync-hostfiles
cancel-in-progress: false
permissions:
contents: write
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: 'true'
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Fetch hostfiles
env:
UA: ${{ secrets.REFCHECK_USER_AGENT }}
run: |
if [ -z "$UA" ]; then
echo "REFCHECK_USER_AGENT secret is not set." >&2
exit 1
fi
for f in M17Hosts.txt M17Hosts.json; do
curl --fail --show-error --silent \
--retry 5 --retry-delay 10 --retry-all-errors \
--max-time 60 \
-A "$UA" \
-o "$f.new" \
"https://hostfiles.refcheck.radio/$f"
done
- name: Replace if changed
id: diff
run: |
for f in M17Hosts.txt M17Hosts.json; do
if [ ! -s "$f.new" ]; then
echo "$f: fetched file is empty; aborting." >&2
exit 1
fi
if [ ! -f "$f" ] || ! cmp -s "$f" "$f.new"; then
mv "$f.new" "$f"
else
rm "$f.new"
fi
done
if [ -n "$(git status --porcelain -- M17Hosts.txt M17Hosts.json)" ]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
fi
- name: Commit and push
if: steps.diff.outputs.changed == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add M17Hosts.txt M17Hosts.json
files=$(git diff --cached --name-only | paste -sd, -)
git commit -m "sync: ${files} $(date -u +%Y-%m-%dT%H:%MZ)"
git push