Merge pull request #5 from arjxn-py/test #27
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 | |
workflow_dispatch: | |
permissions: | |
pull-requests: write | |
contents: 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: Install GitHub CLI | |
run: sudo apt-get install gh | |
- 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: Get last merged PR info | |
id: pr_info | |
env: | |
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | |
run: | | |
LAST_MERGED_PR=$(gh pr list --repo $GITHUB_REPOSITORY --state closed --json number --jq '.[0].number') | |
echo "Last merged PR number: $LAST_MERGED_PR" | |
PR_INFO=$(gh pr view $LAST_MERGED_PR --repo $GITHUB_REPOSITORY --json author,mergedBy --jq '{author: .author.login, mergedBy: .mergedBy.login}') | |
echo "PR Info: $PR_INFO" | |
echo "pr_author=$(echo $PR_INFO | jq -r .author)" >> $GITHUB_ENV | |
echo "pr_mergedBy=$(echo $PR_INFO | jq -r .mergedBy)" >> $GITHUB_ENV | |
echo "PR Author: $(echo $PR_INFO | jq -r .author)" | |
echo "PR MergedBy: $(echo $PR_INFO | jq -r .mergedBy)" | |
- 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: ${{ github.head_ref || github.ref_name }} | |
title: Update requirements-docker.lock | |
# prettier-ignore | |
body: | |
https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
reviewers: ${{ env.pr_author }},${{ env.pr_mergedBy }} | |
- name: Show diff | |
if: ${{ steps.update.outputs.needs-update }} | |
run: git diff --exit-code |