Skip to content

Commit

Permalink
Update geoip
Browse files Browse the repository at this point in the history
  • Loading branch information
DustinWin committed Nov 17, 2024
1 parent be06655 commit 7482029
Show file tree
Hide file tree
Showing 10 changed files with 318 additions and 2,183 deletions.
190 changes: 129 additions & 61 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ name: Build geoip files
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 4"
- cron: "0 18 * * *"
push:
branches:
- master
paths-ignore:
- ".gitignore"
- "LICENSE*"
- "LICENSE"
- "*.md"

jobs:
build:
name: Build
Expand All @@ -27,36 +28,42 @@ jobs:

- name: Set variables
run: |
echo "TAG_NAME=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV
echo "RELEASE_NAME=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV
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: Download GeoLite2 databases
env:
LICENSE_KEY: ${{ secrets.MAXMIND_GEOLITE2_LICENSE }}
- name: Generate private
run: |
mkdir -p output
curl -L "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&license_key=${LICENSE_KEY}&suffix=tar.gz" -o ./output/GeoLite2-ASN.tar.gz
curl -L "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN-CSV&license_key=${LICENSE_KEY}&suffix=zip" -o ./output/GeoLite2-ASN-CSV.zip
curl -L "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=${LICENSE_KEY}&suffix=tar.gz" -o ./output/GeoLite2-Country.tar.gz
curl -L "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&license_key=${LICENSE_KEY}&suffix=zip" -o ./output/GeoLite2-Country-CSV.zip
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: Prepare GeoLite2 databases
- name: Generate cn and cn_ip
run: |
cp ./output/{*.gz,*.zip} ./
unzip GeoLite2-Country-CSV.zip
unzip GeoLite2-ASN-CSV.zip
tar -xvzf GeoLite2-Country.tar.gz
tar -xvzf GeoLite2-ASN.tar.gz
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
cp GeoLite2-Country_*/*.mmdb ./output/
cp GeoLite2-ASN_*/*.mmdb ./output/
cp GeoLite2-Country-CSV_*/{GeoLite2-Country-Blocks-*,GeoLite2-Country-Locations-en,GeoLite2-Country-Locations-zh-CN}.csv ./output/
cp GeoLite2-ASN-CSV_*/*.csv ./output/
mkdir -p geolite2
cp GeoLite2-Country-CSV_*/*.csv ./geolite2/
cp GeoLite2-ASN-CSV_*/*.csv ./geolite2/
- 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: |
Expand All @@ -65,58 +72,119 @@ jobs:
- name: Verify mmdb files
run: |
cd ./output || exit 1
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: Generate sha256 checksum for dat files
- name: Get geoip-all.dat and Country-all.mmdb relative files
run: |
cd ./output || exit 1
for name in $(ls *.dat); do
sha256sum ${name} > ./${name}.sha256sum
done
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: Generate sha256 checksum for mmdb files
- name: Build db and metadb file
run: |
cd ./output || exit 1
for name in $(ls *.mmdb); do
sha256sum ${name} > ./${name}.sha256sum
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: Git push assets to "release" branch
- name: Move files
run: |
cd output || exit 1
git init
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -b release
git add -A
git commit -m "${{ env.RELEASE_NAME }}"
git remote add geoip "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"
git push -f -u geoip release
- name: Purge jsdelivr CDN
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: |
cd output || exit 1
for file in $(ls); do
curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@release/${file}"
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: Remove some files to avoid publishing to GitHub release
- 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: |
rm -rf ./output/*.{gz,zip}
rm -rf ./output/GeoLite2-*.csv
rm -rf ./output/GeoLite2-*.mmdb
rm -rf ./output/GeoLite2-*.sha256sum
rm -rf ./output/{clash,dat,mrs,nginx,srs,surge,text}
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: Upload files to GitHub release
- 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: ./output/*
release_name: ${{ env.RELEASE_NAME }}
tag: ${{ env.TAG_NAME }}
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
Loading

0 comments on commit 7482029

Please sign in to comment.