-
Notifications
You must be signed in to change notification settings - Fork 1
192 lines (174 loc) · 7.91 KB
/
ci_update_dependencies.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
name: CI - Update dependencies PR
on:
workflow_call:
inputs:
# REQUIRED
git_username:
description: "A git username (used to set the 'user.name' config option)."
required: true
type: string
git_email:
description: "A git user's email address (used to set the 'user.email' config option)."
required: true
type: string
# OPTIONAL
runner:
description: "The runner to use for the workflow. Note, the callable workflow expects a Linux/Unix system."
required: false
type: string
default: ubuntu-latest
permanent_dependencies_branch:
description: "The branch name for the permanent dependency updates branch."
required: false
type: string
default: "ci/dependency-updates"
default_repo_branch:
description: "The branch name of the repository's default branch. More specifically, the branch the PR should target."
required: false
type: string
default: main
pr_body_file:
description: "Relative path to PR body file from the root of the repository. Example: `'.github/utils/pr_body_update_deps.txt'`."
required: false
type: string
default: ""
pr_labels:
description: "A comma separated list of strings of GitHub labels to use for the created PR."
required: false
type: string
default: ""
extra_to_dos:
description: "A multi-line string (insert `\\n` to create line breaks) with extra 'to do' checks. Should start with `- [ ] `."
required: false
type: string
default: ""
update_pre-commit:
description: "Whether or not to update pre-commit hooks as part of creating the PR."
required: false
type: boolean
default: false
python_version:
description: "The Python version to use for the workflow. This is only relevant if `update_pre-commit` is `true`."
required: false
type: string
default: "3.9"
install_extras:
description: "Any extras to install from the local repository through 'pip'. Must be encapsulated in square parentheses (`[]`) and be separated by commas (`,`) without any spaces. Example: `'[dev,pre-commit]'`. This is only relevant if `update_pre-commit` is `true`."
required: false
type: string
default: ""
pip_index_url:
description: "A URL to a PyPI repository index. Defaults to 'https://pypi.org/simple/'."
required: false
type: string
default: "https://pypi.org/simple/"
pip_extra_index_urls:
description: "A space-delimited string of URLs to additional PyPI repository indices."
required: false
type: string
default: ""
skip_pre-commit_hooks:
description: "A comma-separated list of pre-commit hook IDs to skip when running `pre-commit` after updating hooks. This is only relevant if `update_pre-commit` is `true`."
required: false
type: string
default: ""
secrets:
PAT:
description: "A personal access token (PAT) with rights to update the `permanent_dependencies_branch`. This will fallback on `GITHUB_TOKEN`."
required: false
jobs:
create-collected-pr:
name: Single dependabot PR
runs-on: ${{ inputs.runner }}
steps:
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v4
with:
ref: ${{ inputs.default_repo_branch }}
- name: Set up git user info
run: |
git config --global user.name "${{ inputs.git_username }}"
git config --global user.email "${{ inputs.git_email }}"
- name: Reset to '${{ inputs.permanent_dependencies_branch }}'
run: |
git fetch origin ${{ inputs.permanent_dependencies_branch }}:${{ inputs.permanent_dependencies_branch }}
git reset --hard ${{ inputs.permanent_dependencies_branch }}
- name: Set up Python ${{ inputs.python_version }}
if: inputs.update_pre-commit
uses: actions/setup-python@v5
with:
python-version: "${{ inputs.python_version }}"
allow-prereleases: true
- name: Install `pre-commit` and dependencies
if: inputs.update_pre-commit
run: |
python -m pip install -U pip
pip install -U setuptools wheel
pip install pre-commit
pip install .${{ inputs.install_extras }}
env:
PIP_INDEX_URL: ${{ inputs.pip_index_url }}
PIP_EXTRA_INDEX_URL: ${{ inputs.pip_extra_index_urls }}
- name: Auto-update `pre-commit` hooks
id: update_pre_commit
if: inputs.update_pre-commit
run: |
pre-commit autoupdate
if [ -n "$(git status --porcelain .pre-commit-config.yaml)" ]; then
# Set environment variable notifying next steps that the hooks changed
echo "Pre-commit hooks have been updated !"
echo "updated_pre_commit_hooks=true" >> $GITHUB_OUTPUT
else
echo "No pre-commit hooks have been updated."
echo "updated_pre_commit_hooks=false" >> $GITHUB_OUTPUT
fi
- name: Possibly run `pre-commit` with updated hooks
if: inputs.update_pre-commit
continue-on-error: true # Still create the PR if this step fails
run: |
if [ "${{ steps.update_pre_commit.outputs.updated_pre_commit_hooks}}" == "true" ]; then
SKIP=${{ inputs.skip_pre-commit_hooks }} pre-commit run --all-files
fi
- name: Possibly commit changes and updates
if: inputs.update_pre-commit
run: |
if [ "${{ steps.update_pre_commit.outputs.updated_pre_commit_hooks}}" == "true" ]; then
git add -- .
git commit -m "Update \`pre-commit\` hooks"
fi
- name: Set PR body
id: pr_body_config
run: |
if [ -z "${{ inputs.pr_body_file }}" ] || [ ! -f "${{ inputs.pr_body_file }}" ]; then
PR_BODY_FILE=.tmp_pr-body_${{ github.run_id }}_${{ github.run_number }}_${{ github.run_attempt }}.txt
echo "pr_body_file=${PR_BODY_FILE}" >> $GITHUB_OUTPUT
echo -e "### Update dependencies\n\nAutomatically created PR from [\`${{ inputs.permanent_dependencies_branch }}\`](https://github.com/${{ github.repository }}/tree/${{ inputs.permanent_dependencies_branch }}).\n\nThe PR is based on the ['CI - Update dependencies PR' workflow](https://SINTEF.github.io/ci-cd/latest/workflows/ci_update_dependencies/) in [SINTEF/ci-cd](https://github.com/SINTEF/ci-cd).\n\n#### To do\n\n- [ ] Check that the diff is sensible, and that tests and builds pass with the new dependency versions.\n${{ inputs.extra_to_dos }}" > ${PR_BODY_FILE}
echo "Using default PR body."
echo "remove_pr_body_file=true" >> $GITHUB_OUTPUT
else
echo "Using found PR body text file at ${{ inputs.pr_body_file }}."
echo "pr_body_file=${{ inputs.pr_body_file }}" >> $GITHUB_OUTPUT
echo "remove_pr_body_file=false" >> $GITHUB_OUTPUT
fi
- name: Fetch PR body
id: pr_body
uses: chuhlomin/render-template@v1.10
with:
template: ${{ steps.pr_body_config.outputs.pr_body_file }}
- name: Remove temporary file
if: steps.pr_body_config.outputs.remove_pr_body_file == 'true'
run: rm -f ${{ steps.pr_body_config.outputs.pr_body_file }}
- name: Create PR
id: cpr
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
committer: "${{ inputs.git_username }} <${{ inputs.git_email }}>"
author: "${{ inputs.git_username }} <${{ inputs.git_email }}>"
branch: ci/update-dependencies
delete-branch: true
title: "[Auto-generated] Update dependencies"
body: ${{ steps.pr_body.outputs.result }}
labels: "${{ inputs.pr_labels }}"
- name: Information
run: 'echo "${{ steps.cpr.outputs.pull-request-operation }} PR #${{ steps.cpr.outputs.pull-request-number }}: ${{ steps.cpr.outputs.pull-request-url }}"'