diff --git a/.github/workflows/dependency-checker.yaml b/.github/workflows/dependency-checker.yaml index b9f57ddf..8a84b199 100644 --- a/.github/workflows/dependency-checker.yaml +++ b/.github/workflows/dependency-checker.yaml @@ -24,30 +24,30 @@ jobs: git config --global user.email "noreply@stackit.de" pip install poetry + + pr_name=$(echo "Dependency Updates") + make update-dependencies - for file in $(git diff --name-only | grep poetry.lock); do - # Extract the service for which the dependencies have been updated - dirpath=$(dirname $file) - pr_name=$(echo "Dependency Updater: ${dirpath}") - - # Check if a PR already exists for the package - if gh pr list --state open | grep -q "${pr_name}"; then - echo "Pr for $dirpath already exists. Deleting old PR." - pr_number=$(gh pr list --state open --json number --search "$pr_name" -q '.[0].number') - gh pr close "$pr_number" --delete-branch + branch_name="dependency-updater-${{ github.run_id }}" + git checkout -b "$branch_name" - fi - - # Create PR - branch_name="dependency-updater-$dirpath-${{ github.run_id }}" - git checkout -b "$branch_name" - git add "$file" - git commit -m "chore: dependency update" - git push --set-upstream origin "$branch_name" - echo $(git status) - gh pr create --title "$pr_name" --body "Automated dependency update" --base "main" - git checkout main - sleep 30 # prevent rate limit. - - done + if [ -n "$(git diff --name-only)" ]; then + for file in $(git diff --name-only | grep poetry.lock); do + # Extract the service for which the dependencies have been updated + dirpath=$(dirname $file) + git add "$file" + git commit -m "chore: dependency update for ${dirpath}" + done + + # Check if a PR already exists for dependency updates + if gh pr list --state open | grep -q "${pr_name}"; then + echo "Pr for $dirpath already exists. Deleting old PR." + pr_number=$(gh pr list --state open --json number --search "$pr_name" -q '.[0].number') + gh pr close "$pr_number" --delete-branch + fi + git push --set-upstream origin "$branch_name" + gh pr create --title "$pr_name" --body "Automated dependency update" --base "main" + else + echo "No changes detected. Skipping PR creation." + fi