diff --git a/.github/workflows/dbip_download.yml b/.github/workflows/dbip_download.yml new file mode 100644 index 000000000..b6a55977a --- /dev/null +++ b/.github/workflows/dbip_download.yml @@ -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 \ No newline at end of file