From a482f2f2c83ff5590fa7404895d635442850ceb3 Mon Sep 17 00:00:00 2001 From: Melvin Klein Date: Thu, 28 Nov 2024 09:37:06 +0000 Subject: [PATCH 1/4] rework pipeline --- .github/workflows/dependency-checker.yaml | 36 +++++++++++------------ 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/.github/workflows/dependency-checker.yaml b/.github/workflows/dependency-checker.yaml index b9f57ddf..892a5f3c 100644 --- a/.github/workflows/dependency-checker.yaml +++ b/.github/workflows/dependency-checker.yaml @@ -24,30 +24,28 @@ jobs: git config --global user.email "noreply@stackit.de" pip install poetry + + pr_name=$(echo "Dependency Update") + make update-dependencies + branch_name="dependency-updater-${{ github.run_id }}" + git checkout -b "$branch_name" 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 + dirpath=$(dirname $file) - 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. - + git commit -m "chore: dependency update" done + + # 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 + fi + + git push --set-upstream origin "$branch_name" + gh pr create --title "$pr_name" --body "Automated dependency update" --base "main" From 03fc16d5112b7267d8f70d98e27843780609630d Mon Sep 17 00:00:00 2001 From: Melvin Klein Date: Thu, 28 Nov 2024 09:42:07 +0000 Subject: [PATCH 2/4] only create pr if required --- .github/workflows/dependency-checker.yaml | 36 ++++++++++++----------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/.github/workflows/dependency-checker.yaml b/.github/workflows/dependency-checker.yaml index 892a5f3c..62b2598a 100644 --- a/.github/workflows/dependency-checker.yaml +++ b/.github/workflows/dependency-checker.yaml @@ -30,22 +30,24 @@ jobs: make update-dependencies branch_name="dependency-updater-${{ github.run_id }}" git checkout -b "$branch_name" - for file in $(git diff --name-only | grep poetry.lock); do - # Extract the service for which the dependencies have been updated - dirpath=$(dirname $file) - # Create PR - git add "$file" - git commit -m "chore: dependency update" - done - - # 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 - fi - - git push --set-upstream origin "$branch_name" - gh pr create --title "$pr_name" --body "Automated dependency update" --base "main" + 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 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 + 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 From 9afa44e2b7bfd9b0e15f524b83a41b58539902f7 Mon Sep 17 00:00:00 2001 From: Melvin <70433111+MelvinKl@users.noreply.github.com> Date: Thu, 28 Nov 2024 10:55:34 +0100 Subject: [PATCH 3/4] Update .github/workflows/dependency-checker.yaml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Palet --- .github/workflows/dependency-checker.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dependency-checker.yaml b/.github/workflows/dependency-checker.yaml index 62b2598a..ab54f0fa 100644 --- a/.github/workflows/dependency-checker.yaml +++ b/.github/workflows/dependency-checker.yaml @@ -39,7 +39,7 @@ jobs: git commit -m "chore: dependency update for ${dirpath}" done - # Check if a PR already exists for the package + # 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') From 2fdeb3f17b8711c615b2b16af2a1a73f17fd0e7b Mon Sep 17 00:00:00 2001 From: Melvin <70433111+MelvinKl@users.noreply.github.com> Date: Thu, 28 Nov 2024 10:55:55 +0100 Subject: [PATCH 4/4] Update .github/workflows/dependency-checker.yaml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Palet --- .github/workflows/dependency-checker.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dependency-checker.yaml b/.github/workflows/dependency-checker.yaml index ab54f0fa..8a84b199 100644 --- a/.github/workflows/dependency-checker.yaml +++ b/.github/workflows/dependency-checker.yaml @@ -25,7 +25,7 @@ jobs: pip install poetry - pr_name=$(echo "Dependency Update") + pr_name=$(echo "Dependency Updates") make update-dependencies branch_name="dependency-updater-${{ github.run_id }}"