Skip to content

Generate routing rules for Surge #1701

Generate routing rules for Surge

Generate routing rules for Surge #1701

name: Generate routing rules for Surge
on:
workflow_dispatch:
schedule:
- cron: '0 23 * * *'
push:
branches:
- master
paths-ignore:
- "**/README.md"
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set variables
run: |
echo "RELEASE_NAME=Released on $(date +%Y%m%d%H%M)" >> $GITHUB_ENV
echo "TAG_NAME=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV
echo "telegram_cidr= https://raw.githubusercontent.com/Loyalsoldier/geoip/release/text/telegram.txt" >> $GITHUB_ENV
echo "anti_ad_surge=https://raw.githubusercontent.com/privacy-protection-tools/anti-AD/master/anti-ad-surge2.txt" >> $GITHUB_ENV
echo "mangoclover_reject=https://raw.githubusercontent.com/mangoclover/v2ray-rules-dat/release/reject-list.txt" >> $GITHUB_ENV
echo "custom_private=https://raw.githubusercontent.com/mangoclover/domain-list-custom/release/private.txt" >> $GITHUB_ENV
echo "annoyances_filter=https://raw.githubusercontent.com/geekdada/surge-list/master/domain-set/annoyances-filter.txt" >> $GITHUB_ENV
echo "base_filter=https://raw.githubusercontent.com/geekdada/surge-list/master/domain-set/base-filter.txt" >> $GITHUB_ENV
echo "chinese_filter=https://raw.githubusercontent.com/geekdada/surge-list/master/domain-set/chinese-filter.txt" >> $GITHUB_ENV
echo "social_media_filter=https://raw.githubusercontent.com/geekdada/surge-list/master/domain-set/social-media-filter.txt" >> $GITHUB_ENV
echo "tracking_protection_filter=https://raw.githubusercontent.com/geekdada/surge-list/master/domain-set/tracking-protection-filter.txt" >> $GITHUB_ENV
echo "adaway=https://raw.githubusercontent.com/geekdada/surge-list/master/domain-set/adaway.txt" >> $GITHUB_ENV
echo "neohosts=https://raw.githubusercontent.com/geekdada/surge-list/master/domain-set/neohosts.txt" >> $GITHUB_ENV
echo "Netflix= https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/Surge/Netflix/Netflix.list" >> $GITHUB_ENV
echo "China=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/Surge/China/China.list" >> $GITHUB_ENV
echo "mangoclover_direct=https://raw.githubusercontent.com/mangoclover/v2ray-rules-dat/release/direct-list.txt" >> $GITHUB_ENV
echo "mangoclover_proxy=https://raw.githubusercontent.com/mangoclover/v2ray-rules-dat/release/proxy-list.txt" >> $GITHUB_ENV
echo "felixonmars_apple=https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf" >> $GITHUB_ENV
echo "custom_icloud=https://raw.githubusercontent.com/mangoclover/domain-list-custom/release/icloud.txt" >> $GITHUB_ENV
shell: bash
- name: Checkout the default branch
uses: actions/checkout@v3
- name: Make directory
run: |
mkdir -p Domainset
mkdir -p Ruleset
mkdir -p dist
- name: Generate telegramcidr.txt file
run: |
curl -sSL ${telegram_cidr} | perl -ne '/^(\d{1,3}(\.\d{1,3}){3}\/\d{1,2})/ && print "IP-CIDR,$1\n"' > Domainset/telegramcidr.txt
curl -sSL ${telegram_cidr} | perl -ne '/^(\d{1,3}(\.\d{1,3}){3}\/\d{1,2})/ && print "IP-CIDR,$1\n"' > Ruleset/telegramcidr.list
curl -sSL ${telegram_cidr} | grep ":" | perl -ne '/(.+\/\d+)/ && print "IP-CIDR6,$1\n"' >> Domainset/telegramcidr.txt
curl -sSL ${telegram_cidr} | grep ":" | perl -ne '/(.+\/\d+)/ && print "IP-CIDR6,$1\n"' >> Ruleset/telegramcidr.list
- name: Generate anti-ad-surge file
run: |
curl -sSL ${mangoclover_reject} | grep -Ev "^(regexp|keyword):" | perl -ne '/^(domain:|full:)?([-_a-zA-Z0-9]+(\.[-_a-zA-Z0-9]+)*)/ && print ".$2\n"' > dist/ad-reject.txt
curl -sSL ${anti_ad_surge} | grep -v "#" > dist/anti-ad-surge.txt
curl https://raw.githubusercontent.com/mangoclover/target-AD/master/target-AD-surge2.txt | grep -v "#" > dist/anti-ad-surge2.txt
curl -sSL ${anti_ad_surge} | grep -v "#" > Domainset/anti-ad-surge.txt
awk 'FNR==1{print ""}{print}' dist/*.txt > dist/merge.txt
awk '!seen[$0]++' dist/merge.txt > dist/anti-ad-surge2.txt
cp -rf dist/anti-ad-surge2.txt ./Domainset/
- name: Generate annoyances-filter file
run: |
curl -sSL ${annoyances_filter} > Domainset/annoyances-filter.txt
- name: Generate base-filter file
run: |
curl -sSL ${base_filter} > Domainset/base-filter.txt
- name: Generate chinese-filter file
run: |
curl -sSL ${chinese_filter} > Domainset/chinese-filter.txt
- name: Generate social_media_filter file
run: |
curl -sSL ${social_media_filter} > Domainset/social-media-filter.txt
- name: Generate tracking-protection-filter file
run: |
curl -sSL ${tracking_protection_filter} > Domainset/tracking-protection-filter.txt
- name: Generate adaway file
run: |
curl -sSL ${adaway} > Domainset/adaway.txt
- name: Generate neohosts file
run: |
curl -sSL ${neohosts} > Domainset/neohosts.txt
- name: Generate Netflix file
run: |
curl -sSL ${Netflix} | grep -v "#" > Ruleset/Netflix.list
- name: Generate China file
run: |
curl -sSL ${China} | grep -v "#" > Ruleset/China.list
- name: Generate direct.txt file
run: |
curl -sSL ${mangoclover_direct} | grep -Ev "^(regexp|keyword):" | perl -ne '/^(full:)([-_a-zA-Z0-9]+(\.[-_a-zA-Z0-9]+)*)/ && print "$2\n"' > Domainset/direct.txt
curl -sSL ${mangoclover_direct} | grep -Ev "^(regexp|keyword|full):" | perl -ne '/^(domain:)?([-_a-zA-Z0-9]+(\.[-_a-zA-Z0-9]+)*)/ && print ".$2\n"' >> Domainset/direct.txt
- name: Generate proxy.txt file
run: |
curl -sSL ${mangoclover_proxy} | grep -Ev "^(regexp|keyword):" | perl -ne '/^(full:)([-_a-zA-Z0-9]+(\.[-_a-zA-Z0-9]+)*)/ && print "$2\n"' > Domainset/proxy.txt
curl -sSL ${mangoclover_proxy} | grep -Ev "^(regexp|keyword|full):" | perl -ne '/^(domain:)?([-_a-zA-Z0-9]+(\.[-_a-zA-Z0-9]+)*)/ && print ".$2\n"' >> Domainset/proxy.txt
- name: Generate apple.txt file
run: |
curl -sSL ${felixonmars_apple} | perl -ne '/^server=\/([^\/]+)\// && print ".$1\n"' > Domainset/apple.txt
curl -sSL ${felixonmars_apple} | perl -ne '/^server=\/([^\/]+)\// && print "DOMAIN-SUFFIX,$1\n"' > Ruleset/apple.list
- name: Generate icloud.txt file
run: |
curl -sSL ${custom_icloud} | grep -E "^full:" | awk -F ':' '{printf "%s\n", $2}' > Domainset/icloud.txt
curl -sSL ${custom_icloud} | grep -E "^domain:" | awk -F ':' '{printf ".%s\n", $2}' >> Domainset/icloud.txt
curl -sSL ${custom_icloud} | grep -E "^full:" | awk -F ':' '{printf "DOMAIN,%s\n", $2}' > Ruleset/icloud.list
curl -sSL ${custom_icloud} | grep -E "^domain:" | awk -F ':' '{printf "DOMAIN-SUFFIX,%s\n", $2}' >> Ruleset/icloud.list
- name: Generate private.txt file
run: |
curl -sSL ${custom_private} | awk -F ':' '/^full:/ {printf "%s\n", $2}' > Domainset/private.txt
curl -sSL ${custom_private} | awk -F ':' '/^domain:/ {printf ".%s\n", $2}' >> Domainset/private.txt
curl -sSL ${custom_private} | awk -F ':' '/^full:/ {printf "DOMAIN,%s\n", $2}' > Ruleset/private.list
curl -sSL ${custom_private} | awk -F ':' '/^domain:/ {printf "DOMAIN-SUFFIX,%s\n", $2}' >> Ruleset/private.list
- name: Move files to publish directory
run: |
mkdir -p publish
mv Ruleset ./publish/
mv Domainset ./publish/
- name: Release and upload assets
uses: softprops/action-gh-release@v1
with:
name: ${{ env.RELEASE_NAME }}
tag_name: ${{ env.TAG_NAME }}
draft: false
prerelease: false
files: |
./publish/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Git push assets to "release" branch
run: |
cd publish || exit 1
git init
git config --local user.name "github-action[bot]"
git config --local user.email "[email protected]"
git checkout -b release
git add .
git commit -m "${{ env.RELEASE_NAME }}"
git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"
git push -f -u origin release
- name: Purge jsdelivr CDN
run: |
cd publish || exit 1
for file in $(ls Domainset); do
curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@release/Domainset/${file}"
done
for file in $(ls Ruleset); do
curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@release/Ruleset/${file}"
done