Skip to content

Automatically merge plugin-only PRs #571

Automatically merge plugin-only PRs

Automatically merge plugin-only PRs #571

name: Automatically merge plugin-only PRs
# Triggered on all PRs either by
# - completion of CI checks, OR
# - tagging with label
# 1) If PR is labeled "automerge" or "automerge-web"
# (all website submissions are tagged "automerge-web"),
# checks if Travis tests pass. If yes, THEN
# 2) Checks if PR modifies any code outside plugin dirs.
# If no changes are made beyond new or revised plugins
# (subdirs of /benchmarks, /data, /models, or /metrics)
# the PR is automatically approved and merged.
on:
pull_request:
types: [labeled]
status:
permissions: write-all
jobs:
setup:
name: setup
runs-on: ubuntu-latest
outputs:
BSC_DATABASESECRET: ${{ steps.setenvvars.outputs.BSC_DATABASESECRET }}
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Check if main & set dev/prod vars
id: setenvvars
run: |
if [ ${{ github.ref }} != 'refs/heads/main' ]; then
echo "is NOT main branch"
echo "::set-output name=BSC_DATABASESECRET:: ${{ secrets.BSC_DATABASESECRET_DEV }}"
else
echo "is main branch"
echo "::set-output name=BSC_DATABASESECRET:: ${{ secrets.BSC_DATABASESECRET_PROD }}"
fi
isautomerge:
name: Set as 'automerge' if PR is labeled with 'automerge' or 'automerge-web'
runs-on: ubuntu-latest
if: |
contains( github.event.pull_request.labels.*.name, 'automerge') ||
contains( github.event.pull_request.labels.*.name, 'automerge-web')
outputs:
AUTOMERGE: ${{ steps.setautomerge.outputs.AUTOMERGE }}
steps:
- name: Set 'automerge' to 'True' # job only runs if True
id: setautomerge
run: |
echo "::set-output name=AUTOMERGE::True"
travis_success:
name: Check if Travis build is successful
runs-on: ubuntu-latest
needs: [isautomerge]
if: ${{ needs.isautomerge.outputs.AUTOMERGE == 'True' }}
outputs:
TRAVIS_OK: ${{ steps.istravisok.outputs.TRAVIS_OK }}
steps:
- name: Get Travis build status
id: gettravisstatus
run: |
echo ${{ github.event.pull_request.head.sha }}
echo "TRAVIS_CONCLUSION=$(python -c "import requests; r = requests.get(\"https://api.github.com/repos/brain-score/language/commits/${{ github.event.pull_request.head.sha }}/check-runs\"); print(next(run['conclusion'] for run in r.json()['check_runs'] if run['name'] == 'Travis CI - Pull Request'))")" >> $GITHUB_ENV
- name: Check if Travis was successful
id: istravisok
run: |
if [ "$TRAVIS_CONCLUSION" == "success" ]
then
travisok=True
elif [ "$TRAVIS_CONCLUSION" == "None" ]
then
travisok=Wait
else
travisok=False
fi
echo "::set-output name=TRAVIS_OK::$travisok"
plugin_only:
name: Ensure PR ONLY changes plugin files
runs-on: ubuntu-latest
needs: travis_success
if: ${{ needs.travis_success.outputs.TRAVIS_OK == 'True' }}
outputs:
PLUGIN_ONLY: ${{ steps.ispluginonly.outputs.PLUGIN_ONLY }}
steps:
- name: Parse plugin_only confirmation from Travis status update
id: getpluginonlyvalue
run: echo "PLUGIN_ONLY=$(python -c "import requests; r = requests.get(\"https://api.github.com/repos/brain-score/language/statuses/$github.event.pull_request.head.sha\"); print(next(status['description'].split('- ')[1] for status in r.json() if status['description'].startswith('Run automerge workflow')))")" >> $GITHUB_ENV
- name: Check if PR is plugin only
id: ispluginonly
run: |
if [ "$PLUGIN_ONLY" == "True" ]
then
pluginonly=True
else
pluginonly=False
fi
echo "::set-output name=PLUGIN_ONLY::$pluginonly"
automerge:
name: If plugin-only, approve and merge
runs-on: ubuntu-latest
needs: plugin_only
if: ${{ needs.plugin_only.outputs.PLUGIN_ONLY == 'True' }}
steps:
- name: Auto Approve
uses: hmarr/[email protected]
- name: Auto Merge (GitHub submissions)
uses: plm9606/[email protected]
with:
github-token: ${{ secrets.WORKFLOW_TOKEN }}
label-name: "automerge"
merge-method: "squash"
auto-delete: "true"
- name: Auto Merge (brain-score.org submissions)
uses: plm9606/[email protected]
with:
github-token: ${{ secrets.WORKFLOW_TOKEN }}
label-name: "automerge-web"
merge-method: "squash"
auto-delete: "true"