name: Build V2Ray rules dat files on: schedule: - cron: "0 22 * * *" push: branches: - master - hidden jobs: build: name: Build runs-on: ubuntu-latest steps: - name: Setup Go 1.14 uses: actions/setup-go@v1 with: go-version: 1.14 - name: Set $GOPATH and more variables run: | echo "::set-env name=RELEASE_NAME::Released on $(date +%Y%m%d%H%M)" echo "::set-env name=TAG_NAME::$(date +%Y%m%d%H%M)" echo "::set-env name=GEOIP_REPO::github.com/Loyalsoldier/geoip" echo "::set-env name=GEOSITE_REPO::github.com/v2ray/domain-list-community" echo "::set-env name=CHINA_DOMAINS_URL::https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf" echo "::set-env name=GOOGLE_DOMAINS_URL::https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/google.china.conf" echo "::set-env name=APPLE_DOMAINS_URL::https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf" echo "::set-env name=GFWLIST_DOMAINS_URL::https://cokebar.github.io/gfwlist2dnsmasq/gfwlist_domain.txt" echo "::set-env name=GREATFIRE_DOMAINS_URL::https://raw.githubusercontent.com/wongsyrone/domain-block-list/master/domains.txt" echo "::set-env name=GREATFIRE_DOMAINS_MINE_URL::https://raw.githubusercontent.com/Loyalsoldier/cn-blocked-domain/release/domains.txt" echo "::set-env name=PROFILES_URL::https://raw.githubusercontent.com/ConnersHua/Profiles/master/Shadow/Pro.conf" echo "::set-env name=GEQ1AN_RULES_APPLE_URL::https://raw.githubusercontent.com/GeQ1an/Rules/master/QuantumultX/Filter/Apple.list" echo "::set-env name=GEQ1AN_RULES_MICROSOFT_URL::https://raw.githubusercontent.com/GeQ1an/Rules/master/QuantumultX/Filter/Optional/Microsoft.list" echo "::set-env name=GEQ1AN_RULES_GLOBAL_MEDIA_URL::https://raw.githubusercontent.com/GeQ1an/Rules/master/QuantumultX/Filter/GMedia.list" echo "::set-env name=GEQ1AN_RULES_OUTSIDE_URL::https://raw.githubusercontent.com/GeQ1an/Rules/master/QuantumultX/Filter/Outside.list" echo "::set-env name=GEQ1AN_RULES_REJECT_URL::https://raw.githubusercontent.com/GeQ1an/Rules/master/QuantumultX/Filter/AdBlock.list" echo "::set-env name=LHIE1_RULES_PROXY_URL::https://raw.githubusercontent.com/lhie1/Rules/master/Surge/Surge%203/Provider/Proxy.list" echo "::set-env name=LHIE1_RULES_REJECT_URL::https://raw.githubusercontent.com/lhie1/Rules/master/Surge/Surge%203/Provider/Reject.list" echo "::set-env name=GOPATH::$(dirname $GITHUB_WORKSPACE)" echo "::add-path::$(dirname $GITHUB_WORKSPACE)/bin" shell: bash - name: Checkout the "hidden" branch uses: actions/checkout@v2 with: ref: hidden - name: Get GeoLite2 zip file run: | curl -L -o GeoLite2-Country-CSV.zip "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&license_key=JvbzLLx7qBZT&suffix=zip" unzip GeoLite2-Country-CSV.zip rm -f GeoLite2-Country-CSV.zip mv GeoLite2* geoip - name: Generate geoip.dat file run: | go get -u -v -insecure $GEOIP_REPO geoip --country=./geoip/GeoLite2-Country-Locations-en.csv --ipv4=./geoip/GeoLite2-Country-Blocks-IPv4.csv --ipv6=./geoip/GeoLite2-Country-Blocks-IPv6.csv --cnipv4url=https://raw.githubusercontent.com/17mon/china_ip_list/master/china_ip_list.txt mkdir -p ./publish mv ./geoip.dat ./publish/ - name: Download geosite project run: | go get -u -v -insecure $GEOSITE_REPO - name: Get and add direct domains into temp-direct.txt file run: | curl -sSL $CHINA_DOMAINS_URL | perl -ne '/^server=\/([^\/]+)\// && print "$1\n"' > temp-direct.txt - name: Get and add proxy domains into temp-proxy.txt file run: | curl -sSL $GFWLIST_DOMAINS_URL | perl -ne '/^((?=^.{3,255})[a-zA-Z0-9][-_a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-_a-zA-Z0-9]{0,62})+)/ && print "$1\n"' > temp-proxy.txt curl -sSL $GREATFIRE_DOMAINS_URL | perl -ne '/^((?=^.{3,255})[a-zA-Z0-9][-_a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-_a-zA-Z0-9]{0,62})+)/ && print "$1\n"' >> temp-proxy.txt curl -sSL $GREATFIRE_DOMAINS_MINE_URL | perl -ne '/^((?=^.{3,255})[a-zA-Z0-9][-_a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-_a-zA-Z0-9]{0,62})+)/ && print "$1\n"' >> temp-proxy.txt curl -sSL $GOOGLE_DOMAINS_URL | perl -ne '/^server=\/([^\/]+)\// && print "$1\n"' >> temp-proxy.txt curl -sSL $APPLE_DOMAINS_URL | perl -ne '/^server=\/([^\/]+)\// && print "$1\n"' >> temp-proxy.txt curl -sSL $PROFILES_URL | awk -F ',' '/^DOMAIN(,|\-SUFFIX,).+PROXY/ {print $2}' >> temp-proxy.txt curl -sSL $GEQ1AN_RULES_APPLE_URL | awk -F ',' '/^(HOST|DOMAIN)(,|\-SUFFIX,).+Apple/ {print $2}' >> temp-proxy.txt curl -sSL $GEQ1AN_RULES_MICROSOFT_URL | awk -F ',' '/^(HOST|DOMAIN)(,|\-SUFFIX,).+Microsoft/ {print $2}' >> temp-proxy.txt curl -sSL $GEQ1AN_RULES_GLOBAL_MEDIA_URL | awk -F ',' '/^(HOST|DOMAIN)(,|\-SUFFIX,).+GMedia/ {print $2}' >> temp-proxy.txt curl -sSL $GEQ1AN_RULES_OUTSIDE_URL | awk -F ',' '/^(HOST|DOMAIN)(,|\-SUFFIX,).+Outside/ {print $2}' >> temp-proxy.txt curl -sSL $LHIE1_RULES_PROXY_URL | awk -F ',' '/^(HOST|DOMAIN)(,|\-SUFFIX,).+/ {print $2}' >> temp-proxy.txt - name: Get and add reject domains into temp-reject.txt file run: | curl -sSL $PROFILES_URL | awk -F ',' '/^DOMAIN(,|\-SUFFIX,).+REJECT/ {print $2}' > temp-reject.txt curl -sSL $GEQ1AN_RULES_REJECT_URL | awk -F ',' '/^(HOST|DOMAIN)(,|\-SUFFIX,).+AdBlock/ {print $2}' >> temp-reject.txt curl -sSL $LHIE1_RULES_REJECT_URL | awk -F ',' '/^DOMAIN(,|\-SUFFIX,).+/ {print $2}' >> temp-reject.txt - name: Add proxy, direct and reject domains from "hidden" branch to appropriate temp files run: | cat proxy.txt >> temp-proxy.txt cat direct.txt >> temp-direct.txt cat reject.txt >> temp-reject.txt - name: Sort and generate redundant lists run: | cat temp-proxy.txt | sort --ignore-case -u | perl -ne '/^((?=^.{3,255})[a-zA-Z0-9][-_a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-_a-zA-Z0-9]{0,62})+)/ && print "$1\n"' > proxy-list-with-redundant cat temp-proxy.txt | sort --ignore-case -u | perl -ne 'print if not /^((?=^.{3,255})[a-zA-Z0-9][-_a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-_a-zA-Z0-9]{0,62})+)/' > proxy-excluse-list cat temp-direct.txt | sort --ignore-case -u | perl -ne '/^((?=^.{3,255})[a-zA-Z0-9][-_a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-_a-zA-Z0-9]{0,62})+)/ && print "$1\n"' > direct-list-with-redundant cat temp-direct.txt | sort --ignore-case -u | perl -ne 'print if not /^((?=^.{3,255})[a-zA-Z0-9][-_a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-_a-zA-Z0-9]{0,62})+)/' > direct-excluse-list cat temp-reject.txt | sort --ignore-case -u | perl -ne '/^((?=^.{3,255})[a-zA-Z0-9][-_a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-_a-zA-Z0-9]{0,62})+)/ && print "$1\n"' > reject-list-with-redundant cat temp-reject.txt | sort --ignore-case -u | perl -ne 'print if not /^((?=^.{3,255})[a-zA-Z0-9][-_a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-_a-zA-Z0-9]{0,62})+)/' > reject-excluse-list - name: Remove redundant domains run: | chmod +x findRedundantDomain.py ./findRedundantDomain.py ./direct-list-with-redundant ./direct-list-deleted-unsort ./findRedundantDomain.py ./proxy-list-with-redundant ./proxy-list-deleted-unsort ./findRedundantDomain.py ./reject-list-with-redundant ./reject-list-deleted-unsort [ ! -f "direct-list-deleted-unsort" ] && touch direct-list-deleted-unsort [ ! -f "proxy-list-deleted-unsort" ] && touch proxy-list-deleted-unsort [ ! -f "reject-list-deleted-unsort" ] && touch reject-list-deleted-unsort sort ./direct-list-deleted-unsort > ./direct-list-deleted-sort sort ./proxy-list-deleted-unsort > ./proxy-list-deleted-sort sort ./reject-list-deleted-unsort > ./reject-list-deleted-sort diff ./direct-list-deleted-sort ./direct-list-with-redundant | awk '/^>/{print $2}' > ./direct-list-without-redundant diff ./proxy-list-deleted-sort ./proxy-list-with-redundant | awk '/^>/{print $2}' > ./proxy-list-without-redundant diff ./reject-list-deleted-sort ./reject-list-with-redundant | awk '/^>/{print $2}' > ./reject-list-without-redundant - name: Remove domains from "need-to-remove" lists in "hidden" branch and remove domains end with ".cn" in proxy-list run: | diff ./direct-need-to-remove.txt ./direct-list-without-redundant | awk '/^>/{print $2}' > $GOPATH/src/$GEOSITE_REPO/data/direct-list diff ./proxy-need-to-remove.txt ./proxy-list-without-redundant | awk '/^>/{print $2}' | perl -ne 'print if not /\.cn$/' > $GOPATH/src/$GEOSITE_REPO/data/proxy-list diff ./reject-need-to-remove.txt ./reject-list-without-redundant | awk '/^>/{print $2}' > $GOPATH/src/$GEOSITE_REPO/data/reject-list - name: Add list into appropriate category file run: | cd $GOPATH/src/$GEOSITE_REPO/data echo "include:proxy-list" >> geolocation-\!cn echo "include:direct-list" >> cn echo "include:reject-list" >> category-ads-all - name: Build geosite.dat file run: | domain-list-community mv ./dlc.dat ./publish/geosite.dat mv ./*-excluse-list ./publish/ cp -f $GOPATH/src/$GEOSITE_REPO/data/{proxy,direct,reject}-list ./publish/ - name: Zip files and generate sha256 hash run: | cd ./publish zip rules.zip {proxy,direct,reject}-list *.dat sha256sum geoip.dat > geoip.dat.sha256sum sha256sum geosite.dat > geosite.dat.sha256sum sha256sum rules.zip > rules.zip.sha256sum - 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 git init git config --local user.name "${{ github.actor }}" git config --local user.email "${{ github.actor }}@users.noreply.github.com" 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