Upgrade one Python dependency #208
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: Upgrade one Python dependency | |
on: | |
workflow_dispatch: | |
inputs: | |
branch: | |
description: 'Target branch to create requirements PR against' | |
required: true | |
default: 'master' | |
type: string | |
package: | |
description: 'Name of package to upgrade' | |
required: true | |
type: string | |
version: | |
description: 'Version number to upgrade to in constraints.txt (only needed if pinned)' | |
default: '' | |
type: string | |
change_desc: | |
description: | | |
Description of change, for commit message and PR. (What does the new version add or fix?) | |
default: '' | |
type: string | |
defaults: | |
run: | |
shell: bash # making this explicit opts into -e -o pipefail | |
jobs: | |
upgrade-one-python-dependency: | |
runs-on: ubuntu-20.04 | |
steps: | |
- name: Check out target branch | |
uses: actions/checkout@v3 | |
with: | |
ref: "${{ inputs.branch }}" | |
- name: Set up Python environment | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.8" | |
- name: Update any pinned dependencies | |
env: | |
NEW_VERSION: "${{ inputs.version }}" | |
PACKAGE: "${{ inputs.package }}" | |
run: | | |
sed 's/^\('$PACKAGE'[^#]*\)==[^ #]\+/\1=='$NEW_VERSION'/' -i requirements/constraints.txt | |
- name: Run make upgrade-package | |
env: | |
PACKAGE: "${{ inputs.package }}" | |
run: | | |
make upgrade-package package="$PACKAGE" | |
- name: PR preflight | |
env: | |
CHANGE_DESC: "${{ inputs.change_desc }}" | |
run: | | |
if git diff --exit-code; then | |
# Fail early (and avoid quiet failure of create-pull-request action) | |
echo "Error: No changes, so not creating PR." | tee -a "$GITHUB_STEP_SUMMARY" | |
exit 1 | |
else | |
# There are changes to commit, so prep some info for the PR. | |
# This is honestly a lot to go through just to say "add two newlines | |
# on the end if the variable isn't empty" but I guess this is what we | |
# have to do to get a conditional delimiter. | |
if [[ -z "$CHANGE_DESC" ]]; then | |
echo "body_prefix=" >> "$GITHUB_ENV" | |
else | |
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) | |
echo "body_prefix<<$EOF" >> "$GITHUB_ENV" | |
echo "$CHANGE_DESC" >> "$GITHUB_ENV" | |
echo "" >> "$GITHUB_ENV" | |
echo "" >> "$GITHUB_ENV" | |
echo "$EOF" >> "$GITHUB_ENV" | |
fi | |
fi | |
- name: Make a PR | |
id: make-pr | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
branch: "${{ github.triggering_actor }}/upgrade-${{ inputs.package }}" | |
branch-suffix: short-commit-hash | |
add-paths: requirements | |
commit-message: | | |
feat: Upgrade Python dependency ${{ inputs.package }} | |
${{ env.body_prefix }}Commit generated by workflow `${{ github.workflow_ref }}` | |
title: "feat: Upgrade Python dependency ${{ inputs.package }}" | |
body: >- | |
${{ env.body_prefix }}PR generated by workflow `${{ github.workflow_ref }}` | |
on behalf of @${{ github.triggering_actor }}. | |
assignees: "${{ github.triggering_actor }}" | |
reviewers: "${{ github.triggering_actor }}" | |
- name: Job summary | |
env: | |
PR_URL: "${{ steps.make-pr.outputs.pull-request-url }}" | |
run: | | |
if [[ -z "$PR_URL" ]]; then | |
echo "PR not created; see log for more information" | tee -a "$GITHUB_STEP_SUMMARY" | |
exit 1 | |
else | |
echo "PR created or updated: $PR_URL" | tee -a "$GITHUB_STEP_SUMMARY" | |
fi |