Skip to content

Commit

Permalink
chore: Address PR change requests
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan committed May 2, 2024
1 parent 70af204 commit 6eacf3a
Showing 1 changed file with 26 additions and 35 deletions.
61 changes: 26 additions & 35 deletions .github/workflows/update-geolite-database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ on:
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'
MAXMIND_URL: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=${{ secrets.MAXMIND_LICENSE_KEY }}&suffix=tar.gz'
MAXMIND_SHA256_URL: 'https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country&license_key=${{ secrets.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_*'
Expand Down Expand Up @@ -59,45 +59,36 @@ jobs:
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'
- name: Setup git
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
git config --global user.email '${{ github.actor }}@users.noreply.github.com'
git config --global user.name '${{ github.actor }}'
- name: Delete Branch
if: steps.make-pr.outcome == 'success'
- name: Create a branch, commit the code and make a PR
id: create-pr
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"
BRANCH="${{ github.actor }}/geoip2-bot-update-country-database-$(echo "${{ github.sha }}" | cut -c 1-7)"
git checkout -b $BRANCH
git add .
git status
git commit -m "chore: geoip2: update maxmind geolite country database"
git push --set-upstream origin $BRANCH
PR_URL=$(gh pr create \
--title "Update GeoLite Database" \
--body "PR generated by workflow `${{ github.workflow }}` on behalf of @${{ github.actor }}." \
--head $BRANCH \
--base 'master' \
--assignee 'arbi-bom' \
--reviewer 'arbi-bom' \
| grep -o 'https://github.com/.*/pull/[0-9]*')
echo "PR Created: ${PR_URL}"
echo "pull-request-url=$PR_URL" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ github.token }}

- name: Job summary
run: |
PR_URL='${{ steps.make-pr.outputs.pull-request-url }}'
PR_URL=${{ steps.create-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
Expand Down

0 comments on commit 6eacf3a

Please sign in to comment.