github action to automerge dbdump PRs

This commit is contained in:
nadeemshahzad
2020-10-05 17:10:17 +00:00
parent 45c54ee6a5
commit 3aa6f55cef
3 changed files with 47 additions and 16 deletions

View File

@@ -0,0 +1,26 @@
# Used to auto approve/merge PRs for mysqldbdump
name: Automerge mysqldbdump PR
on:
pull_request:
types:
- opened
- labeled
pull_request_review:
types:
- submitted
jobs:
approve_and_merge:
runs-on: ubuntu-latest
if: github.actor == 'edx-deployment' && github.event.label.name == 'mysqldbdump'
steps:
- uses: hmarr/auto-approve-action@7782c7e2bdf62b4d79bdcded8332808fd2f179cd
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: automerge
uses: "pascalgn/automerge-action@7ab42e888a333bf77ce865bc84fedc6a365a3548"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
MERGE_LABELS: "mysqldbdump"
MERGE_FILTER_AUTHOR: "edx-deployment"
MERGE_METHOD: "merge"

View File

@@ -17,7 +17,7 @@ jobs:
with:
time: '900s'
- name: Dump database
run: docker exec -i edx.devstack.mysql mysqldump -u'edxapp001' -p'password' edxapp > edxapp.sql
run: docker exec -i edx.devstack.mysql mysqldump -u'edxapp001' -p'password' --skip-dump-date edxapp > edxapp.sql
- name: Commit dump file to repo.
run: ./.github/workflows/mysqldbdump_pr.sh
env:

View File

@@ -14,21 +14,26 @@ tar -zxvf hub.tgz
cd "$REPO_NAME"
git config --global user.name "${GITHUB_USER}"
git config --global user.email "${GITHUB_EMAIL}"
if [[ -z $(git status -s) ]]; then
echo "No changes to commit."
else
git config --global user.name "${GITHUB_USER}"
git config --global user.email "${GITHUB_EMAIL}"
obsolete_dump_prs=`../hub-linux*/bin/hub pr list -s open --format '%I:%H %n' | grep 'github-actions-mysqldbdump'`
obsolete_dump_prs=`../hub-linux*/bin/hub pr list -s open --format '%I:%H %n' | grep 'github-actions-mysqldbdump'`
if [[ ! -z $obsolete_dump_prs ]]; then
for pr in $obsolete_dump_prs; do
IFS=':' read pr_num branch <<< "$pr"
../hub-linux*/bin/hub issue update ${pr_num} -s closed
../hub-linux*/bin/hub push origin --delete ${branch}
done
fi
git checkout -b github-actions-mysqldbdump/$GITHUB_SHA
git add "${DB_NAME}".sql
git commit -m "MySQLdbdump" --author "GitHub Actions MySQLdbdump automation <admin@edx.org>"
git push --set-upstream origin github-actions-mysqldbdump/$GITHUB_SHA
../hub-linux*/bin/hub pull-request -m "${DB_NAME} MySQL database dump" -m "MySQL database dump" -l mysqldbdump
if [[ ! -z $obsolete_dump_prs ]]; then
for pr in $obsolete_dump_prs; do
IFS=':' read pr_num branch <<< "$pr"
../hub-linux*/bin/hub issue update ${pr_num} -s closed
../hub-linux*/bin/hub push origin --delete ${branch}
done
fi
git checkout -b github-actions-mysqldbdump/$GITHUB_SHA
git add "${DB_NAME}".sql
git commit -m "MySQLdbdump" --author "GitHub Actions MySQLdbdump automation <admin@edx.org>"
git push --set-upstream origin github-actions-mysqldbdump/$GITHUB_SHA
../hub-linux*/bin/hub pull-request -m "${DB_NAME} MySQL database dump" -m "MySQL database dump"