Skip to content

Commit

Permalink
automate docker workflow (#8)
Browse files Browse the repository at this point in the history
* Quansight#458 Disable running workflow on PRs & enable push on main

* Ping PR author & the person who merged

* Do not remove `workflow_dispatch`

* Try again after setting gh_token

* Secret names must not start with GITHUB_

* Skip CLI auth

* Also print PR info

* Apply suggestions from code review

Co-authored-by: Philip Meier <[email protected]>

* Enhance workflow, remove dependency on GH Token

* Now try with token

* Update .github/workflows/update-docker-requirements.yml

Co-authored-by: Philip Meier <[email protected]>

* Remove has_pr, have author in body

* Avoid tagging author if none

* Rely on exit code instead setting `PR_NUMBER` to None

---------

Co-authored-by: Philip Meier <[email protected]>
  • Loading branch information
arjxn-py and pmeier authored Jul 31, 2024
1 parent 7c5728a commit 79f77ea
Showing 1 changed file with 37 additions and 15 deletions.
52 changes: 37 additions & 15 deletions .github/workflows/update-docker-requirements.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
name: docker-requirements

on:
pull_request:
push:
branches:
- main
paths:
- ".github/workflows/update-docker-requirements.yml"
- "pyproject.toml"
Expand Down Expand Up @@ -42,24 +44,44 @@ jobs:
NEEDS_UPDATE=$(git diff --quiet && echo 'false' || echo 'true')
echo "needs-update=${NEEDS_UPDATE}" | tee --append $GITHUB_OUTPUT
- name: Check if commit is associated with a PR
id: pr-check
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
PR_NUMBER=$(gh api \
-H 'Accept: application/vnd.github+json' \
/repos/${{ github.repository }}/commits/${{ github.sha }}/pulls \
--jq '.[0].number')
if [ $? -eq 0 ]; then
PR_INFO=$(gh pr view ${PR_NUMBER} --json author,mergedBy --jq '{author: .author.login, merger: .mergedBy.login}')
if [ $? -eq 0 ]; then
AUTHOR=$(echo ${PR_INFO} | jq -r .author)
MERGER=$(echo ${PR_INFO} | jq -r .merger)
else
AUTHOR=${{ github.actor }}
MERGER="none"
fi
else
AUTHOR=${{ github.actor }}
MERGER="none"
fi
echo "author=${AUTHOR}" | tee --append $GITHUB_OUTPUT
echo "merger=${MERGER}" | tee --append $GITHUB_OUTPUT
- name: Open a PR to update the requirements
# prettier-ignore
if:
${{ steps.update.outputs.needs-update && github.event_name == 'workflow_dispatch' }}
if: ${{ steps.update.outputs.needs-update }}
uses: peter-evans/create-pull-request@v5
with:
commit-message: update requirements-docker.lock
branch: update-docker-requirements
branch-suffix: timestamp
base: ${{ github.head_ref || github.ref_name }}
base: main
title: Update requirements-docker.lock
# prettier-ignore
body:
https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
reviewers: ${{ github.actor }}

- name: Show diff
# prettier-ignore
if:
${{ steps.update.outputs.needs-update && github.event_name != 'workflow_dispatch' }}
run: git diff --exit-code
body: |
Automatic update of requirements-docker.lock.
[Workflow run details](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
${{ steps.pr-check.outputs.author != 'none' && format('cc @{0}', steps.pr-check.outputs.author) || '' }}
reviewers: ${{ steps.pr-check.outputs.merger }}

0 comments on commit 79f77ea

Please sign in to comment.