Build geoip files #1325
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: 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@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: ./go.mod | |
- name: Set variables | |
run: | | |
echo "update_version=$(date -d '+8 hours' +%Y-%m-%d)" >> ${GITHUB_ENV} | |
echo "private=https://raw.githubusercontent.com/XIU2/TrackersListCollection/master/all.txt" >> $GITHUB_ENV | |
echo "cn=http://ftp.apnic.net/stats/apnic/delegated-apnic-latest" >> $GITHUB_ENV | |
echo "cn_asn=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/Surge/ChinaASN/ChinaASN.list" >> $GITHUB_ENV | |
shell: bash | |
- name: Generate private | |
run: | | |
mkdir -p ./data/ | |
curl -sSL ${private} | grep -E '\/[^A-Za-z]+\/' | awk -F'[/:]' '{print $4}' >> ./data/private | |
curl -sSL ${private} | grep '::' | awk -F'[][]' '{print $2}' >> ./data/private | |
- name: Generate cn and cn_ip | |
run: | | |
mkdir -p ./ips/ | |
curl -sSL ${cn} | awk -F '|' '/CN/&&/ipv4/ {print $4 "/" 32-log($5)/log(2)}' > ./ips/cn_ipv4.txt | |
cat ./ips/cn_ipv4.txt >> ./data/cn | |
curl -sSL ${cn} | awk -F '|' '/CN/&&/ipv6/ {print $4 "/" $5}' > ./ips/cn_ipv6.txt | |
cat ./ips/cn_ipv6.txt >> ./data/cn | |
- 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 db and metadb file | |
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" | |
geo convert ip -i v2ray -o sing -f "./${file}.db" "./${file}.dat" | |
done | |
- name: Move files | |
run: | | |
mkdir -p ./clash/ ./sing-box/ | |
cd ./output/ || exit 1 | |
for file in $(ls *.dat *.metadb); do | |
install -Dp "./${file}" ../clash/ | |
done | |
for file in $(ls *.db); do | |
install -Dp "./${file}" ../sing-box/ | |
done | |
- name: Move and generate files to branchs | |
run: | | |
mkdir -p ./tmp/ | |
mv -f ./output/Country*.mmdb ./clash/ | |
curl -sSL ${cn_asn} | grep -v '#' | sed 's/,no-resolve$//' > ./tmp/cn.list | |
for file in $(ls ./output/clash/classical/ | sed 's/\..*//'); do | |
grep -v 'payload:' "./output/clash/classical/${file}.txt" | sed 's/^ - //' >> "./tmp/${file}.list" | |
grep "\"${file}\":" ./config.json | awk -F'[][]' '{print $2}' | awk -F', ' '{for(i=1;i<=NF;i++){gsub(/"/, "", $i); gsub(/AS/, "", $i); print "IP-ASN,"$i}}' >> "./tmp/${file}.list" | |
sort --ignore-case -u "./tmp/${file}.list" > "./ips/${file}ip.list" | |
done | |
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: | | |
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 段列表更新于 ${update_version}" | |
git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}" | |
git push -f -u origin ips | |
- name: Release and upload `clash` assets | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
release_name: clash | |
tag: clash | |
overwrite: true | |
body: | | |
[Clash](https://github.com/Dreamacro/clash) geoip 文件 | |
geoip 文件更新于 ${{ env.update_version }} | |
file_glob: true | |
file: ./clash/* | |
- name: Release and upload `sing-box` assets | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
release_name: sing-box | |
tag: sing-box | |
overwrite: true | |
body: | | |
[sing-box](https://github.com/SagerNet/sing-box) geoip 文件 | |
geoip 文件更新于 ${{ env.update_version }} | |
file_glob: true | |
file: ./sing-box/* | |
- 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 ../clash/ || exit 1 | |
for file in $(ls); do | |
curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@clash/${file}" | |
done | |
cd ../sing-box/ || exit 1 | |
for file in $(ls); do | |
curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@sing-box/${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 |