Adblack_update #184
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: Adblack_update | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 21 * * *" | |
jobs: | |
update: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@main | |
- name: Set up time zone | |
run: sudo timedatectl set-timezone Asia/Shanghai | |
- name: Download Rule | |
run: | | |
echo 下载anti-AD | |
curl -kfSL -o adblack.txt https://raw.githubusercontent.com/privacy-protection-tools/anti-AD/master/anti-ad-surge.txt | |
echo 下载自用黑名单 | |
curl -kfSL -o blacklist.txt https://raw.githubusercontent.com/mphin/AdGuardHomeRules/main/Blacklist.txt | |
echo 下载自用白名单 | |
curl -kfSL -o allowlist.txt https://raw.githubusercontent.com/mphin/AdGuardHomeRules/main/Allowlist.txt | |
- name: Process Rule File | |
run: | | |
sed -i '/^[#!]/d' adblack.txt | |
echo 处理黑名单,添加进主规则 | |
sed -i -e '/^[#!]/d' -e '/^[[:space:]]*$/d' -e 's/[||^@]//g' -e 's/^/DOMAIN-SUFFIX,/' blacklist.txt | |
cat blacklist.txt >> adblack.txt | |
echo 处理白名单,删除对应规则 | |
sed -i -e '/^[#!]/d' -e '/^[[:space:]]*$/d' -e 's/[||^@]//g' -e 's/^/DOMAIN-SUFFIX,/' allowlist.txt | |
while IFS= read -r line; do | |
sed -i "/$line/d" adblack.txt | |
done < allowlist.txt | |
echo 比较新规则和已存在规则 | |
if cmp -s adblack.txt <(sed '/^[#!]/d' "${{ github.workspace }}/rules/adblack.txt"); then | |
echo "未检测到更新,退出工作流程" | |
exit 0 | |
fi | |
echo 添加注释数量时间备注 | |
version=$(TZ=Asia/Shanghai date '+%Y年%m月%d日%H:%M:%S') | |
count=$(grep -e '^DOMAIN,' -e '^DOMAIN-SUFFIX,' -e '^IP-CIDR,' -e '^DOMAIN-KEYWORD,' adblack.txt | wc -l) | |
sed -i "1i\\# 内容: 🚫 广告过滤 规则集\\n# 备注: 以anti-AD为基础,添加自用规则,原作者: https://anti-ad.net/\\n# 更新: $version\\n# 数量: $count条" adblack.txt | |
echo 创建DOMAIN-SET格式规则 | |
cp adblack.txt adblack2.txt | |
sed -i 's/DOMAIN-SUFFIX,/\./g' adblack2.txt | |
mv adblack.txt adblack2.txt rules/ | |
- name: Commit And Push | |
run: | | |
git config --global user.email "mphin@qq.com" && git config --global user.name "Bot" | |
git add rules/adblack.txt rules/adblack2.txt && git commit -m "广告规则$(date +'%Y-%m-%d %H:%M')" || exit 0 | |
git push | |
- name: Cleanup Workflow | |
uses: Mattraks/delete-workflow-runs@main | |
with: | |
retain_days: 1 | |
keep_minimum_runs: 2 |