Update Allowlist_Earners.txt #9
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: AdRules_update | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- '*.txt' | |
workflow_dispatch: | |
jobs: | |
update: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up time zone | |
run: | | |
sudo timedatectl set-timezone Asia/Shanghai | |
- name: Checkout | |
uses: actions/checkout@main | |
- name: Get last commit SHA | |
id: last_commit | |
run: | | |
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_ENV | |
- name: Get changed files | |
id: file_list | |
run: | | |
COMMIT=${{ env.sha }} | |
URL="https://api.github.com/repos/${{ github.repository }}/compare/${COMMIT}^...${COMMIT}" | |
FILES=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" $URL | jq -r '.files[] | select(.filename | test("^.*\\.txt$")) | .filename') | |
if [ -z "$FILES" ]; then | |
FILES=$(find . -maxdepth 1 -name '*.txt') | |
fi | |
echo FILES=$FILES >> $GITHUB_OUTPUT | |
- name: Update files | |
run: | | |
echo "Updating files..." | |
FILES="${{ steps.file_list.outputs.FILES }}" | |
for file in $FILES; do | |
sed -i -e 's/>/>/g' -e 's/!/!/g' $file | |
sed -i -E '/^\s*$/! { /^[^!#]/ { /^.*\^$/! s/$/\^/ } }' $file | |
current_date=$(TZ=Asia/Shanghai date '+%Y%m%d%H%M') | |
count=$(grep -v -e '^$' -e '^!' -e '^#' $file | wc -l) | |
count_with_unit="${count}" | |
sed -i "s/^! Version: .*/! Version: $current_date/" $file | |
sed -i "s/^! Total lines: .*/! Total lines: $count_with_unit/" $file | |
temp_file=$(mktemp) | |
domain_list="" | |
while IFS= read -r line; do | |
if [[ ! $line =~ ^[!#[:space:]]*$ && $line =~ ^([a-zA-Z0-9.-]+|\|\||@@) ]]; then | |
domain_list="$domain_list"$'\n'"$line" | |
else | |
if [[ $domain_list ]]; then | |
echo "$domain_list" | sort | sed '/^$/d' >> "$temp_file" | |
domain_list="" | |
fi | |
echo "$line" >> "$temp_file" | |
fi | |
done < "$file" | |
if [[ $domain_list ]]; then | |
echo "$domain_list" | sort | sed '/^$/d' >> "$temp_file" | |
fi | |
mv "$temp_file" "$file" | |
done | |
- name: 更新 README | |
run: | | |
echo "Updating README.md..." | |
new_date=$(TZ='Asia/Shanghai' date +'%Y年%m月%d日%H:%M:%S') | |
count_1=$(grep -v -e '^$' -e '^!' -e '^#' *.txt | wc -l) | |
sed -i "s/最近更新: .*/最近更新: $new_date/" readme.md | |
sed -i "s/补充数量: .*/补充数量: $count_1条/" readme.md | |
- name: Commit And Push | |
run: | | |
git config --global user.email "[email protected]" && git config --global user.name "Bot" | |
git add . && git commit -m "日常更新$(date +'%Y-%m-%d %H:%M')" | |
git push | |
- name: Cleanup Workflow | |
uses: Mattraks/delete-workflow-runs@main | |
with: | |
retain_days: 1 | |
keep_minimum_runs: 2 |