Build geoip files #1834
This file contains hidden or 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: Build geoip files | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: "0 18 * * *" | |
| push: | |
| branches: | |
| - master | |
| paths-ignore: | |
| - ".gitignore" | |
| - "LICENSE" | |
| - "*.md" | |
| jobs: | |
| build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout codebase | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version-file: ./go.mod | |
| - name: Set variables | |
| run: | | |
| echo "update_version=$(date -d '+8 hours' +%Y-%m-%d)" >> ${GITHUB_ENV} | |
| echo "media=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/Clash/GlobalMedia/GlobalMedia.list" >> ${GITHUB_ENV} | |
| echo "games=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/Clash/Game/Game.list" >> ${GITHUB_ENV} | |
| echo "cn1=https://ispip.clang.cn/all_cn.txt" >> $GITHUB_ENV | |
| echo "cn2=https://ispip.clang.cn/all_cn_ipv6.txt" >> $GITHUB_ENV | |
| echo "cn_asn=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/Surge/ChinaASN/ChinaASN.list" >> $GITHUB_ENV | |
| shell: bash | |
| - name: Gererate `media` | |
| run: | | |
| mkdir -p ./data/ | |
| curl -sSL ${media} | perl -ne '/^(IP-CIDR.*),([^,]+),/ && print "$2\n"' > ./data/media | |
| - name: Gererate `games` | |
| run: | | |
| curl -sSL ${games} | perl -ne '/^(IP-CIDR.*),([^,]+),/ && print "$2\n"' > ./data/games | |
| - name: Generate `cn_ip` | |
| run: | | |
| mkdir -p ./ips/ | |
| curl -sSL ${cn1} > ./ips/cn_ipv4.txt | |
| curl -sSL ${cn2} > ./ips/cn_ipv6.txt | |
| - name: Get GeoLite2 | |
| env: | |
| LICENSE_KEY: ${{ secrets.MAXMIND_GEOLITE2_LICENSE }} | |
| run: | | |
| mkdir -p ./output/ ./geolite2/ | |
| curl -L "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&license_key=${LICENSE_KEY}&suffix=tar.gz" | tar -zx -C ./ | |
| curl -L "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=${LICENSE_KEY}&suffix=tar.gz" | tar -zx -C ./ | |
| curl -o ./GeoLite2-ASN-CSV.zip -L "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN-CSV&license_key=${LICENSE_KEY}&suffix=zip" | |
| curl -o ./GeoLite2-Country-CSV.zip -L "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&license_key=${LICENSE_KEY}&suffix=zip" | |
| unzip ./GeoLite2-ASN-CSV.zip | |
| unzip ./GeoLite2-Country-CSV.zip | |
| rm -f ./*.zip | |
| mv -f ./GeoLite2-Country_*/*.mmdb ./output/ | |
| mv -f ./GeoLite2-ASN_*/*.mmdb ./output/ | |
| mv -f ./GeoLite2-ASN-CSV_*/*.csv ./geolite2/ | |
| mv -f ./GeoLite2-Country-CSV_*/*.csv ./geolite2/ | |
| - name: Build geoip files | |
| run: | | |
| go build ./ | |
| ./geoip convert -c ./config.json | |
| - name: Verify mmdb files | |
| run: | | |
| cd ./output/ || exit 1 | |
| go install -v github.com/maxmind/mmdbverify@latest | |
| for name in $(ls *.mmdb); do | |
| $(go env GOPATH)/bin/mmdbverify -file ${name} | |
| done | |
| - name: Get geoip-all.dat and Country-all.mmdb relative files | |
| run: | | |
| curl -o ./output/geoip-all.dat -L https://raw.githubusercontent.com/Loyalsoldier/geoip/release/geoip.dat | |
| curl -o ./output/Country-all.mmdb -L https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country.mmdb | |
| curl -o ./output/Country-ASN-all.mmdb -L https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country-asn.mmdb | |
| - name: Build metadb files | |
| run: | | |
| cd ./output/ || exit 1 | |
| go install -trimpath -ldflags="-s -w -buildid=" github.com/metacubex/geo/cmd/geo@master | |
| for file in $(ls *.dat | sed 's/\..*//'); do | |
| geo convert ip -i v2ray -o meta -f "./${file}.metadb" "./${file}.dat" | |
| done | |
| - name: Move files | |
| run: | | |
| mkdir -p ./mihomo-geodata/ | |
| cd ./output/ || exit 1 | |
| for file in $(ls *.dat *.metadb); do | |
| install -Dp "./${file}" ../mihomo-geodata/ | |
| done | |
| - name: Move and generate files to branchs | |
| run: | | |
| mkdir -p ./tmp/ | |
| mv -f ./output/Country*.mmdb ./mihomo-geodata/ | |
| for file in $(ls ./output/clash/classical/ | sed 's/\..*//'); do | |
| cat "./output/clash/classical/${file}.txt" | perl -ne '/^\s*-\s+(.*)/ && print "$1\n"' > "./tmp/temp-${file}.list" | |
| sort --ignore-case "./tmp/temp-${file}.list" > "./ips/${file}ip.list" | |
| done | |
| cat ./config.json | grep '\"netflix\":' | grep -o 'AS[0-9]\+' | sed 's/^/IP-ASN,/' | sort --ignore-case > ./ips/netflix-asn.list | |
| cat ./config.json | grep '\"telegram\":' | grep -o 'AS[0-9]\+' | sed 's/^/IP-ASN,/' | sort --ignore-case > ./ips/telegram-asn.list | |
| curl -sSL ${cn_asn} | perl -ne '/^(IP-ASN,\d+),/ && print "$1\n"' | sort --ignore-case > ./ips/cn-asn.list | |
| rm -rf ./tmp* ./output* | |
| - name: Release and upload `ips` assets | |
| uses: svenstaro/upload-release-action@v2 | |
| with: | |
| repo_token: ${{ secrets.GITHUB_TOKEN }} | |
| release_name: ips | |
| tag: ips | |
| overwrite: true | |
| body: | | |
| 供下游项目 [DustinWin/ruleset_geodata](https://github.com/DustinWin/ruleset_geodata) 使用的 IP 数据源文件 | |
| [ShellCrash](https://github.com/juewuy/ShellCrash) 中 CN_IP 绕过内核所需文件 | |
| 文件更新于 ${{ env.update_version }} | |
| file_glob: true | |
| file: ./ips/* | |
| - name: Commit and push `ips` branch | |
| run: | | |
| cd ./ips/ || exit 1 | |
| git init | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git checkout -b ips | |
| git add . && git commit -m "IP 数据源文件和 CNIP 绕过内核文件更新于 ${update_version}" | |
| git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}" | |
| git push -f origin ips | |
| - name: Release and upload `mihomo-geodata` assets | |
| uses: svenstaro/upload-release-action@v2 | |
| with: | |
| repo_token: ${{ secrets.GITHUB_TOKEN }} | |
| release_name: mihomo-geodata | |
| tag: mihomo-geodata | |
| overwrite: true | |
| body: | | |
| [mihomo 内核](https://github.com/MetaCubeX/mihomo) geodata 文件 | |
| geodata 文件更新于 ${{ env.update_version }} | |
| file_glob: true | |
| file: ./mihomo-geodata/* | |
| - name: Commit and push `mihomo-geodata` branch | |
| run: | | |
| cd ./mihomo-geodata/ || exit 1 | |
| git init | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| git checkout -b mihomo-geodata | |
| git add . && git commit -m "mihomo 内核 geodata 文件更新于 ${update_version}" | |
| git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}" | |
| git push -f origin mihomo-geodata | |
| - name: Purge jsDelivr CDN | |
| run: | | |
| cd ./ips/ || exit 1 | |
| for file in $(ls); do | |
| curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@ips/${file}" | |
| done | |
| cd ../mihomo-geodata/ || exit 1 | |
| for file in $(ls); do | |
| curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@mihomo-geodata/${file}" | |
| done | |
| - name: Delete old workflow runs | |
| uses: Mattraks/delete-workflow-runs@v2 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| repository: ${{ github.repository }} | |
| retain_days: 3 | |
| keep_minimum_runs: 1 |