-
Notifications
You must be signed in to change notification settings - Fork 3.9k
112 lines (100 loc) · 3.79 KB
/
upgrade-one-python-dependency.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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@v4
with:
ref: "${{ inputs.branch }}"
- name: Set up Python environment
uses: actions/setup-python@v5
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@v6
with:
branch: "${{ github.triggering_actor }}/upgrade-${{ inputs.package }}"
branch-suffix: short-commit-hash
add-paths: |
requirements
scripts/**/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