-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (84 loc) · 3.05 KB
/
update_dependencies.yaml
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
name: Update dependencies
on:
schedule:
- cron: '0 0 * * 0' # Runs at 00:00 every Sunday
workflow_dispatch:
inputs:
pr_branch:
description: 'Branch to push changes to (optional)'
required: false
type: string
workflow_call:
inputs:
pr_branch:
description: 'Branch to push changes to'
required: true
type: string
jobs:
update-deps:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
name: Checkout repository
with:
fetch-depth: 0 # Fetch all history for all branches
- name: Checkout target branch
if: inputs.pr_branch
run: |
BRANCH_NAME=$(echo ${{ inputs.pr_branch }} | sed 's|refs/heads/||')
git fetch origin $BRANCH_NAME
git checkout $BRANCH_NAME
git pull origin $BRANCH_NAME
- name: Setup PDM
uses: pdm-project/setup-pdm@v4
with:
cache: true
- name: Lock dependencies
run: pdm lock -G :all
- name: Export requirements
run: pdm run export
- name: Check for changes
id: git-check
run: |
git diff --exit-code --quiet requirements.txt || echo "changed=true" >> $GITHUB_OUTPUT
- name: Handle dependency updates
if: steps.git-check.outputs.changed == 'true'
run: |
git config user.name github-actions
git config user.email [email protected]
if [ -n "${{ inputs.pr_branch }}" ]; then
# Push to existing branch
BRANCH_NAME=$(echo ${{ inputs.pr_branch }} | cut -d'/' -f 3)
git checkout $BRANCH_NAME
git add requirements.txt pyproject.toml pdm.lock
git commit -m "Update dependencies"
git push origin $BRANCH_NAME
else
# Check for existing PR
EXISTING_PR=$(gh pr list --search "Update dependencies in:title is:open" --json headRefName,number -q '.[0]')
if [ -n "$EXISTING_PR" ]; then
# Update existing PR
BRANCH_NAME=$(echo $EXISTING_PR | jq -r .headRefName)
git checkout -B $BRANCH_NAME
git add requirements.txt pyproject.toml pdm.lock
git commit -m "Update dependencies"
git push -f origin $BRANCH_NAME
else
# Create new branch and PR
NEW_BRANCH="update-dependencies-${{ github.run_id }}"
git checkout -b $NEW_BRANCH
git add requirements.txt pyproject.toml pdm.lock
git commit -m "Update dependencies"
git push origin $NEW_BRANCH
gh pr create \
--title "Update dependencies" \
--body "This PR updates the project dependencies. Please review the changes and merge if everything looks good." \
--base ${{ github.ref_name }} \
--head $NEW_BRANCH
fi
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}