Skip to content

Auto-updating Blocklists #68

Auto-updating Blocklists

Auto-updating Blocklists #68

Workflow file for this run

name: Auto-updating Blocklists
on:
schedule:
- cron: '0 0 * * 0'
workflow_dispatch:
push:
branches:
- '*'
env:
GIT_USER_NAME: yqhr
GIT_USER_EMAIL: [email protected]
DEFAULT_BRANCH: main
jobs:
update-blocklists:
runs-on: ubuntu-latest
steps:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Checkout Repository
uses: actions/checkout@v3
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
python -m pip install requests
npm update npm
npm i -g @adguard/hostlist-compiler
- name: Update Blocklist
run: |
echo "Generating config.json"
python update.py
echo "Creating AdGuard Home's blocklist"
hostlist-compiler -c config-block.json -v -o blocklist.txt
echo "Remove Headers & Comments"
temp=$(mktemp)
cat blocklist.txt | sed '/#/d' | sed '/!/d' > $temp
echo "Remove Blank/Empty Lines"
sed '/^$/d' -i $temp
mv $temp blocklist.txt
rm -f config-block.json temp_adblock.txt
echo "Make domains.txt"
sed -e "s/||\(.*\)\^/\1/g" blocklist.txt > domains.txt
echo "Make hosts.txt"
sed -e "s/||\(.*\)\^/0\.0\.0\.0 \1/g" blocklist.txt > hosts.txt
echo "Rename blocklist"
mv blocklist.txt adblock.txt
rm package-lock.json
- name: Configure Git
run: |
git config --local user.email "${{ env.GIT_USER_EMAIL }}"
git config --local user.name "${{ env.GIT_USER_NAME }}"
- name: Commit and Push Changes
run: |
git add .
if ! git status | grep "nothing to commit"; then
git commit -m "Update blocklists"
git pull
git push origin ${{ env.DEFAULT_BRANCH }}
else
echo "No changes detected, skipping commit and push."
fi