-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (82 loc) · 2.68 KB
/
periodical-update.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: Update China IP list and generate GeoIP2 database
on:
push:
branches:
- master
paths:
- '.github/workflows/**'
workflow_dispatch:
schedule:
- cron: '0 16 * * *'
env:
TZ: Asia/Shanghai
jobs:
build:
name: Generate GeoIP2 database
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.14
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Get dependencies
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo -E apt-get update -y
sudo -E apt-get install -y aggregate
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Compile GeoIP conversion bin (Golang)
run: |
mkdir -p dist
./build.sh
- name: Obtain CN IP lists
run: |
cd dist
curl -LR "https://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest" -o - | grep ipv4 | grep CN | awk -F\| '{ printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > apnic.txt
curl -LR "https://github.com/17mon/china_ip_list/raw/master/china_ip_list.txt" -o ipip.txt
curl -LR "https://ispip.clang.cn/all_cn.txt" -o clang.txt
curl -LR "https://github.com/metowolf/iplist/raw/master/data/special/china.txt" -o chunzhen.txt
cat apnic.txt ipip.txt clang.txt chunzhen.txt | aggregate -q > cncidr.txt
cat cncidr.txt | sed "s_^_ - '_g;s_\$_'_g;1i payload:" > cncidr.yaml
- name: Generate GeoIP2 database
run: |
cd dist
./ipip2mmdb -s ./cncidr.txt -d Country.mmdb
- name: Push artifacts to release branch
env:
TZ: Asia/Shanghai
run: |
git config --local user.email "[email protected]"
git config --local user.name "RikudouPatrickstar"
git fetch
git checkout release
git checkout --orphan release-orphan
git rm -rf .
cp -rf dist/cncidr.txt ./
cp -rf dist/cncidr.yaml ./
cp -rf dist/Country.mmdb ./
git add Country.mmdb
git add cncidr.yaml
git add cncidr.txt
git commit -am "Updated at $( date +%Y/%m/%d\ %H:%M:%S)"
git branch -D release
git branch -m release
- name: GitHub Push
uses: ad-m/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: release
force: true
- name: Cleanup Workflow
uses: Mattraks/delete-workflow-runs@main
with:
retain_days: 1
keep_minimum_runs: 1