Skip to content

Commit acf1cc5

Browse files
authored
👷 Reuse branch in update_dependencies.yaml (#71)
1 parent 7be7f05 commit acf1cc5

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

.github/workflows/update_dependencies.yaml

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
run: |
5656
git config user.name github-actions
5757
git config user.email github-actions@github.com
58-
58+
5959
if [ -n "${{ inputs.pr_branch }}" ]; then
6060
# Push to existing branch
6161
BRANCH_NAME=$(echo ${{ inputs.pr_branch }} | cut -d'/' -f 3)
@@ -64,18 +64,30 @@ jobs:
6464
git commit -m "Update dependencies"
6565
git push origin $BRANCH_NAME
6666
else
67-
# Create new branch and PR
68-
NEW_BRANCH="update-dependencies-${{ github.run_id }}"
69-
git checkout -b $NEW_BRANCH
70-
git add requirements.txt pyproject.toml pdm.lock
71-
git commit -m "Update dependencies"
72-
git push origin $NEW_BRANCH
73-
74-
gh pr create \
75-
--title "Update dependencies" \
76-
--body "This PR updates the project dependencies. Please review the changes and merge if everything looks good." \
77-
--base ${{ github.ref_name }} \
78-
--head $NEW_BRANCH
67+
# Check for existing PR
68+
EXISTING_PR=$(gh pr list --search "Update dependencies in:title is:open" --json headRefName,number -q '.[0]')
69+
70+
if [ -n "$EXISTING_PR" ]; then
71+
# Update existing PR
72+
BRANCH_NAME=$(echo $EXISTING_PR | jq -r .headRefName)
73+
git checkout -B $BRANCH_NAME
74+
git add requirements.txt pyproject.toml pdm.lock
75+
git commit -m "Update dependencies"
76+
git push -f origin $BRANCH_NAME
77+
else
78+
# Create new branch and PR
79+
NEW_BRANCH="update-dependencies-${{ github.run_id }}"
80+
git checkout -b $NEW_BRANCH
81+
git add requirements.txt pyproject.toml pdm.lock
82+
git commit -m "Update dependencies"
83+
git push origin $NEW_BRANCH
84+
85+
gh pr create \
86+
--title "Update dependencies" \
87+
--body "This PR updates the project dependencies. Please review the changes and merge if everything looks good." \
88+
--base ${{ github.ref_name }} \
89+
--head $NEW_BRANCH
90+
fi
7991
fi
8092
env:
8193
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)