Skip to content

Build geoip files

Build geoip files #324

Workflow file for this run

name: Build geoip files
on:
workflow_dispatch:
schedule:
- cron: "20 3,22 * * *"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout codebase
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get APNIC data
run: |
curl 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' -o apnic-data.txt
grep '|CN|ipv4|' apnic-data.txt | awk -F '|' '{ printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > ipv4-apnic.txt
grep '|CN|ipv6|' apnic-data.txt | cut -d '|' -f '4,5' | tr '|' '/' > ipv6-apnic.txt
ls *.txt
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: ./go.mod
- name: Build geoip files
run: |
go build ./
./geoip convert -c ./config.json
- name: Generate sha256 checksum for dat files
run: |
cd ./output/dat || exit 1
for name in $(ls *.dat); do
sha256sum ${name} > ./${name}.sha256sum
done
- name: Move files to publish directory
run: |
mkdir -p publish
mv ./output/dat/*.dat ./output/dat/*.sha256sum ./publish/
cp -fpPR ./output/text ./publish
- name: Git push assets to "release" branch
run: |
cd publish || exit 1
git init -b release
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "$(date +%Y%m%d%H%M)"
git remote add geoip "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}"
git push -f -u geoip release