Merge TXT Files #11585
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: Merge TXT Files | |
on: | |
schedule: | |
- cron: '*/5 * * * *' | |
push: | |
branches: | |
- main | |
jobs: | |
merge_txt: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Download TXT files | |
run: | | |
mkdir -p downloads | |
FILES=( | |
"https://raw.githubusercontent.com/badmojr/1Hosts/master/mini/adblock.txt" | |
"https://raw.githubusercontent.com/AdguardTeam/AdguardFilters/master/BaseFilter/sections/adservers.txt" | |
"https://raw.githubusercontent.com/TG-Twilight/AWAvenue-Ads-Rule/main/AWAvenue-Ads-Rule.txt" | |
"https://raw.githubusercontent.com/hagezi/dns-blocklists/main/adblock/multi.txt" | |
"https://anti-ad.net/easylist.txt" | |
"https://big.oisd.nl" | |
"https://raw.githubusercontent.com/Cats-Team/AdRules/main/dns.txt" | |
"https://raw.githubusercontent.com/lingeringsound/10007_auto/master/adb.txt" | |
) | |
for FILE in "${FILES[@]}"; do | |
FILENAME=$(basename "$FILE") | |
wget -O "downloads/$FILENAME" "$FILE" | |
done | |
- name: Rename and merge files | |
run: | | |
cat downloads/*.txt > merged.txt | |
- name: Create output directory | |
run: | | |
mkdir -p 1 | |
- name: Remove comment lines and duplicate lines | |
run: | | |
LINE_COUNT=$(awk '!/^#|^!|^@@|^:/' merged.txt | sort | uniq | wc -l) | |
BEIJING_TIME=$(TZ='Asia/Shanghai' date '+%Y-%m-%d %H:%M:%S') | |
{ | |
echo "# 生成时间: $BEIJING_TIME" | |
echo "# 规则数量: $LINE_COUNT" | |
awk '!/^#|^!|^@@|^:/' merged.txt | sort | uniq | |
} > 1/1.txt | |
- name: Check if output file was created | |
run: | | |
ls -l 1/1.txt | |
- name: Add and commit changes | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "Your Name" | |
git add 1/1.txt | |
git status | |
if [ "$(git diff --cached --name-only)" ]; then | |
git commit -m "Add merged unique TXT file as 1.txt" | |
else | |
echo "No changes to commit" | |
fi | |
git push |