From 28871177b6102eb3b17e260341eaa05a861628c1 Mon Sep 17 00:00:00 2001 From: Adarsha Dinda Date: Thu, 19 Jun 2025 18:26:06 +0530 Subject: [PATCH] removed build_utils dependency from ceph pull request job --- .../config/definitions/ceph-pr-api.yml | 2 +- .../config/definitions/ceph-pr-commits.yml | 1 + .../definitions/ceph-pull-requests-arm64.yml | 2 +- .../config/definitions/ceph-pull-requests.yml | 2 +- .../ceph-windows-pull-requests.yml | 2 +- scripts/build_utils.sh | 64 ------------------ scripts/pr_checks.sh | 67 +++++++++++++++++++ 7 files changed, 72 insertions(+), 68 deletions(-) create mode 100644 scripts/pr_checks.sh diff --git a/ceph-pr-api/config/definitions/ceph-pr-api.yml b/ceph-pr-api/config/definitions/ceph-pr-api.yml index b2afd6a9..9c251b34 100644 --- a/ceph-pr-api/config/definitions/ceph-pr-api.yml +++ b/ceph-pr-api/config/definitions/ceph-pr-api.yml @@ -66,7 +66,7 @@ builders: - shell: !include-raw-verbatim: - - ../../../scripts/build_utils.sh + - ../../../scripts/pr_checks.sh - ../../build/build - ../../../scripts/dashboard/install-backend-api-test-deps.sh - ../../build/api diff --git a/ceph-pr-commits/config/definitions/ceph-pr-commits.yml b/ceph-pr-commits/config/definitions/ceph-pr-commits.yml index 38fa5446..fd81601c 100644 --- a/ceph-pr-commits/config/definitions/ceph-pr-commits.yml +++ b/ceph-pr-commits/config/definitions/ceph-pr-commits.yml @@ -73,6 +73,7 @@ - shell: !include-raw-verbatim: - ../../../scripts/build_utils.sh + - ../../../scripts/pr_checks.sh - ../../build/build publishers: diff --git a/ceph-pull-requests-arm64/config/definitions/ceph-pull-requests-arm64.yml b/ceph-pull-requests-arm64/config/definitions/ceph-pull-requests-arm64.yml index 624fa8c2..30140a9c 100644 --- a/ceph-pull-requests-arm64/config/definitions/ceph-pull-requests-arm64.yml +++ b/ceph-pull-requests-arm64/config/definitions/ceph-pull-requests-arm64.yml @@ -4,7 +4,7 @@ builders: - shell: !include-raw-verbatim: - - ../../../scripts/build_utils.sh + - ../../../scripts/pr_checks.sh - ../../build/build concurrent: true disabled: false diff --git a/ceph-pull-requests/config/definitions/ceph-pull-requests.yml b/ceph-pull-requests/config/definitions/ceph-pull-requests.yml index 8cef990c..f8d6a47d 100644 --- a/ceph-pull-requests/config/definitions/ceph-pull-requests.yml +++ b/ceph-pull-requests/config/definitions/ceph-pull-requests.yml @@ -62,7 +62,7 @@ builders: - shell: !include-raw-verbatim: - - ../../../scripts/build_utils.sh + - ../../../scripts/pr_checks.sh - ../../build/build publishers: diff --git a/ceph-windows-pull-requests/config/definitions/ceph-windows-pull-requests.yml b/ceph-windows-pull-requests/config/definitions/ceph-windows-pull-requests.yml index abd1d797..23e82283 100644 --- a/ceph-windows-pull-requests/config/definitions/ceph-windows-pull-requests.yml +++ b/ceph-windows-pull-requests/config/definitions/ceph-windows-pull-requests.yml @@ -67,7 +67,7 @@ builders: - shell: !include-raw-verbatim: - - ../../../scripts/build_utils.sh + - ../../../scripts/pr_checks.sh - ../../build/check_docs_pr_only - ../../../scripts/ceph-windows/setup_libvirt - ../../../scripts/ceph-windows/setup_libvirt_ubuntu_vm diff --git a/scripts/build_utils.sh b/scripts/build_utils.sh index d753ba9a..b14b9055 100755 --- a/scripts/build_utils.sh +++ b/scripts/build_utils.sh @@ -1679,70 +1679,6 @@ maybe_reset_ci_container() { fi } -# NOTE: These functions will only work on a Pull Request job! -pr_only_for() { - # $1 is passed by reference to avoid having to call with ${array[@]} and - # receive by creating another local array ("$@") - local -n local_patterns=$1 - local files - pushd . - # cd to ceph repo if we need to. - # The ceph-pr-commits job checks out ceph.git and ceph-build.git but most - # other jobs do not. - if ! [[ "$(git config --get remote.origin.url)" =~ "ceph/ceph.git" ]]; then - cd "$WORKSPACE/ceph" - fi - if [ -f $(git rev-parse --git-dir)/shallow ]; then - # We can't do a regular `git diff` in a shallow clone. There is no other way to check files changed. - files="$(curl -s -u ${GITHUB_USER}:${GITHUB_PASS} https://api.github.com/repos/${ghprbGhRepository}/pulls/${ghprbPullId}/files | jq '.[].filename' | tr -d '"')" - else - files="$(git diff --name-only origin/${ghprbTargetBranch}...origin/pr/${ghprbPullId}/head)" - fi - popd - echo -e "changed files:\n$files" - # 0 is true, 1 is false - local all_match=0 - for f in $files; do - local match=1 - for p in "${local_patterns[@]}"; do - # pattern loop: if one pattern matches, skip the others - if [[ $f == $p ]]; then match=0; break; fi - done - # file loop: if this file matched no patterns, the group fails - # (one mismatch spoils the whole bushel) - if [[ $match -eq 1 ]] ; then all_match=1; break; fi - done - return $all_match -} - -docs_pr_only() { - DOCS_ONLY=false - local patterns=( - 'doc/*' - 'admin/*' - 'src/sample.ceph.conf' - 'CodingStyle' - '*.rst' - '*.md' - 'COPYING*' - 'README.*' - 'SubmittingPatches' - '.readthedocs.yml' - 'PendingReleaseNotes' - ) - if pr_only_for patterns; then DOCS_ONLY=true; fi -} - -container_pr_only() { - CONTAINER_ONLY=false - local patterns=( - 'container/*' - 'Dockerfile.build' - 'src/script/buildcontainer-setup.sh' - 'src/script/build-with-container.py' - ) - if pr_only_for patterns; then CONTAINER_ONLY=true; fi -} function ssh_exec() { if [[ -z $SSH_ADDRESS ]]; then diff --git a/scripts/pr_checks.sh b/scripts/pr_checks.sh new file mode 100644 index 00000000..bf422c64 --- /dev/null +++ b/scripts/pr_checks.sh @@ -0,0 +1,67 @@ +#!/bin/bash -ex +# vim: ts=4 sw=4 expandtab + +# NOTE: These functions will only work on a Pull Request job! +pr_only_for() { + # $1 is passed by reference to avoid having to call with ${array[@]} and + # receive by creating another local array ("$@") + local -n local_patterns=$1 + local files + pushd . + # cd to ceph repo if we need to. + # The ceph-pr-commits job checks out ceph.git and ceph-build.git but most + # other jobs do not. + if ! [[ "$(git config --get remote.origin.url)" =~ "ceph/ceph.git" ]]; then + cd "$WORKSPACE/ceph" + fi + if [ -f $(git rev-parse --git-dir)/shallow ]; then + # We can't do a regular `git diff` in a shallow clone. There is no other way to check files changed. + files="$(curl -s -u ${GITHUB_USER}:${GITHUB_PASS} https://api.github.com/repos/${ghprbGhRepository}/pulls/${ghprbPullId}/files | jq '.[].filename' | tr -d '"')" + else + files="$(git diff --name-only origin/${ghprbTargetBranch}...origin/pr/${ghprbPullId}/head)" + fi + popd + echo -e "changed files:\n$files" + # 0 is true, 1 is false + local all_match=0 + for f in $files; do + local match=1 + for p in "${local_patterns[@]}"; do + # pattern loop: if one pattern matches, skip the others + if [[ $f == $p ]]; then match=0; break; fi + done + # file loop: if this file matched no patterns, the group fails + # (one mismatch spoils the whole bushel) + if [[ $match -eq 1 ]] ; then all_match=1; break; fi + done + return $all_match +} + +docs_pr_only() { + DOCS_ONLY=false + local patterns=( + 'doc/*' + 'admin/*' + 'src/sample.ceph.conf' + 'CodingStyle' + '*.rst' + '*.md' + 'COPYING*' + 'README.*' + 'SubmittingPatches' + '.readthedocs.yml' + 'PendingReleaseNotes' + ) + if pr_only_for patterns; then DOCS_ONLY=true; fi +} + +container_pr_only() { + CONTAINER_ONLY=false + local patterns=( + 'container/*' + 'Dockerfile.build' + 'src/script/buildcontainer-setup.sh' + 'src/script/build-with-container.py' + ) + if pr_only_for patterns; then CONTAINER_ONLY=true; fi +} \ No newline at end of file -- 2.39.5