Skip to content

Commit 0bedea4

Browse files
authored
added dbip_download github workflow (#637)
* added dbip_download github workflow * change to run every day on midnight for QA
1 parent f2a2470 commit 0bedea4

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Download DBIP data and generate dbip_country.rs
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *" # Runs at midnight on the 3rd of every month
6+
7+
env:
8+
TEMP_DIR: '/tmp'
9+
YEAR_MONTH: '01-9999'
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
generate:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Rust
22+
uses: actions-rs/toolchain@v1
23+
with:
24+
toolchain: stable
25+
26+
- name: Download DBIP data in MMDB format
27+
run: |
28+
cd ip_country
29+
export YEAR_MONTH=$(date +%Y-%m)
30+
echo "TEMP_DIR=$(mktemp -d)" >> $GITHUB_ENV
31+
echo "YEAR_MONTH=$YEAR_MONTH" >> $GITHUB_ENV
32+
mkdir -p dbip-data
33+
curl -L -o dbip-data/dbip-country-lite.mmdb.gz "https://download.db-ip.com/free/dbip-country-lite-$YEAR_MONTH.mmdb.gz"
34+
gunzip dbip-data/dbip-country-lite.mmdb.gz
35+
36+
- name: Generate Rust source file
37+
run: |
38+
cd ip_country
39+
cargo run < "dbip-data/dbip-country-lite.mmdb" > "$TEMP_DIR"/dbip_country.rs
40+
ls "$TEMP_DIR"
41+
42+
- name: Commit and push generated file
43+
run: |
44+
git config user.name "github-actions[bot]"
45+
git config user.email "github-actions[bot]@users.noreply.github.com"
46+
git checkout -B generated-source
47+
git rm -rf .
48+
mkdir ip_country/src
49+
mv "${TEMP_DIR}"/dbip_country.rs ip_country/src/dbip_country.rs
50+
git add ip_country/src/dbip_country.rs
51+
git commit -m "Update generated dbip_country ${YEAR_MONTH} Rust source file"
52+
git push -u origin HEAD

0 commit comments

Comments
 (0)