Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/dbip_download.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Download DBIP data and generate dbip_country.rs

on:
schedule:
- cron: "0 0 * * *" # Runs at midnight on the 3rd of every month

env:
TEMP_DIR: '/tmp'
YEAR_MONTH: '01-9999'

permissions:
contents: write

jobs:
generate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable

- name: Download DBIP data in MMDB format
run: |
cd ip_country
export YEAR_MONTH=$(date +%Y-%m)
echo "TEMP_DIR=$(mktemp -d)" >> $GITHUB_ENV
echo "YEAR_MONTH=$YEAR_MONTH" >> $GITHUB_ENV
mkdir -p dbip-data
curl -L -o dbip-data/dbip-country-lite.mmdb.gz "https://download.db-ip.com/free/dbip-country-lite-$YEAR_MONTH.mmdb.gz"
gunzip dbip-data/dbip-country-lite.mmdb.gz

- name: Generate Rust source file
run: |
cd ip_country
cargo run < "dbip-data/dbip-country-lite.mmdb" > "$TEMP_DIR"/dbip_country.rs
ls "$TEMP_DIR"

- name: Commit and push generated file
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -B generated-source
git rm -rf .
mkdir ip_country/src
mv "${TEMP_DIR}"/dbip_country.rs ip_country/src/dbip_country.rs
git add ip_country/src/dbip_country.rs
git commit -m "Update generated dbip_country ${YEAR_MONTH} Rust source file"
git push -u origin HEAD
Loading