From 87d14de4ef9d56970cc52033e062fb2442bac652 Mon Sep 17 00:00:00 2001 From: Hedi Nasr Date: Thu, 9 Jul 2026 15:17:46 +0200 Subject: [PATCH 1/2] BUILD-11718: reach 100% code coverage on config-poetry Add config-poetry to Sonar sources and extend ShellSpec tests to cover poetry_set_project_version sourcing, main(), provided versions, and GITHUB_ENV/GITHUB_OUTPUT writes. --- sonar-project.properties | 2 +- spec/config-poetry_spec.sh | 124 +++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index 8bebcf1a..85e0d272 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -4,7 +4,7 @@ sonar.projectName=ci-github-actions sonar.sourceEncoding=UTF-8 -sonar.sources=build-poetry,get-build-number,pr_cleanup,promote,build-gradle,build-maven,config-npm,build-npm,build-yarn,shared,config-pip,cache,code-signing,config-gradle,config-maven,check-sca,update-release-channel,report-ci-metrics +sonar.sources=build-poetry,get-build-number,pr_cleanup,promote,build-gradle,build-maven,config-npm,build-npm,build-yarn,shared,config-pip,config-poetry,cache,code-signing,config-gradle,config-maven,check-sca,update-release-channel,report-ci-metrics sonar.tests=spec sonar.coverageReportPaths=coverage/coverage_data/sonar_coverage.xml diff --git a/spec/config-poetry_spec.sh b/spec/config-poetry_spec.sh index 594c32b4..5d9d1ce1 100644 --- a/spec/config-poetry_spec.sh +++ b/spec/config-poetry_spec.sh @@ -34,6 +34,29 @@ Describe 'configure_poetry_repox()' The line 3 should include "jf config use repox" The line 4 should include "jf poetry-config --global --server-id-resolve repox --repo-resolve sonarsource-pypi" End + + It 'writes Poetry credentials to GITHUB_ENV' + GITHUB_ENV=$(mktemp) + export GITHUB_ENV + When call configure_poetry_repox + The status should be success + The line 1 should equal "$MESSAGE_CONFIGURING_POETRY" + The contents of file "$GITHUB_ENV" should include "POETRY_HTTP_BASIC_REPOX_USERNAME=test-user" + The contents of file "$GITHUB_ENV" should include "POETRY_HTTP_BASIC_REPOX_PASSWORD=test-token" + End + + It 'ignores missing repox JFrog configuration when removing config' + Mock jf + if [[ "$1" == "config" && "$2" == "remove" ]]; then + return 1 + fi + echo "jf $*" + End + When call configure_poetry_repox + The status should be success + The line 1 should equal "$MESSAGE_CONFIGURING_POETRY" + The line 2 should include "jf config add repox" + End End Describe 'main()' @@ -60,9 +83,63 @@ End export BUILD_NUMBER="42" export GITHUB_OUTPUT=/dev/null +Describe 'config-poetry/poetry_set_project_version.sh' + It 'does not run main when sourced' + When run source config-poetry/poetry_set_project_version.sh + The status should be success + The lines of output should equal 0 + The lines of error should equal 0 + End +End + Include config-poetry/poetry_set_project_version.sh Describe 'set_project_version()' + # shellcheck disable=SC2329,SC2317 + common_setup() { + GITHUB_OUTPUT=$(mktemp) + GITHUB_ENV=$(mktemp) + return 0 + } + # shellcheck disable=SC2329,SC2317 + common_cleanup() { + [[ -f "$GITHUB_OUTPUT" ]] && rm "$GITHUB_OUTPUT" + [[ -f "$GITHUB_ENV" ]] && rm "$GITHUB_ENV" + return 0 + } + + BeforeEach 'common_setup' + AfterEach 'common_cleanup' + + It 'uses provided CURRENT_VERSION and PROJECT_VERSION without changes' + export CURRENT_VERSION="1.2.3.dev" + export PROJECT_VERSION="1.2.3.42" + When call set_project_version + The status should be success + The line 1 should equal "Using provided CURRENT_VERSION 1.2.3.dev and PROJECT_VERSION 1.2.3.42 without changes." + The line 1 of contents of file "$GITHUB_OUTPUT" should equal "current-version=1.2.3.dev" + The line 2 of contents of file "$GITHUB_OUTPUT" should equal "project-version=1.2.3.42" + End + + It 'writes version outputs to GITHUB_OUTPUT and GITHUB_ENV' + Mock poetry + if [[ "$*" == "version -s" ]]; then + echo "1.2.3" + else + echo "poetry $*" + fi + End + When call set_project_version + The status should be success + The line 1 of contents of file "$GITHUB_OUTPUT" should equal "current-version=1.2.3" + The line 2 of contents of file "$GITHUB_OUTPUT" should equal "project-version=1.2.3.42" + The line 1 of contents of file "$GITHUB_ENV" should equal "CURRENT_VERSION=1.2.3" + The line 2 of contents of file "$GITHUB_ENV" should equal "PROJECT_VERSION=1.2.3.42" + The line 1 should equal "Replacing version 1.2.3 with 1.2.3.42" + The line 2 should include "poetry version 1.2.3.42" + The line 3 should equal "PROJECT_VERSION=1.2.3.42" + End + It 'appends .0 given version is 1.2 and append BUILD_NUMBER' Mock poetry if [[ "$*" == "version -s" ]]; then @@ -137,3 +214,50 @@ Describe 'set_project_version()' The status should be failure End End + +Describe 'poetry_set_project_version main()' + # shellcheck disable=SC2329,SC2317 + common_setup() { + GITHUB_OUTPUT=$(mktemp) + GITHUB_ENV=$(mktemp) + return 0 + } + # shellcheck disable=SC2329,SC2317 + common_cleanup() { + [[ -f "$GITHUB_OUTPUT" ]] && rm "$GITHUB_OUTPUT" + [[ -f "$GITHUB_ENV" ]] && rm "$GITHUB_ENV" + return 0 + } + + BeforeEach 'common_setup' + AfterEach 'common_cleanup' + + It 'runs set_project_version within a GitHub Actions group' + Mock poetry + if [[ "$*" == "version -s" ]]; then + echo "1.2.3" + else + echo "poetry $*" + fi + End + When run script config-poetry/poetry_set_project_version.sh + The status should be success + The line 1 should equal "::group::Set project version" + The line 2 should equal "Replacing version 1.2.3 with 1.2.3.42" + The line 3 should include "poetry version 1.2.3.42" + The line 4 should equal "PROJECT_VERSION=1.2.3.42" + The line 5 should equal "::endgroup::" + End + + It 'uses provided CURRENT_VERSION and PROJECT_VERSION without changes' + export CURRENT_VERSION="1.2.3.dev" + export PROJECT_VERSION="1.2.3.42" + When run script config-poetry/poetry_set_project_version.sh + The status should be success + The line 1 should equal "::group::Set project version" + The line 2 should equal "Using provided CURRENT_VERSION 1.2.3.dev and PROJECT_VERSION 1.2.3.42 without changes." + The line 3 should equal "::endgroup::" + The line 1 of contents of file "$GITHUB_OUTPUT" should equal "current-version=1.2.3.dev" + The line 2 of contents of file "$GITHUB_OUTPUT" should equal "project-version=1.2.3.42" + End +End From d471feb35d0c528eb332e8f0e5cda5fb12e7a7b4 Mon Sep 17 00:00:00 2001 From: Hedi Nasr Date: Fri, 10 Jul 2026 15:16:41 +0200 Subject: [PATCH 2/2] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- spec/config-poetry_spec.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/config-poetry_spec.sh b/spec/config-poetry_spec.sh index 5d9d1ce1..653da37e 100644 --- a/spec/config-poetry_spec.sh +++ b/spec/config-poetry_spec.sh @@ -220,6 +220,7 @@ Describe 'poetry_set_project_version main()' common_setup() { GITHUB_OUTPUT=$(mktemp) GITHUB_ENV=$(mktemp) + export GITHUB_OUTPUT GITHUB_ENV return 0 } # shellcheck disable=SC2329,SC2317