Skip to content

Download DBIP data and generate dbip_country.rs #21

Download DBIP data and generate dbip_country.rs

Download DBIP data and generate dbip_country.rs #21

Workflow file for this run

name: Download DBIP data and generate dbip_country.rs
on:
workflow_dispatch:
# schedule:
# - cron: "0 0 3 * *" # Runs at midnight on the 3rd of every month
env:
SKIP_EXPORT: 'false'
TEMP_DIR: '/tmp'
permissions:
contents: write
jobs:
generate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- 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)
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
echo "TEMP_DIR=$(mktemp -d)" >> $GITHUB_ENV
if [ "$?" -ne "0" ]; then
echo "SKIP_EXPORT=true" >> $GITHUB_ENV
fi
- name: Generate Rust source file
if: ${{ env.SKIP_EXPORT == 'false' }}
run: |
set -xv
echo $TEMP_DIR
pwd
cd ip_country
mkdir -p generated
cargo run < "dbip-data/dbip-country-lite.mmdb" > "$TEMP_DIR"/dbip_country.rs
ls "$TEMP_DIR"
if [ "$?" -ne "0" ]; then
echo "SKIP_EXPORT=true" >> $GITHUB_ENV
fi
- name: Commit and push generated file
if: ${{ env.SKIP_EXPORT == 'false' }}
run: |
set -xv
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 .
ls -la
ls -la ip_country
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 Rust source file"
git push origin generated-source --force