@@ -3,10 +3,9 @@ name: Download DBIP data and generate dbip_country.rs
33on :
44 workflow_dispatch :
55# schedule:
6- # - cron: "0 0 3 * *" # Runs at midnight on the 3rd of every month
6+ # - cron: "0 0 * * *" # Runs at midnight on the 3rd of every month
77
88env :
9- SKIP_EXPORT : ' false'
109 TEMP_DIR : ' /tmp'
1110 YEAR_MONTH : ' 01-9999'
1211
1817 runs-on : ubuntu-latest
1918 steps :
2019 - name : Checkout repository
21- uses : actions/checkout@v3
20+ uses : actions/checkout@v4
2221
2322 - name : Set up Rust
2423 uses : actions-rs/toolchain@v1
@@ -27,37 +26,38 @@ jobs:
2726
2827 - name : Download DBIP data in MMDB format
2928 run : |
30- cd ip_country
29+ set -xv
3130 export YEAR_MONTH=$(date +%Y-%m)
3231 echo "TEMP_DIR=$(mktemp -d)" >> $GITHUB_ENV
3332 echo "YEAR_MONTH=$YEAR_MONTH" >> $GITHUB_ENV
33+ git clone https://github.com/MASQ-Project/DBIP-Experiment.git dbipexperiment
34+ cd dbipexperiment/ip_country
3435 mkdir -p dbip-data
3536 curl -L -o dbip-data/dbip-country-lite.mmdb.gz "https://download.db-ip.com/free/dbip-country-lite-$YEAR_MONTH.mmdb.gz"
3637 gunzip dbip-data/dbip-country-lite.mmdb.gz
37- if [ "$?" -ne "0" ]; then
38- echo "SKIP_EXPORT=true" >> $GITHUB_ENV
39- fi
4038
4139 - name : Generate Rust source file
42- if : ${{ env.SKIP_EXPORT == 'false' }}
4340 run : |
44- cd ip_country
45- mkdir -p generated
41+ set -xv
42+ cd dbipexperiment/ip_country
4643 cargo run < "dbip-data/dbip-country-lite.mmdb" > "$TEMP_DIR"/dbip_country.rs
4744 ls "$TEMP_DIR"
48- if [ "$?" -ne "0" ]; then
49- echo "SKIP_EXPORT=true" >> $GITHUB_ENV
50- fi
5145
5246 - name : Commit and push generated file
53- if : ${{ env.SKIP_EXPORT == 'false' }}
5447 run : |
48+ set -xv
5549 git config user.name "github-actions[bot]"
5650 git config user.email "github-actions[bot]@users.noreply.github.com"
57- git checkout -B generated-source
58- git rm -rf .
59- mkdir ip_country/src
51+ BRANCH=$(git ls-remote --heads 2>/dev/null | grep generated-source)
52+ if [[ "$BRANCH" == "" ]]
53+ then
54+ git checkout -B generated-source
55+ git rm -rf .
56+ mkdir -p ip_country/src
57+ else
58+ git checkout generated-source
59+ fi
6060 mv "${TEMP_DIR}"/dbip_country.rs ip_country/src/dbip_country.rs
6161 git add ip_country/src/dbip_country.rs
6262 git commit -m "Update generated dbip_country ${YEAR_MONTH} Rust source file"
63- git push origin generated-source --force
63+ git push -u origin HEAD
0 commit comments