-
Notifications
You must be signed in to change notification settings - Fork 0
70 lines (63 loc) · 2.6 KB
/
dependabot-post.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
name: Dependabot post processing
on:
pull_request:
paths:
- "pyproject.toml"
permissions:
pull-requests: write
issues: write
repository-projects: write
jobs:
dependabot-post:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: "Checkout"
uses: actions/checkout@v3
- name: "Dependabot metadata"
id: metadata
uses: dependabot/fetch-metadata@v1
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: "Setup Python"
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: "Duplicate changes from Dependabot on pyproject template"
id: modify_state
shell: python
run: |
import json
import os
PYPROJECT_TOML_TEMPLATE_PATH = os.path.join('custom-template', 'pyproject.mustache')
with open(PYPROJECT_TOML_TEMPLATE_PATH, 'r') as pyproject_template_file:
pyproject_template_content = pyproject_template_file.read()
has_changes = False
json_data = '${{steps.metadata.outputs.updated-dependencies-json}}'
updated_dependencies = json.loads(json_data)
for dependency in updated_dependencies:
dependency_name = dependency['dependencyName']
current_version = dependency['prevVersion']
updated_version = dependency['newVersion']
package_ecosystem = dependency['packageEcosystem']
# replace version in pyproject.toml template content
if package_ecosystem == 'pip':
version_str = f'{dependency_name} = "^%s"'
pyproject_template_content = pyproject_template_content.replace(
version_str % current_version,
version_str % updated_version
)
has_changes = True
if has_changes:
# rewrite updated pyproject.toml template file
with open(PYPROJECT_TOML_TEMPLATE_PATH, 'w') as pyproject_template_file:
pyproject_template_file.write(pyproject_template_content)
print('::set-output name=has_changes::true')
else:
print('::set-output name=has_changes::false')
- name: "Commit pyproject template changes"
uses: stefanzweifel/git-auto-commit-action@v4
if: ${{steps.modify_state.outputs.has_changes}} == 'true'
with:
commit_message: "Update dependencies in pyproject.mustache"
file_pattern: custom-template/pyproject.mustache