feat: Move geoipupdate script from ecommerce-scripts repo

* Ticket: https://github.com/openedx/axim-engineering/issues/1046
This commit is contained in:
farhan
2024-04-17 17:25:01 +05:00
parent 2ce25b3eb6
commit 70af2048d4

View File

@@ -0,0 +1,106 @@
name: Update GeoLite Database
on:
workflow_dispatch:
inputs:
branch:
description: 'Target branch against which to create PR'
required: false
default: 'master'
env:
MAXMIND_URL: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=${{ env.MAXMIND_LICENSE_KEY }}&suffix=tar.gz'
MAXMIND_SHA256_URL: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=${{ env.MAXMIND_LICENSE_KEY }}&suffix=tar.gz.sha256'
TAR_FILE_NAME: 'GeoLite2-Country.tar.gz'
TAR_SHA256_FILE_NAME: 'GeoLite2-Country.tar.gz.sha256'
TAR_UNZIPPED_ROOT_PATTERN: 'GeoLite2-Country_*'
DB_FILE: 'GeoLite2-Country.mmdb'
DB_DESTINATION_PATH: 'common/static/data/geoip'
jobs:
download-and-replace:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Download GeoLite tar file
run: |
wget -O '${{ env.TAR_FILE_NAME }}' '${{ env.MAXMIND_URL }}'\
- name: Download GeoLite sha256 file
run: |
wget -O '${{ env.TAR_SHA256_FILE_NAME }}' '${{ env.MAXMIND_SHA256_URL }}'\
- name: Check SHA256 hash
run: |
sha256sum '${{ env.TAR_FILE_NAME }}' | grep $(cat '${{ env.TAR_SHA256_FILE_NAME }}' | cut -d' ' -f1)
- name: Extract tar file
run: |
tar xvf '${{ env.TAR_FILE_NAME }}'
- name: Copy DB file to destination path
run: |
find . -type d -name '${{ env.TAR_UNZIPPED_ROOT_PATTERN }}' -exec cp {}/'${{ env.DB_FILE }}' '${{ env.DB_DESTINATION_PATH }}'/ \;
- name: Delete un-required content
run: |
rm '${{ env.TAR_FILE_NAME }}'
rm '${{ env.TAR_SHA256_FILE_NAME }}'
find . -type d -name '${{ env.TAR_UNZIPPED_ROOT_PATTERN }}' -exec rm -r {} \; || true
- name: PR preflight
run: |
if git diff --exit-code; then
echo 'Summary: No updates/changes detected. Terminating the run and no pull request is going to be created.' | tee -a '$GITHUB_STEP_SUMMARY'
exit 1
else
echo 'Updates/changes detected, going to create PR.'
fi
- name: Make a PR
id: make-pr
uses: peter-evans/create-pull-request@v6
with:
branch: '${{ github.actor }}/geoip2-bot-update-country-database'
branch-suffix: short-commit-hash
commit-message: |
chore: geoip2: update maxmind geolite country database
Commit generated by workflow `${{ github.workflow }}`
title: 'Update GeoLite Database'
body: |
PR generated by workflow `${{ github.workflow }}`
on behalf of @${{ github.actor }}.
It's updating the [maxmind geolite country database](https://github.com/openedx/edx-platform/blob/master/common/static/data/geoip/GeoLite2-Country.mmdb)
assignees: '${{ github.triggering_actor }}'
reviewers: '${{ github.triggering_actor }}'
- name: Merge PR
if: steps.make-pr.outcome == 'success'
run: |
PR_URL='${{ steps.make-pr.outputs.pull-request-url }}'
PR_NUMBER=$(basename $PR_URL)
curl -X PUT -H 'Authorization: token ${{ secrets.GITHUB_TOKEN }}' \
-H 'Accept: application/vnd.github.v3+json' \
https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER/merge
- name: Delete Branch
if: steps.make-pr.outcome == 'success'
run: |
SHORT_SHA=$(echo '${{ github.sha }}' | cut -c 1-7)
BRANCH_NAME='${{ github.actor }}/geoip2-bot-update-country-database-'$SHORT_SHA
git push origin --delete $BRANCH_NAME
echo "Successfully deleted the branch $BRANCH_NAME"
- name: Job summary
run: |
PR_URL='${{ steps.make-pr.outputs.pull-request-url }}'
if [[ -z '$PR_URL' ]]; then
echo 'Error: PR creation unsuccessful; refer to the log for further details.' | tee -a "${GITHUB_STEP_SUMMARY}"
exit 1
else
echo "PR: ${PR_URL}" | tee -a "${GITHUB_STEP_SUMMARY}"
fi