Skip to content

Commit 0fbfb22

Browse files
committed
修改上游项目
1 parent 85084df commit 0fbfb22

21 files changed

Lines changed: 336 additions & 2881 deletions

.github/dependabot.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
# To get started with Dependabot version updates, you'll need to specify which
2-
# package ecosystems to update and where the package manifests are located.
3-
# Please see the documentation for all configuration options:
4-
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5-
61
version: 2
72
updates:
83
- package-ecosystem: "github-actions"
9-
directory: "/"
4+
directories:
5+
- "/*"
106
schedule:
117
interval: "daily"
128
timezone: "Asia/Shanghai"
13-
time: "07:00"
9+
time: "06:00"
1410
pull-request-branch-name:
1511
separator: "-"
1612

1713
- package-ecosystem: "gomod"
18-
directory: "/"
14+
directories:
15+
- "/*"
1916
schedule:
2017
interval: "daily"
2118
timezone: "Asia/Shanghai"
22-
time: "07:00"
19+
time: "06:00"
2320
pull-request-branch-name:
2421
separator: "-"

.github/workflows/build.yml

Lines changed: 129 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,26 @@ name: Build geoip files
22
on:
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+
2221
permissions:
2322
contents: write
23+
actions: write
24+
2425
jobs:
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

.github/workflows/sync.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Upstream Sync
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
schedule:
8+
- cron: "0 0 * * *"
9+
workflow_dispatch:
10+
11+
jobs:
12+
sync_latest_from_upstream:
13+
name: Sync latest commits from upstream repo
14+
runs-on: ubuntu-latest
15+
if: ${{ github.event.repository.fork }}
16+
steps:
17+
- name: Checkout target repo
18+
uses: actions/checkout@v7
19+
20+
- name: Sync upstream changes
21+
id: sync
22+
uses: aormsby/Fork-Sync-With-Upstream-action@v3.4.3
23+
with:
24+
upstream_sync_repo: Loyalsoldier/geoip
25+
upstream_sync_branch: master
26+
target_sync_branch: main
27+
target_repo_token: ${{ secrets.GITHUB_TOKEN }}
28+
test_mode: false
29+
30+
- name: Sync check
31+
if: failure()
32+
run: |
33+
echo "[Error] 由于上游仓库的 workflow 文件变更,导致 GitHub 自动暂停了本次自动更新,你需要手动 Sync Fork 一次。"
34+
exit 1

0 commit comments

Comments
 (0)