Build China IPv6 list. #1237
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 IPv6 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@v3 | |
- name: Setup Rust environmet | |
uses: dtolnay/rust-toolchain@stable | |
- name: Install packages. | |
run: | | |
sudo apt-get update && sudo apt-get install -y bgpdump html2text | |
cargo install --vers 0.0.3 bgptools | |
go install github.com/zhanhb/cidr-merger@v1.1.3 | |
shell: bash | |
- name: Set variables | |
run: | | |
echo "PATH=$(go env GOPATH)/bin:${PATH}" >> $GITHUB_ENV | |
echo "IP6UPSTREAM=http://archive.routeviews.org/route-views6/bgpdata" >> $GITHUB_ENV | |
echo "MONTH6=$(date -u +%Y.%m)" >> $GITHUB_ENV | |
shell: bash | |
- 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: | | |
LATEST6=$(curl -sL ${{ env.IP6UPSTREAM }}/${{ env.MONTH6 }}/RIBS|html2text|grep bz2|awk '{print $3}'|tail -n 1) | |
TAG_NAME=$(echo ${LATEST6}|awk '{gsub("(rib.|.bz2)",""); print $1}') | |
wget -O rib6.bz2 "$IP6UPSTREAM/$MONTH6/RIBS/$LATEST6" | |
echo "RELEASE_NAME=${TAG_NAME}" >> $GITHUB_ENV | |
- name: Dump bgp date. | |
run: | | |
echo "running bgpdump ..." | |
bgpdump -m -O rib6.txt rib6.bz2 | |
echo "finish bgpdump" | |
shell: bash | |
- name: Generate China IPv6 list | |
run: | | |
cat asnames.txt|grep -P "CN\$"|grep -vPi "AS45102"|awk '{gsub(/AS/, ""); print $1}' > cnasn.list | |
cat cnasn.list|xargs bgptools -b rib6.txt|grep -v '^::/0$'|cidr-merger -s|grep -F ':' > cn6.txt | |
shell: bash | |
- name: Generate cn6.txt sha256 hash | |
run: | | |
sha256sum cn6.txt > cn6.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 cn6.txt release/ | |
mv cn6.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 |