Build China IPv4 list. #1289
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
# This is a basic workflow to help you get started with Actions | |
name: Build China IPv4 list. | |
# Controls when the workflow will run | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 22 * * *" | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- "**/README.md" | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
# This workflow contains a single job called "build" | |
build: | |
# The type of runner that the job will run on | |
runs-on: ubuntu-latest | |
env: | |
GO111MODULE: on | |
# Steps represent a sequence of tasks that will be executed as part of the job | |
steps: | |
- name: Setup Go environment | |
uses: actions/setup-go@v4 | |
- name: Setup Rust environmet | |
uses: dtolnay/rust-toolchain@stable | |
- name: Install packages. | |
run: | | |
sudo apt-get update && sudo apt-get install -y bgpdump | |
cargo install --vers 0.0.3 bgptools | |
go install github.com/zhanhb/[email protected] | |
shell: bash | |
- name: Set variables | |
run: | | |
echo "PATH=$(go env GOPATH)/bin:${PATH}" >> $GITHUB_ENV | |
echo "RELEASE_NAME=$(date -u +%Y.%m.%d)" >> $GITHUB_ENV | |
shell: bash | |
- name: Checkout main branch | |
uses: actions/checkout@v3 | |
with: | |
ref: main | |
path: code | |
- name: Generate AS table | |
run: curl -sSL https://bgp.potaroo.net/cidr/autnums.html | awk '-F[<>]' '{print $3,$5}' | grep '^AS' > asnames.txt | |
shell: bash | |
- name: Fetch bgp data. | |
run: | | |
wget -O rib.bz2 "http://archive.routeviews.org/dnszones/rib.bz2" | |
- name: Dump bgp date. | |
run: | | |
echo "running bgpdump ..." | |
bgpdump -m -O rib.txt rib.bz2 | |
echo "finish bgpdump" | |
shell: bash | |
- name: Generate China IPv4 list | |
run: | | |
cat asnames.txt|grep -P "CN\$"|grep -vPi "AS45102"|awk '{gsub(/AS/, ""); print $1}' > cnasn.list | |
cat cnasn.list|xargs bgptools -b rib.txt|cidr-merger -s|grep -Fv ':' > cn.txt | |
shell: bash | |
- name: Generate cn.txt sha256 hash | |
run: | | |
sha256sum cn.txt > cn.txt.sha256sum | |
shell: bash | |
- name: Checkout release branch | |
uses: actions/checkout@v3 | |
with: | |
ref: release | |
path: release | |
- name: Git push assets to "release" branch | |
if: ${{ github.event_name == 'schedule' }} | |
run: | | |
mv cn.txt release/ | |
mv cn.txt.sha256sum release/ | |
cd release | |
git config user.name 'github-actions[bot]' | |
git config user.email 'github-actions[bot]@users.noreply.github.com' | |
git add . | |
[ -n "$(git status -s)" ] && git commit -m "${{ env.RELEASE_NAME }}" || echo "Nothing to commit!" | |
git push | |
shell: bash |