-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild-poetry_spec.sh
More file actions
executable file
·668 lines (619 loc) · 26.3 KB
/
build-poetry_spec.sh
File metadata and controls
executable file
·668 lines (619 loc) · 26.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
#!/bin/bash
eval "$(shellspec - -c) exit 1"
Mock python
echo "python $*"
End
Mock poetry
echo "poetry $*"
End
Mock jf
echo "jf $*"
End
# Minimal environment variables
export GITHUB_ENV=/dev/null
export ARTIFACTORY_URL="https://dummy.repox"
export ARTIFACTORY_PYPI_REPO="<repox pypi repo>"
export ARTIFACTORY_ACCESS_TOKEN="dummy access token"
export ARTIFACTORY_USERNAME="dummy-user"
export ARTIFACTORY_DEPLOY_REPO="<deploy repo>"
export ARTIFACTORY_DEPLOY_ACCESS_TOKEN="<deploy token>"
export GITHUB_REPOSITORY="my-org/my-repo"
export DEFAULT_BRANCH="main"
export GITHUB_REF_NAME="any-branch"
export GITHUB_EVENT_NAME="push"
export BUILD_NUMBER="42"
export PULL_REQUEST=""
GITHUB_EVENT_PATH=$(mktemp)
export GITHUB_EVENT_PATH
export GITHUB_OUTPUT=/dev/null
export SONAR_HOST_URL="https://sonarqube.test"
export SONAR_TOKEN="dummy-sonar-token"
export GITHUB_SHA="dummy-sha"
export GITHUB_RUN_ID="dummy-run-id"
export SONAR_PLATFORM="next"
export NEXT_URL="https://next.sonarqube.com"
export NEXT_TOKEN="next-token"
export SQC_US_URL="https://sonarqube-us.com"
export SQC_US_TOKEN="sqc-us-token"
export SQC_EU_URL="https://sonarcloud.io"
export SQC_EU_TOKEN="sqc-eu-token"
export DEPLOY="true"
export RUN_SHADOW_SCANS="false"
# Constant outputs (exported so mocks run in subshells can access it)
export JQ_VERSION_OUTPUT="jq-1.8.1"
Describe 'build-poetry/build.sh'
It 'does not run build_poetry() if the script is sourced'
When run source build-poetry/build.sh
The status should be success
The output should equal ""
End
It 'runs build_poetry()'
Mock poetry
if [[ "$*" == "version -s" ]]; then
echo "1.2"
else
echo "poetry $*"
fi
End
Mock git
echo "git $*"
End
Mock jq
echo "$JQ_VERSION_OUTPUT"
End
GITHUB_OUTPUT=$(mktemp)
export GITHUB_OUTPUT
When run script build-poetry/build.sh
The status should be success
The lines of stdout should equal 37
The line 1 should equal "::group::Check tools"
The line 2 should include "jq"
The line 3 should include "jq"
The line 4 should include "python"
The line 5 should include "python"
The line 6 should include "poetry"
The line 7 should include "poetry"
The line 8 should include "jf"
The line 9 should include "jf"
The line 10 should equal "::endgroup::"
The line 11 should equal "::group::Configure build environment"
The line 12 should equal "PROJECT: my-repo"
The line 13 should equal "Fetch Git references for SonarQube analysis..."
The line 14 should equal "git fetch --unshallow"
The line 15 should equal "::endgroup::"
The line 16 should equal "=== Poetry Build, Deploy, and Analyze ==="
The line 17 should equal "Branch: any-branch"
The line 18 should equal "Pull Request: "
The line 19 should equal "Deploy Pull Request: false"
The line 20 should equal "::group::Set project version"
The line 21 should equal "Replacing version 1.2 with 1.2.0.42"
The line 22 should equal "poetry version 1.2.0.42"
The line 23 should equal "PROJECT_VERSION=1.2.0.42"
The line 24 should equal "::endgroup::"
The line 25 should equal "======= Build other branch ======="
The line 26 should equal "::group::Install dependencies"
The line 27 should equal "Installing dependencies..."
The line 28 should equal "jf config add repox --url https://dummy.repox --artifactory-url https://dummy.repox --access-token dummy access token"
The line 29 should equal "jf config use repox"
The line 30 should equal "jf poetry-config --server-id-resolve repox --repo-resolve <repox pypi repo>"
The line 31 should equal "poetry install"
The line 32 should equal "::endgroup::"
The line 33 should equal "::group::Build project"
The line 35 should equal "poetry build"
The line 36 should equal "::endgroup::"
The line 37 should equal "=== Build completed successfully ==="
End
End
Include build-poetry/build.sh
Describe 'set_build_env()'
It 'sets the project name and do git fetch'
Mock git
echo "git $*"
End
When call set_build_env
The status should be success
The line 1 should equal "PROJECT: my-repo"
The line 2 should equal "Fetch Git references for SonarQube analysis..."
The variable PROJECT should equal "my-repo"
End
It 'Fetches base branch for SonarQube analysis'
Mock git
if [[ "$*" == "rev-parse --is-shallow-repository --quiet" ]]; then
return 1
else
echo "git $*"
fi
End
export GITHUB_BASE_REF="main"
When call set_build_env
The status should be success
The line 1 should equal "PROJECT: my-repo"
The line 2 should equal "Fetch main for SonarQube analysis..."
The variable PROJECT should equal "my-repo"
End
End
Describe 'export_built_artifacts()'
# shellcheck disable=SC2329,SC2317 # Function invoked indirectly by Before
setup() {
mkdir -p dist
return 0
}
# shellcheck disable=SC2329,SC2317 # Function invoked indirectly by After
cleanup() {
[[ -f "$GITHUB_OUTPUT" ]] && rm -f "$GITHUB_OUTPUT"
rm -rf dist
return 0
}
Before 'setup'
After 'cleanup'
It 'captures built artifacts when deployment is enabled'
GITHUB_OUTPUT=$(mktemp)
export GITHUB_OUTPUT
echo "should-deploy=true" >> "$GITHUB_OUTPUT"
touch dist/pkg-1.0.0.42.whl
Mock grep
echo "should-deploy=true"
End
When call export_built_artifacts
The status should be success
The lines of stdout should equal 4
The line 1 should equal "::group::Capturing built artifacts for attestation"
The line 2 should equal "Found artifacts for attestation:"
The line 3 should equal "dist/pkg-1.0.0.42.whl"
The line 4 should equal "::endgroup::"
The contents of file "$GITHUB_OUTPUT" should include "artifact-paths<<EOF"
The contents of file "$GITHUB_OUTPUT" should include "dist/pkg-1.0.0.42.whl"
End
It 'skips silently when deployment is disabled'
GITHUB_OUTPUT=$(mktemp)
export GITHUB_OUTPUT
echo "should-deploy=false" >> "$GITHUB_OUTPUT"
touch dist/ignored.whl
When call export_built_artifacts
The status should be success
The output should be blank
The contents of file "$GITHUB_OUTPUT" should not include "artifact-paths<<EOF"
End
It 'reports no artifacts found when build directory is empty'
GITHUB_OUTPUT=$(mktemp)
export GITHUB_OUTPUT
echo "should-deploy=true" >> "$GITHUB_OUTPUT"
Mock grep
echo "should-deploy=true"
End
When call export_built_artifacts
The status should be success
The lines of stdout should equal 2
The line 1 should equal "::group::Capturing built artifacts for attestation"
The line 2 should equal "::endgroup::"
The stderr should include "::warning title=No artifacts found::No artifacts found for attestation in build output directories"
The lines of contents of file "$GITHUB_OUTPUT" should equal 1
The line 1 of contents of file "$GITHUB_OUTPUT" should equal "should-deploy=true"
End
End
Describe 'set_sonar_platform_vars() - poetry specific'
It 'handles none platform'
# Unset any existing sonar variables to test none platform behavior
unset SONAR_HOST_URL SONAR_TOKEN
When call set_sonar_platform_vars "none"
The status should be success
The line 1 should equal "Sonar analysis disabled (platform: none)"
The variable SONAR_HOST_URL should be undefined
The variable SONAR_TOKEN should be undefined
End
It 'fails with unknown platform'
When call set_sonar_platform_vars "unknown"
The status should be failure
The stderr should include "::error title=Invalid Sonar platform::Unknown sonar platform 'unknown'. Expected: next, sqc-us, sqc-eu, or none"
End
End
Describe 'set_project_version()'
It 'appends .0 given version is 1.2 and append BUILD_NUMBER'
Mock poetry
if [[ "$*" == "version -s" ]]; then
echo "1.2"
else
echo "poetry $*"
fi
End
When call set_project_version
The line 1 should equal "Replacing version 1.2 with 1.2.0.42"
The variable CURRENT_VERSION should equal "1.2"
The variable PROJECT_VERSION should equal "1.2.0.42"
End
It 'appends BUILD_NUMBER given version is 1.2.3'
Mock poetry
if [[ "$*" == "version -s" ]]; then
echo "1.2.3"
else
echo "poetry $*"
fi
End
When call set_project_version
The line 1 should equal "Replacing version 1.2.3 with 1.2.3.42"
The variable CURRENT_VERSION should equal "1.2.3"
The variable PROJECT_VERSION should equal "1.2.3.42"
End
It 'replaces dev with BUILD_NUMBER given version is 1.2.3.dev'
Mock poetry
if [[ "$*" == "version -s" ]]; then
echo "1.2.3.dev"
else
echo "poetry $*"
fi
End
When call set_project_version
The line 1 should equal "Replacing version 1.2.3.dev with 1.2.3.42"
The variable CURRENT_VERSION should equal "1.2.3.dev"
The variable PROJECT_VERSION should equal "1.2.3.42"
End
It 'replaces 41 with BUILD_NUMBER given version is 1.2.3.41'
Mock poetry
if [[ "$*" == "version -s" ]]; then
echo "1.2.3.41"
else
echo "poetry $*"
fi
End
When call set_project_version
The line 1 of error should equal "::warning title=Version truncated::Version was truncated to 1.2.3 because it had more than 3 digits"
The line 1 should equal "Replacing version 1.2.3.41 with 1.2.3.42"
The variable CURRENT_VERSION should equal "1.2.3.41"
The variable PROJECT_VERSION should equal "1.2.3.42"
End
It 'returns error message if version cannot be retrieved'
Mock poetry
if [[ "$*" == "version -s" ]]; then
echo "Failed to get version"
exit 1
else
echo "poetry $*"
fi
End
When call set_project_version
The line 1 of error should equal "::error title=Invalid project version::Could not get version from Poetry project ('poetry version -s')"
The line 2 of error should equal "Failed to get version"
The variable CURRENT_VERSION should be undefined
The variable PROJECT_VERSION should be undefined
The status should be failure
End
End
Describe 'jfrog_poetry_install()'
export PROJECT="my-repo"
It 'configures JFrog and installs with plain poetry install'
When call jfrog_poetry_install
The line 1 should include "jf config add repox"
The line 2 should include "jf config use repox"
The line 3 should include "jf poetry-config"
The line 4 should equal "poetry install"
End
End
Describe 'build_poetry()'
setup() {
# shellcheck disable=SC2317
mkdir -p dist
}
cleanup() {
# shellcheck disable=SC2317
rm -rf dist
}
Before 'setup'
After 'cleanup'
Mock check_tool
End
Mock set_build_env
End
Mock set_project_version
End
export PROJECT_VERSION="1.0.0.$BUILD_NUMBER"
export PROJECT="my-repo"
Mock jfrog_poetry_install
End
It 'builds and publishes when on the default branch (main) and not a PR'
export PULL_REQUEST=""
export GITHUB_REF_NAME="main"
When call build_poetry
The line 1 should equal '=== Poetry Build, Deploy, and Analyze ==='
The line 2 should equal 'Branch: main'
The line 3 should equal 'Pull Request: '
The line 4 should equal 'Deploy Pull Request: false'
The line 5 should equal '::group::Set project version'
The line 6 should equal '::endgroup::'
The line 7 should equal '======= Building main branch ======='
The line 8 should equal '::group::Install dependencies'
The line 9 should equal 'Installing dependencies...'
The line 10 should equal '::endgroup::'
The line 11 should equal '::group::Build project'
The line 12 should equal 'Building project...'
The line 13 should equal 'poetry build'
The line 14 should equal '::endgroup::'
The line 15 should equal 'run_sonar_analysis()'
The line 16 should equal '=== Running Sonar analysis on selected platform: next ==='
The line 17 should equal '::group::Sonar analysis on next'
The line 18 should equal 'Using Sonar platform: next (URL: https://next.sonarqube.com)'
The line 19 should equal 'poetry run pip install pysonar'
The line 21 should equal 'poetry run pysonar -Dsonar.host.url=https://next.sonarqube.com -Dsonar.token=next-token -Dsonar.analysis.buildNumber=42 -Dsonar.analysis.pipeline=dummy-run-id -Dsonar.analysis.repository=my-org/my-repo'
The line 22 should equal '::endgroup::'
The line 23 should equal '::group::Publish to Artifactory'
The line 24 should equal 'jf config add repox --url https://dummy.repox --artifactory-url https://dummy.repox --access-token <deploy token>'
The line 25 should equal 'jf config use repox'
The line 26 should include '/dist'
The line 27 should equal 'jf rt upload ./ <deploy repo>/poetry/1.0.0.42/ --module=poetry:1.0.0.42 --build-name=my-repo --build-number=42'
The line 29 should equal 'jf rt build-collect-env my-repo 42'
The line 30 should include 'jf rt build-publish my-repo 42'
The line 31 should equal '::endgroup::'
The line 32 should include '=== Build completed successfully ==='
The status should be success
End
It 'skips deploy when on a PR and DEPLOY_PULL_REQUEST is not true'
export GITHUB_EVENT_NAME="pull_request"
export PULL_REQUEST="123"
export PULL_REQUEST_SHA="dummy-sha"
export GITHUB_REF_NAME="123/merge"
When call build_poetry
The line 1 should equal '=== Poetry Build, Deploy, and Analyze ==='
The line 2 should equal 'Branch: 123/merge'
The line 3 should equal 'Pull Request: 123'
The line 4 should equal 'Deploy Pull Request: false'
The line 5 should equal '::group::Set project version'
The line 6 should equal '::endgroup::'
The line 7 should equal '======= Building pull request ======='
The line 8 should equal '======= no deploy ======='
The line 9 should equal '::group::Install dependencies'
The line 10 should equal 'Installing dependencies...'
The line 11 should equal '::endgroup::'
The line 12 should equal '::group::Build project'
The line 13 should equal 'Building project...'
The line 14 should equal 'poetry build'
The line 15 should equal '::endgroup::'
The line 16 should equal 'run_sonar_analysis()'
The line 17 should equal '=== Running Sonar analysis on selected platform: next ==='
The line 18 should equal '::group::Sonar analysis on next'
The line 19 should equal 'Using Sonar platform: next (URL: https://next.sonarqube.com)'
The line 20 should equal 'poetry run pip install pysonar'
The line 22 should equal 'poetry run pysonar -Dsonar.host.url=https://next.sonarqube.com -Dsonar.token=next-token -Dsonar.analysis.buildNumber=42 -Dsonar.analysis.pipeline=dummy-run-id -Dsonar.analysis.repository=my-org/my-repo -Dsonar.analysis.prNumber=123'
The line 23 should equal '::endgroup::'
The line 24 should equal '=== Build completed successfully ==='
The status should be success
End
It 'builds and publishes when on a PR and DEPLOY_PULL_REQUEST is true'
export GITHUB_EVENT_NAME="pull_request"
export PULL_REQUEST="123"
export PULL_REQUEST_SHA="dummy-sha"
export GITHUB_REF_NAME="123/merge"
export DEPLOY_PULL_REQUEST="true"
When call build_poetry
The line 1 should equal '=== Poetry Build, Deploy, and Analyze ==='
The line 2 should equal 'Branch: 123/merge'
The line 3 should equal 'Pull Request: 123'
The line 4 should equal 'Deploy Pull Request: true'
The line 5 should equal '::group::Set project version'
The line 6 should equal '::endgroup::'
The line 7 should equal '======= Building pull request ======='
The line 8 should equal '======= with deploy ======='
The line 9 should equal '::group::Install dependencies'
The line 10 should equal 'Installing dependencies...'
The line 11 should equal '::endgroup::'
The line 12 should equal '::group::Build project'
The line 13 should equal 'Building project...'
The line 14 should equal 'poetry build'
The line 15 should equal '::endgroup::'
The line 16 should equal 'run_sonar_analysis()'
The line 17 should equal '=== Running Sonar analysis on selected platform: next ==='
The line 18 should equal '::group::Sonar analysis on next'
The line 19 should equal 'Using Sonar platform: next (URL: https://next.sonarqube.com)'
The line 20 should equal 'poetry run pip install pysonar'
The line 22 should equal 'poetry run pysonar -Dsonar.host.url=https://next.sonarqube.com -Dsonar.token=next-token -Dsonar.analysis.buildNumber=42 -Dsonar.analysis.pipeline=dummy-run-id -Dsonar.analysis.repository=my-org/my-repo -Dsonar.analysis.prNumber=123'
The line 23 should equal '::endgroup::'
The line 24 should equal "::group::Publish to Artifactory"
The line 25 should equal "jf config add repox --url https://dummy.repox --artifactory-url https://dummy.repox --access-token <deploy token>"
The line 26 should equal "jf config use repox"
The line 27 should include "/dist"
The line 28 should equal "jf rt upload ./ <deploy repo>/poetry/1.0.0.42/ --module=poetry:1.0.0.42 --build-name=my-repo --build-number=42"
The line 30 should equal "jf rt build-collect-env my-repo 42"
The line 31 should include "jf rt build-publish my-repo 42"
The line 32 should equal "::endgroup::"
The status should be success
End
It 'disables sonarqube on dogfood branch'
export GITHUB_REF_NAME="dogfood-on-test"
When call build_poetry
The line 1 should equal '=== Poetry Build, Deploy, and Analyze ==='
The line 2 should equal 'Branch: dogfood-on-test'
The line 3 should equal 'Pull Request: '
The line 4 should equal 'Deploy Pull Request: false'
The line 5 should equal '::group::Set project version'
The line 6 should equal '::endgroup::'
The line 7 should equal '======= Build dogfood branch ======='
The status should be success
The variable BUILD_ENABLE_SONAR should equal "false"
End
It 'enables deploy on long-lived branch'
export GITHUB_REF_NAME="feature/long/test"
When call build_poetry
The line 1 should equal '=== Poetry Build, Deploy, and Analyze ==='
The line 2 should equal 'Branch: feature/long/test'
The line 3 should equal 'Pull Request: '
The line 4 should equal 'Deploy Pull Request: false'
The line 5 should equal '::group::Set project version'
The line 6 should equal '::endgroup::'
The line 7 should equal '======= Build long-lived feature branch ======='
The status should be success
The variable BUILD_ENABLE_SONAR should equal "true"
The variable BUILD_ENABLE_DEPLOY should equal "true"
The variable BUILD_SONAR_ARGS should equal "-Dsonar.branch.name=feature/long/test"
End
It 'disables deploy when DEPLOY is false'
export GITHUB_REF_NAME="main"
export DEPLOY="false"
When call build_poetry
The status should be success
The output should include "======= Building main branch ======="
The variable BUILD_ENABLE_DEPLOY should equal "false"
End
It 'enables deploy and scan on maintenance branch'
export GITHUB_REF_NAME="branch-1.2"
When call build_poetry
The line 1 should equal '=== Poetry Build, Deploy, and Analyze ==='
The line 2 should equal 'Branch: branch-1.2'
The line 3 should equal 'Pull Request: '
The line 4 should equal 'Deploy Pull Request: false'
The line 5 should equal '::group::Set project version'
The line 6 should equal '::endgroup::'
The line 7 should equal '======= Building maintenance branch ======='
The status should be success
The variable BUILD_ENABLE_SONAR should equal "true"
End
It 'disables deploy and scan on merge queue branch'
export GITHUB_REF_NAME="gh-readonly-queue/123"
When call build_poetry
The line 1 should equal '=== Poetry Build, Deploy, and Analyze ==='
The line 2 should equal 'Branch: gh-readonly-queue/123'
The line 3 should equal 'Pull Request: '
The line 4 should equal 'Deploy Pull Request: false'
The line 5 should equal '::group::Set project version'
The line 6 should equal '::endgroup::'
The line 7 should equal '======= Build other branch ======='
The status should be success
The variable BUILD_ENABLE_SONAR should equal "false"
The variable BUILD_ENABLE_DEPLOY should equal "false"
End
It 'runs shadow scans on all platforms when RUN_SHADOW_SCANS is true'
export PULL_REQUEST=""
export GITHUB_REF_NAME="main"
export RUN_SHADOW_SCANS="true"
When call build_poetry
The line 1 should equal '=== Poetry Build, Deploy, and Analyze ==='
The line 2 should equal 'Branch: main'
The line 3 should equal 'Pull Request: '
The line 4 should equal 'Deploy Pull Request: false'
The line 5 should equal '::group::Set project version'
The line 6 should equal '::endgroup::'
The line 7 should equal '======= Building main branch ======='
The line 13 should equal 'poetry build'
The line 14 should equal '::endgroup::'
The line 15 should equal 'run_sonar_analysis()'
The line 16 should equal '=== Running Sonar analysis on all platforms (shadow scan enabled) ==='
The line 17 should equal '::group::Sonar analysis on next'
The line 18 should equal '--- ORCHESTRATOR: Analyzing with platform: next ---'
The line 19 should equal 'Using Sonar platform: next (URL: https://next.sonarqube.com)'
The line 20 should equal 'poetry run pip install pysonar'
The line 22 should equal 'poetry run pysonar -Dsonar.host.url=https://next.sonarqube.com -Dsonar.token=next-token -Dsonar.analysis.buildNumber=42 -Dsonar.analysis.pipeline=dummy-run-id -Dsonar.analysis.repository=my-org/my-repo'
The line 23 should equal '::endgroup::'
The line 24 should equal '::group::Sonar analysis on sqc-us'
The line 25 should equal '--- ORCHESTRATOR: Analyzing with platform: sqc-us ---'
The line 26 should equal 'Using Sonar platform: sqc-us (URL: https://sonarqube-us.com)'
The line 27 should equal 'poetry run pip install pysonar'
The line 29 should equal 'poetry run pysonar -Dsonar.host.url=https://sonarqube-us.com -Dsonar.token=sqc-us-token -Dsonar.analysis.buildNumber=42 -Dsonar.analysis.pipeline=dummy-run-id -Dsonar.analysis.repository=my-org/my-repo'
The line 30 should equal '::endgroup::'
The line 31 should equal '::group::Sonar analysis on sqc-eu'
The line 32 should equal '--- ORCHESTRATOR: Analyzing with platform: sqc-eu ---'
The line 33 should equal 'Using Sonar platform: sqc-eu (URL: https://sonarcloud.io)'
The line 34 should equal 'poetry run pip install pysonar'
The line 36 should equal 'poetry run pysonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.token=sqc-eu-token -Dsonar.analysis.buildNumber=42 -Dsonar.analysis.pipeline=dummy-run-id -Dsonar.analysis.repository=my-org/my-repo'
The line 37 should equal '::endgroup::'
The line 38 should equal '=== Completed Sonar analysis on all platforms ==='
The stderr should include "::warning title=Deployment disabled::Shadow scans enabled - disabling deployment"
The status should be success
End
It 'skips sonar analysis when sonar-platform is none'
export PULL_REQUEST=""
export GITHUB_REF_NAME="main"
export SONAR_PLATFORM="none"
When call build_poetry
The line 1 should equal '=== Poetry Build, Deploy, and Analyze ==='
The line 2 should equal 'Branch: main'
The line 3 should equal 'Pull Request: '
The line 4 should equal 'Deploy Pull Request: false'
The line 5 should equal '::group::Set project version'
The line 6 should equal '::endgroup::'
The line 7 should equal '======= Building main branch ======='
The line 13 should equal 'poetry build'
The line 14 should equal '::endgroup::'
The line 15 should equal 'run_sonar_analysis()'
The line 16 should equal "=== Sonar platform set to 'none'. Skipping Sonar analysis."
The line 17 should equal '::group::Publish to Artifactory'
The line 18 should equal 'jf config add repox --url https://dummy.repox --artifactory-url https://dummy.repox --access-token <deploy token>'
The line 19 should equal 'jf config use repox'
The line 20 should include '/dist'
The line 21 should equal 'jf rt upload ./ <deploy repo>/poetry/1.0.0.42/ --module=poetry:1.0.0.42 --build-name=my-repo --build-number=42'
The line 23 should equal 'jf rt build-collect-env my-repo 42'
The line 24 should include 'jf rt build-publish my-repo 42'
The line 25 should equal '::endgroup::'
The line 26 should equal '=== Build completed successfully ==='
The status should be success
End
Describe 'git_fetch_unshallow()'
It 'skips git fetch when sonar platform is none'
export SONAR_PLATFORM="none"
When call git_fetch_unshallow
The status should be success
The line 1 should equal "Skipping git fetch (sonar analysis disabled)"
End
End
Describe 'main()'
It 'runs tool checks and calls build_poetry'
Mock jq
echo "$JQ_VERSION_OUTPUT"
End
Mock python
echo "Python 3.11.0"
End
Mock poetry
if [[ "$*" == "version -s" ]]; then
echo "1.8.0"
else
echo "Poetry (version 1.8.0)"
fi
End
Mock jf
echo "jf version 2.96.0"
End
Mock git
case "$*" in
"rev-parse --is-shallow-repository --quiet") return 0 ;;
*) echo "git $*" ;;
esac
End
GITHUB_OUTPUT=$(mktemp)
export GITHUB_OUTPUT
When run script build-poetry/build.sh
The status should be success
The output should include "jq-1.8.1"
The output should include "Python 3.11.0"
The output should include "Poetry (version 1.8.0)"
The output should include "jf version 2.96.0"
The output should include "=== Build completed successfully ==="
End
It 'executes main when script is run directly'
# This test ensures the conditional execution path is covered
Mock jq
echo "$JQ_VERSION_OUTPUT"
End
Mock python
echo "Python 3.11.0"
End
Mock poetry
if [[ "$*" == "version -s" ]]; then
echo "1.8.0"
else
echo "Poetry (version 1.8.0)"
fi
End
Mock jf
echo "jf version 2.96.0"
End
Mock git
case "$*" in
"rev-parse --is-shallow-repository --quiet") return 0 ;;
*) echo "git $*" ;;
esac
End
GITHUB_OUTPUT=$(mktemp)
export GITHUB_OUTPUT
When run script build-poetry/build.sh
The status should be success
The output should include "=== Poetry Build, Deploy, and Analyze ==="
End
End
End