Update China IP list and generate GeoIP2 database #33300
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update China IP list and generate GeoIP2 database | |
on: | |
push: | |
branches: [ master ] | |
workflow_dispatch: | |
schedule: | |
- cron: '30 * * * *' | |
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 | |
run: | | |
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: Create dist folder | |
run: mkdir -p dist | |
- name: Compile GeoIP conversion bin (Golang) | |
run: ./build.sh | |
- name: Obtain CN IP lists | |
run: | | |
curl -LR -o- "https://raw.githubusercontent.com/misakaio/chnroutes2/master/chnroutes.txt" | grep -v "#" > dist/CN-ip-cidr.txt | |
cat dist/CN-ip-cidr.txt | sed "s/^\(.*\)$/ - '\1'/g;1ipayload:" > dist/clash-rule-provider.yml | |
cat dist/CN-ip-cidr.txt | sed "s/^\(.*\)$/IP-CIDR,\1/g" > dist/clash-ruleset.list | |
cat dist/CN-ip-cidr.txt | sed "s/^\(.*\)$/IP-CIDR,\1/g" > dist/surge-ruleset.list | |
echo 'create chnroute hash:net family inet hashsize 1024 maxelem 65536' > dist/chnroute.ipset | |
cat dist/CN-ip-cidr.txt | sed 's/^/add chnroute /g' >> dist/chnroute.ipset | |
- name: Generate GeoIP2 database | |
run: | | |
CURRENT_DIR=$(pwd) | |
cd dist | |
./ipip2mmdb -s ./CN-ip-cidr.txt -d Country.mmdb | |
cd $CURRENT_DIR | |
- name: Push artifacts to release branch | |
run: | | |
git config --local user.email "891708+soffchen@users.noreply.github.com" | |
git config --local user.name "github-action[bot]" | |
git fetch | |
git checkout release | |
git checkout --orphan release-orphan | |
git rm -rf . | |
cp -f dist/* . | |
git add Country.mmdb | |
git add CN-ip-cidr.txt | |
git add clash-rule-provider.yml | |
git add clash-ruleset.list | |
git add surge-ruleset.list | |
git add chnroute.ipset | |
git commit -am "Updated at $(date)" | |
git branch -D release | |
git branch -m release | |
- name: GitHub Push | |
uses: ad-m/github-push-action@v0.6.0 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: release | |
force: true | |
- name: Purge CDN Cache | |
run: | | |
curl -L https://purge.jsdelivr.net/gh/soffchen/GeoIP2-CN@release/CN-ip-cidr.txt > /dev/null 2>&1 | |
curl -L https://purge.jsdelivr.net/gh/soffchen/GeoIP2-CN@release/Country.mmdb > /dev/null 2>&1 | |
curl -L https://purge.jsdelivr.net/gh/soffchen/GeoIP2-CN@release/clash-rule-provider.yml > /dev/null 2>&1 | |
curl -L https://purge.jsdelivr.net/gh/soffchen/GeoIP2-CN@release/clash-ruleset.list > /dev/null 2>&1 | |
curl -L https://purge.jsdelivr.net/gh/soffchen/GeoIP2-CN@release/surge-ruleset.list > /dev/null 2>&1 | |
curl -L https://purge.jsdelivr.net/gh/soffchen/GeoIP2-CN@release/chnroute.ipset > /dev/null 2>&1 |