@@ -2,25 +2,26 @@ name: Build geoip files
22on :
33 workflow_dispatch :
44 schedule :
5- - cron : " 0 0 * * 4 "
5+ - cron : " 0 18 * * * "
66 push :
77 branches :
8- - master
8+ - main
99 paths-ignore :
10- - " assets/*"
1110 - " .gitignore"
12- - " LICENSE* "
11+ - " LICENSE"
1312 - " *.md"
1413 pull_request :
1514 branches :
16- - master
15+ - main
1716 paths-ignore :
18- - " assets/*"
1917 - " .gitignore"
20- - " LICENSE* "
18+ - " LICENSE"
2119 - " *.md"
20+
2221permissions :
2322 contents : write
23+ actions : write
24+
2425jobs :
2526 build :
2627 name : Build
@@ -35,40 +36,43 @@ jobs:
3536 uses : actions/setup-go@v7
3637 with :
3738 go-version-file : ./go.mod
38- cache-dependency-path : ./go.sum
3939
4040 - name : Set variables
4141 run : |
42- echo "TAG_NAME=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV
43- echo "RELEASE_NAME=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV
42+ echo "update_version=$(date -d '+8 hours' +%Y-%m-%d)" >> ${GITHUB_ENV}
43+ echo "cn_asn=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/Surge/ChinaASN/ChinaASN.list" >> $GITHUB_ENV
44+ echo "media=https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/Clash/GlobalMedia/GlobalMedia.list" >> ${GITHUB_ENV}
45+ echo "cn1=https://ispip.clang.cn/all_cn.txt" >> $GITHUB_ENV
46+ echo "cn2=https://ispip.clang.cn/all_cn_ipv6.txt" >> $GITHUB_ENV
4447 shell : bash
4548
46- - name : Download GeoLite2 databases
47- env :
48- LICENSE_KEY : ${{ secrets.MAXMIND_GEOLITE2_LICENSE }}
49+ - name : Gererate `media`
4950 run : |
50- mkdir -p output
51- 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
52- 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
53- 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
54- 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
51+ mkdir -p ./data/
52+ curl -sSL ${media} | perl -ne '/^(IP-CIDR.*),([^,]+),/ && print "$2\n"' > ./data/media
5553
56- - name : Prepare GeoLite2 databases
54+ - name : Generate `cn_ip`
5755 run : |
58- cp ./output/{*.gz,*.zip} ./
59- unzip GeoLite2-Country-CSV.zip
60- unzip GeoLite2-ASN-CSV.zip
61- tar -xvzf GeoLite2-Country.tar.gz
62- tar -xvzf GeoLite2-ASN.tar.gz
63-
64- cp GeoLite2-Country_*/*.mmdb ./output/
65- cp GeoLite2-ASN_*/*.mmdb ./output/
66- cp GeoLite2-Country-CSV_*/{GeoLite2-Country-Blocks-*,GeoLite2-Country-Locations-en,GeoLite2-Country-Locations-zh-CN}.csv ./output/
67- cp GeoLite2-ASN-CSV_*/*.csv ./output/
56+ mkdir -p ./ips/
57+ curl -sSL ${cn1} > ./ips/cn_ipv4.txt
58+ curl -sSL ${cn2} > ./ips/cn_ipv6.txt
6859
69- mkdir -p geolite2
70- cp GeoLite2-Country-CSV_*/*.csv ./geolite2/
71- cp GeoLite2-ASN-CSV_*/*.csv ./geolite2/
60+ - name : Get GeoLite2
61+ env :
62+ LICENSE_KEY : ${{ secrets.MAXMIND_GEOLITE2_LICENSE }}
63+ run : |
64+ mkdir -p ./output/ ./geolite2/
65+ curl -sS -L "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&license_key=${LICENSE_KEY}&suffix=tar.gz" | tar -zx -C ./
66+ curl -sS -L "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=${LICENSE_KEY}&suffix=tar.gz" | tar -zx -C ./
67+ curl -sS -o ./GeoLite2-ASN-CSV.zip -L "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN-CSV&license_key=${LICENSE_KEY}&suffix=zip"
68+ curl -sS -o ./GeoLite2-Country-CSV.zip -L "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&license_key=${LICENSE_KEY}&suffix=zip"
69+ unzip ./GeoLite2-ASN-CSV.zip
70+ unzip ./GeoLite2-Country-CSV.zip
71+ rm -f ./*.zip
72+ mv -f ./GeoLite2-Country_*/*.mmdb ./output/
73+ mv -f ./GeoLite2-ASN_*/*.mmdb ./output/
74+ mv -f ./GeoLite2-ASN-CSV_*/*.csv ./geolite2/
75+ mv -f ./GeoLite2-Country-CSV_*/*.csv ./geolite2/
7276
7377 - name : Build geoip files
7478 run : |
@@ -77,59 +81,117 @@ jobs:
7781
7882 - name : Verify mmdb files
7983 run : |
80- cd ./output || exit 1
84+ cd ./output/ || exit 1
8185 go install -v github.com/maxmind/mmdbverify@latest
8286 for name in $(ls *.mmdb); do
8387 $(go env GOPATH)/bin/mmdbverify -file ${name}
8488 done
8589
86- - name : Generate sha256 checksum for dat files
90+ - name : Get geoip-all.dat and Country-all.mmdb relative files
8791 run : |
88- cd ./output || exit 1
89- for name in $(ls *.dat); do
90- sha256sum ${name} > ./${name}.sha256sum
92+ curl -sS -o ./output/geoip-all.dat -L https://raw.githubusercontent.com/Loyalsoldier/geoip/release/geoip.dat
93+ curl -sS -o ./output/Country-all.mmdb -L https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country.mmdb
94+ curl -sS -o ./output/Country-ASN-all.mmdb -L https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country-asn.mmdb
95+
96+ - name : Build metadb files
97+ run : |
98+ cd ./output/ || exit 1
99+ go install -trimpath -ldflags="-s -w -buildid=" github.com/metacubex/geo/cmd/geo@master
100+ for file in $(ls *.dat | sed 's/\..*//'); do
101+ geo convert ip -i v2ray -o meta -f "./${file}.metadb" "./${file}.dat"
91102 done
92103
93- - name : Generate sha256 checksum for mmdb files
104+ - name : Move files
94105 run : |
95- cd ./output || exit 1
96- for name in $(ls *.mmdb); do
97- sha256sum ${name} > ./${name}.sha256sum
106+ mkdir -p ./mihomo-geodata/
107+ cd ./output/ || exit 1
108+ for file in $(ls *.dat *.metadb); do
109+ install -Dp "./${file}" ../mihomo-geodata/
110+ done
111+
112+ - name : Move and generate files to branchs
113+ run : |
114+ mkdir -p ./tmp/
115+ mv -f ./output/Country*.mmdb ./mihomo-geodata/
116+ for file in $(ls ./output/clash/classical/ | sed 's/\..*//'); do
117+ cat "./output/clash/classical/${file}.txt" | perl -ne '/^\s*-\s+(.*)/ && print "$1\n"' > "./tmp/temp-${file}.list"
118+ sort --ignore-case "./tmp/temp-${file}.list" > "./ips/${file}ip.list"
98119 done
99120
100- - name : Git push assets to "release" branch
121+ cat ./config.json | grep '\"netflix\":' | grep -o 'AS[0-9]\+' | sed 's/^/IP-ASN,/' | sort --ignore-case > ./ips/netflix-asn.list
122+ cat ./config.json | grep '\"telegram\":' | grep -o 'AS[0-9]\+' | sed 's/^/IP-ASN,/' | sort --ignore-case > ./ips/telegram-asn.list
123+ curl -sSL ${cn_asn} | perl -ne '/^(IP-ASN,\d+),/ && print "$1\n"' | sort --ignore-case > ./ips/cn-asn.list
124+
125+ rm -rf ./tmp* ./output*
126+
127+ - name : Release and upload `ips` assets
128+ if : github.event_name != 'pull_request'
129+ uses : svenstaro/upload-release-action@v2
130+ with :
131+ repo_token : ${{ secrets.GITHUB_TOKEN }}
132+ release_name : ips
133+ tag : ips
134+ overwrite : true
135+ body : |
136+ 供下游项目 [DustinWin/ruleset_geodata](https://github.com/DustinWin/ruleset_geodata) 使用的 IP 数据源文件
137+ [ShellCrash](https://github.com/juewuy/ShellCrash) 中 CN_IP 绕过内核所需文件
138+ 文件更新于 ${{ env.update_version }}
139+ file_glob : true
140+ file : ./ips/*
141+
142+ - name : Commit and push `ips` branch
101143 if : github.event_name != 'pull_request'
102144 run : |
103- cd output || exit 1
145+ cd ./ips/ || exit 1
104146 git init
147+ git config --local user.email "github-actions[bot]@users.noreply.github.com"
105148 git config --local user.name "github-actions[bot]"
106- git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
107- git checkout -b release
108- git add -A
109- git commit -m "${{ env.RELEASE_NAME }}"
110- git remote add geoip "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"
111- git push -f -u geoip release
112-
113- - name : Purge jsdelivr CDN
149+ git checkout -b ips
150+ git add . && git commit -m "IP 数据源文件和 CNIP 绕过内核文件更新于 ${update_version}"
151+ git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"
152+ git push -f origin ips
153+
154+ - name : Release and upload `mihomo-geodata` assets
114155 if : github.event_name != 'pull_request'
115- run : |
116- cd output || exit 1
117- for file in $(ls); do
118- curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@release/${file}"
119- done
156+ uses : svenstaro/upload-release-action@v2
157+ with :
158+ repo_token : ${{ secrets.GITHUB_TOKEN }}
159+ release_name : mihomo-geodata
160+ tag : mihomo-geodata
161+ overwrite : true
162+ body : |
163+ [mihomo 内核](https://github.com/MetaCubeX/mihomo) geodata 文件
164+ geodata 文件更新于 ${{ env.update_version }}
165+ file_glob : true
166+ file : ./mihomo-geodata/*
120167
121- - name : Remove some files to avoid publishing to GitHub release
168+ - name : Commit and push `mihomo-geodata` branch
122169 if : github.event_name != 'pull_request'
123170 run : |
124- rm -rf ./output/*.{gz,zip}
125- rm -rf ./output/GeoLite2-*.csv
126- rm -rf ./output/GeoLite2-*.mmdb
127- rm -rf ./output/GeoLite2-*.sha256sum
128- rm -rf ./output/{clash,dat,mrs,nginx,srs,surge,text}
171+ cd ./mihomo-geodata/ || exit 1
172+ git init
173+ git config --local user.email "github-actions[bot]@users.noreply.github.com"
174+ git config --local user.name "github-actions[bot]"
175+ git checkout -b mihomo-geodata
176+ git add . && git commit -m "mihomo 内核 geodata 文件更新于 ${update_version}"
177+ git remote add origin "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"
178+ git push -f origin mihomo-geodata
129179
130- - name : Upload files to GitHub release
131- if : github.event_name != 'pull_request'
132- env :
133- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
180+ - name : Purge jsDelivr CDN
134181 run : |
135- gh release create ${{ env.TAG_NAME }} --title "${{ env.RELEASE_NAME }}" ./output/*
182+ cd ./ips/ || exit 1
183+ for file in $(ls); do
184+ curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@ips/${file}"
185+ done
186+ cd ../mihomo-geodata/ || exit 1
187+ for file in $(ls); do
188+ curl -i "https://purge.jsdelivr.net/gh/${{ github.repository }}@mihomo-geodata/${file}"
189+ done
190+
191+ - name : Delete old workflow runs
192+ uses : Mattraks/delete-workflow-runs@v2
193+ with :
194+ token : ${{ secrets.GITHUB_TOKEN }}
195+ repository : ${{ github.repository }}
196+ retain_days : 3
197+ keep_minimum_runs : 1
0 commit comments