Skip to content

Merge pull request #7 from alexanderadam/fix/update_github_action #22

Merge pull request #7 from alexanderadam/fix/update_github_action

Merge pull request #7 from alexanderadam/fix/update_github_action #22

name: Update AdBlock List Metadata
on:
push:
branches:
- main
permissions:
contents: write
env:
FILENAME: alexanderadam.txt
jobs:
update-metadata:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4.1.7
- name: Setup Node.js
uses: actions/setup-node@v4.0.3
with:
node-version: '18'
- name: Install dependencies
run: yarn install
# https://github.com/AdguardTeam/AGLint?tab=readme-ov-file#introduction
- name: Run linting
run: yarn aglint ${{ env.FILENAME }}
- name: Update metadata
run: |
sed -i "s/! Last modified: .*/! Last modified: $(date +%Y-%m-%d)/" ${{ env.FILENAME }}
- name: Remove duplicated rules
run: |
awk '!seen[$0]++' ${{ env.FILENAME }} > temp && mv temp ${{ env.FILENAME }}
- name: Sort rules
run: |
awk 'BEGIN { header = 1 } /^[[:space:]]*$/ { header = 0 } header { print; next } /^[\[!]/ { print; next } { lines[NR] = $0 } END { n = asort(lines); for (i = 1; i <= n; i++) print lines[i] }' ${{ env.FILENAME }} > temp && mv temp ${{ env.FILENAME }}
- name: Extract affected hosts
run: |
echo -e "# Affected hosts\n\n" > hosts.md
# Download blocklists
blocklists=("torrent" "scam" "ransomware" "porn" "piracy" "phishing" "malware" "fraud")
for list in "${blocklists[@]}"; do
wget -q "https://blocklistproject.github.io/Lists/${list}.txt" -O "${list}.txt"
done
# Combine blocklists into one file, ignoring comments
grep -hv '^#' *.txt | awk '{print $2}' | sort -u > combined_blocklist.txt
# Extract affected hosts and filter against blocklist
grep -oP '^[^#]+(?=##)' ${{ env.FILENAME }} | sort -u | while read -r domain; do
if [[ "$domain" == *.* ]]; then
if ! grep -q "^${domain}$" combined_blocklist.txt; then
favicon_url="https://icons.duckduckgo.com/ip3/${domain}.ico"
if wget -q --spider "$favicon_url"; then
echo "- ![favicon](${favicon_url}) ${domain}" >> hosts.md
else
echo "- 🌐 ${domain}" >> hosts.md
fi
fi
fi
done
# Clean up blocklist files
rm -f *.txt combined_blocklist.txt
- name: Commit and push if changed
env:
ACTIONS_PAT: ${{ secrets.ACTIONS_PAT }}
run: |
git config --global user.email "action@github.com"
git config --global user.name "GitHub Action"
git add ${{ env.FILENAME }}
git add hosts.md
git commit -m "✏️ Update metadata" || exit 0 # Exit gracefully if no changes
git push https://x-access-token:${{ secrets.ACTIONS_PAT }}@github.com/alexanderadam/adblock_list.git