Skip to content

Commit a2fea84

Browse files
committed
build: update renovate.json and add sync-requirements.yml for automating update requirements.txt with uv.lock by GitHub Actions
1 parent 38ae1cc commit a2fea84

2 files changed

Lines changed: 83 additions & 11 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Sync Requirements
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'pyproject.toml'
7+
- 'uv.lock'
8+
types: [opened, synchronize, reopened]
9+
10+
jobs:
11+
sync-requirements:
12+
# Only run on Renovate PRs to avoid conflicts
13+
if: startsWith(github.head_ref, 'renovate/')
14+
runs-on: ubuntu-latest
15+
16+
permissions:
17+
contents: write
18+
pull-requests: write
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
with:
24+
# Use the head ref for PRs to commit back to the PR branch
25+
ref: ${{ github.head_ref }}
26+
token: ${{ secrets.GITHUB_TOKEN }}
27+
28+
- name: Install uv
29+
uses: astral-sh/setup-uv@v6
30+
with:
31+
version: "latest"
32+
33+
- name: Set up Python
34+
uses: actions/setup-python@v5
35+
with:
36+
python-version-file: ".python-version"
37+
38+
- name: Generate requirements.txt
39+
run: |
40+
echo "Generating requirements.txt from uv.lock..."
41+
uv export --frozen > requirements.txt
42+
43+
# Check if requirements.txt was modified
44+
if git diff --quiet requirements.txt; then
45+
echo "requirements.txt is already up to date"
46+
echo "requirements_updated=false" >> $GITHUB_ENV
47+
else
48+
echo "requirements.txt has been updated"
49+
echo "requirements_updated=true" >> $GITHUB_ENV
50+
fi
51+
52+
- name: Commit and push changes
53+
if: env.requirements_updated == 'true'
54+
run: |
55+
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
56+
git config --local user.name "github-actions[bot]"
57+
58+
git add requirements.txt
59+
git commit -m "chore(deps): sync requirements.txt with uv.lock
60+
61+
Auto-generated by GitHub Actions from uv export"
62+
63+
git push
64+
65+
- name: Comment on PR
66+
if: env.requirements_updated == 'true'
67+
uses: actions/github-script@v7
68+
with:
69+
script: |
70+
github.rest.issues.createComment({
71+
issue_number: context.issue.number,
72+
owner: context.repo.owner,
73+
repo: context.repo.repo,
74+
body: ':white_check_mark: **requirements.txt updated**\n\nGenerated from `uv.lock` using `uv export --no-hashes --frozen`'
75+
})

renovate.json

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,19 @@
1313
"matchUpdateTypes": ["minor", "patch"],
1414
"groupName": "Python Dependencies (Minor/Patch)",
1515
"addLabels": ["dependencies"],
16-
"postUpgradeTasks": {
17-
"commands": ["uv export --no-hashes > requirements.txt"],
18-
"fileFilters": ["requirements.txt"],
19-
"executionMode": "update"
20-
}
16+
"automerge": false
2117
},
2218
{
2319
"matchManagers": ["pep621"],
2420
"matchUpdateTypes": ["major"],
2521
"groupName": "Python Dependencies (Major)",
26-
"addLabels": ["dependencies"],
27-
"postUpgradeTasks": {
28-
"commands": ["uv export --no-hashes > requirements.txt"],
29-
"fileFilters": ["requirements.txt"],
30-
"executionMode": "update"
31-
}
22+
"addLabels": ["dependencies"]
23+
},
24+
{
25+
"matchDepNames": ["python"],
26+
"groupName": null,
27+
"dependencyDashboardApproval": true,
28+
"addLabels": ["dependencies"]
3229
},
3330
{
3431
"matchFileNames": ["requirements.txt"],

0 commit comments

Comments
 (0)