Skip to content

Commit 7482029

Browse files
committed
Update geoip
1 parent be06655 commit 7482029

File tree

10 files changed

+318
-2183
lines changed

10 files changed

+318
-2183
lines changed

.github/workflows/build.yml

+129-61
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ name: Build geoip files
22
on:
33
workflow_dispatch:
44
schedule:
5-
- cron: "0 0 * * 4"
5+
- cron: "0 18 * * *"
66
push:
77
branches:
88
- master
99
paths-ignore:
1010
- ".gitignore"
11-
- "LICENSE*"
11+
- "LICENSE"
1212
- "*.md"
13+
1314
jobs:
1415
build:
1516
name: Build
@@ -27,36 +28,42 @@ jobs:
2728

2829
- name: Set variables
2930
run: |
30-
echo "TAG_NAME=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV
31-
echo "RELEASE_NAME=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV
31+
echo "update_version=$(date -d '+8 hours' +%Y-%m-%d)" >> ${GITHUB_ENV}
32+
echo "private=https://raw.githubusercontent.com/XIU2/TrackersListCollection/master/all.txt" >> $GITHUB_ENV
33+
echo "cn=http://ftp.apnic.net/stats/apnic/delegated-apnic-latest" >> $GITHUB_ENV
34+
echo "cn_asn=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/Surge/ChinaASN/ChinaASN.list" >> $GITHUB_ENV
3235
shell: bash
3336

