#458 Automate Docker Requirements Workflow for PR Creation and Review… #37
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: docker-requirements | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- ".github/workflows/update-docker-requirements.yml" | |
- "pyproject.toml" | |
- "requirements-docker.lock" | |
workflow_dispatch: | |
permissions: | |
pull-requests: write | |
contents: write | |
issues: write | |
jobs: | |
update: | |
runs-on: ubuntu-latest | |
defaults: | |
run: | |
shell: bash -el {0} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup environment | |
uses: ./.github/actions/setup-env | |
with: | |
python-version: "3.11" | |
optional-dependencies: "false" | |
- name: Update docker requirements | |
id: update | |
run: | | |
pip-compile \ | |
--quiet \ | |
--strip-extras --output-file=requirements-docker.lock \ | |
--extra=all pyproject.toml | |
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}') | |
AUTHOR=$(echo ${PR_INFO} | jq -r .author) | |
MERGER=$(echo ${PR_INFO} | jq -r .merger) | |
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 | |
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: main | |
title: Update requirements-docker.lock | |
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 }} | |
- name: Create failure issue | |
if: failure() | |
uses: JasonEtco/create-an-issue@v2 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | |
with: | |
filename: .github/ISSUE_TEMPLATE/DOCKER_ISSUE_TEMPLATE.md |