34-
- name: Download GeoLite2 databases
35-
env:
36-
LICENSE_KEY: ${{ secrets.MAXMIND_GEOLITE2_LICENSE }}
37+
- name: Generate private
3738
run: |
38-
mkdir -p output
39-
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
40-
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
41-
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
42-
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
39+
mkdir -p ./data/
40+
curl -sSL ${private} | grep -E '\/[^A-Za-z]+\/' | awk -F'[/:]' '{print $4}' >> ./data/private
41+
curl -sSL ${private} | grep '::' | awk -F'[][]' '{print $2}' >> ./data/private
4342
44-
- name: Prepare GeoLite2 databases
43+
- name: Generate cn and cn_ip
4544
run: |
46-
cp ./output/{*.gz,*.zip} ./
47-
unzip GeoLite2-Country-CSV.zip
48-
unzip GeoLite2-ASN-CSV.zip
49-
tar -xvzf GeoLite2-Country.tar.gz
50-
tar -xvzf GeoLite2-ASN.tar.gz
45+
mkdir -p ./ips/
46+
curl -sSL ${cn} | awk -F '|' '/CN/&&/ipv4/ {print $4 "/" 32-log($5)/log(2)}' > ./ips/cn_ipv4.txt
47+
cat ./ips/cn_ipv4.txt >> ./data/cn
48+
curl -sSL ${cn} | awk -F '|' '/CN/&&/ipv6/ {print $4 "/" $5}' > ./ips/cn_ipv6.txt
49+
cat ./ips/cn_ipv6.txt >> ./data/cn
5150
52-
cp GeoLite2-Country_*/*.mmdb ./output/
53-
cp GeoLite2-ASN_*/*.mmdb ./output/
54-
cp GeoLite2-Country-CSV_*/{GeoLite2-Country-Blocks-*,GeoLite2-Country-Locations-en,GeoLite2-Country-Locations-zh-CN}.csv ./output/
55-
cp GeoLite2-ASN-CSV_*/*.csv ./output/
56-
57-
mkdir -p geolite2
58-
cp GeoLite2-Country-CSV_*/*.csv ./geolite2/
59-
cp GeoLite2-ASN-CSV_*/*.csv ./geolite2/
51+
- name: Get GeoLite2
52+
env:
53+
LICENSE_KEY: ${{ secrets.MAXMIND_GEOLITE2_LICENSE }}
54+
run: |
55+
mkdir -p ./output/ ./geolite2/
56+
curl -L "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&license_key=${LICENSE_KEY}&suffix=tar.gz" | tar -zx -C ./
57+
curl -L "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=${LICENSE_KEY}&suffix=tar.gz" | tar -zx -C ./
58+
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"
59+
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"
60+
unzip ./GeoLite2-ASN-CSV.zip
61+
unzip ./GeoLite2-Country-CSV.zip
62+
rm -f ./*.zip
63+
mv -f ./GeoLite2-Country_*/*.mmdb ./output/
64+
mv -f ./GeoLite2-ASN_*/*.mmdb ./output/
65+
mv -f ./GeoLite2-ASN-CSV_*/*.csv ./geolite2/
66+
mv -f ./GeoLite2-Country-CSV_*/*.csv ./geolite2/
6067
6168
- name: Build geoip files
6269
run: |
@@ -65,58 +72,119 @@ jobs:
6572
6673
- name: Verify mmdb files
6774
run: |
68-
cd ./output || exit 1
75+
cd ./output/ || exit 1
6976
go install -v github.com/maxmind/mmdbverify@latest
7077
for name in $(ls *.mmdb); do
7178
$(go env GOPATH)/bin/mmdbverify -file ${name}
7279
done
7380
74-
- name: Generate sha256 checksum for dat files
81+
- name: Get geoip-all.dat and Country-all.mmdb relative files
7582
run: |
76-
cd ./output || exit 1
77-
for name in $(ls *.dat); do
78-
sha256sum ${name} > ./${name}.sha256sum
79-
done
83+
curl -o ./output/geoip-all.dat -L https://raw.githubusercontent.com/Loyalsoldier/geoip/release/geoip.dat
84+
curl -o ./output/Country-all.mmdb -L https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country.mmdb
85+
curl -o ./output/Country-ASN-all.mmdb -L https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country-asn.mmdb
8086
81-
- name: Generate sha256 checksum for mmdb files
87+
- name: Build db and metadb file
8288
run: |
83-
cd ./output || exit 1
84-
for name in $(ls *.mmdb); do
85-
sha256sum ${name} > ./${name}.sha256sum
89+
cd ./output/ || exit 1
90+
go install -trimpath -ldflags="-s -w -buildid=" github.com/metacubex/geo/cmd/geo@master
91+
for file in $(ls *.dat | sed 's/\..*//'); do
92+
geo convert ip -i v2ray -o meta -f "./${file}.metadb" "./${file}.dat"
93+
geo convert ip -i v2ray -o sing -f "./${file}.db" "./${file}.dat"
8694
done
8795
88-
- name: Git push assets to "release" branch
96+
- name: Move files
8997
run: |
90-
cd output || exit 1
91-
git init
92-
git config --local user.name "github-actions[bot]"
93-
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
94-
git checkout -b release
95-
git add -A
96-
git commit -m "${{ env.RELEASE_NAME }}"
97-
git remote add geoip "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"
98-
git push -f -u geoip release
99-
100-
- name: Purge jsdelivr CDN
98+
mkdir -p ./clash/ ./sing-box/
99+
cd ./output/ || exit 1
100+
for file in $(ls *.dat *.metadb); do
101+
install -Dp "./${file}" ../clash/
102+
done
103+
for file in $(ls *.db); do
104+
install -Dp "./${file}" ../sing-box/
105+
done
106+
107+
- name: Move and generate files to branchs
101108
run: |
102-
cd output || exit 1
103-
for file in $(ls); do
104-
curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@release/${file}"
109+
mkdir -p ./tmp/
110+
mv -f ./output/Country*.mmdb ./clash/
111+
curl -sSL ${cn_asn} | grep -v '#' | sed 's/,no-resolve$//' > ./tmp/cn.list
112+
for file in $(ls ./output/clash/classical/ | sed 's/\..*//'); do
113+
grep -v 'payload:' "./output/clash/classical/${file}.txt" | sed 's/^ - //' >> "./tmp/${file}.list"
114+
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"
115+
sort --ignore-case -u "./tmp/${file}.list" > "./ips/${file}ip.list"
105116
done
117+
rm -rf ./tmp* ./output*
106118
107-
- name: Remove some files to avoid publishing to GitHub release
119+
- name: Release and upload `ips` assets
120+
uses: svenstaro/upload-release-action@v2
121+
with:
122+
repo_token: ${{ secrets.GITHUB_TOKEN }}
123+
release_name: ips
124+
tag: ips
125+
overwrite: true
126+
body: |
127+
IP 段列表文件
128+
文件更新于 ${{ env.update_version }}
129+
file_glob: true
130+
file: ./ips/*
131+
132+
- name: Commit and push `ips` branch
108133
run: |
109-
rm -rf ./output/*.{gz,zip}
110-
rm -rf ./output/GeoLite2-*.csv
111-
rm -rf ./output/GeoLite2-*.mmdb
112-
rm -rf ./output/GeoLite2-*.sha256sum
113-
rm -rf ./output/{clash,dat,mrs,nginx,srs,surge,text}
134+
cd ./ips/ || exit 1
135+
git init
136+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
137+
git config --local user.name "github-actions[bot]"
138+
git checkout -b ips
139+
git add . && git commit -m "IP 段列表更新于 ${update_version}"
140+
git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"
141+
git push -f -u origin ips
114142
115-
- name: Upload files to GitHub release
143+
- name: Release and upload `clash` assets
116144
uses: svenstaro/upload-release-action@v2
117145
with:
118146
repo_token: ${{ secrets.GITHUB_TOKEN }}
147+
release_name: clash
148+
tag: clash
149+
overwrite: true
150+
body: |
151+
[Clash](https://github.com/Dreamacro/clash) geoip 文件
152+
geoip 文件更新于 ${{ env.update_version }}
119153
file_glob: true
120-
file: ./output/*
121-
release_name: ${{ env.RELEASE_NAME }}
122-
tag: ${{ env.TAG_NAME }}
154+
file: ./clash/*
155+
156+
- name: Release and upload `sing-box` assets
157+
uses: svenstaro/upload-release-action@v2
158+
with:
159+
repo_token: ${{ secrets.GITHUB_TOKEN }}
160+
release_name: sing-box
161+
tag: sing-box
162+
overwrite: true
163+
body: |
164+
[sing-box](https://github.com/SagerNet/sing-box) geoip 文件
165+
geoip 文件更新于 ${{ env.update_version }}
166+
file_glob: true
167+
file: ./sing-box/*
168+
169+
- name: Purge jsDelivr CDN
170+
run: |
171+
cd ./ips/ || exit 1
172+
for file in $(ls); do
173+
curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@ips/${file}"
174+
done
175+
cd ../clash/ || exit 1
176+
for file in $(ls); do
177+
curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@clash/${file}"
178+
done
179+
cd ../sing-box/ || exit 1
180+
for file in $(ls); do
181+
curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@sing-box/${file}"
182+
done
183+
184+
- name: Delete old workflow runs
185+
uses: Mattraks/delete-workflow-runs@v2
186+
with:
187+
token: ${{ secrets.GITHUB_TOKEN }}
188+
repository: ${{ github.repository }}
189+
retain_days: 3
190+
keep_minimum_runs: 1

0 commit comments

Comments
 (0)