-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathazure-pipelines.yml
More file actions
969 lines (876 loc) · 42.9 KB
/
azure-pipelines.yml
File metadata and controls
969 lines (876 loc) · 42.9 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
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
# Azure DevOps CI Pipeline for Umbraco.AI
# Converted from GitHub Actions (.github/workflows/ci.yml)
# ============================================================
# Product Definitions - UPDATE HERE WHEN ADDING NEW PACKAGES
# ============================================================
# Level 0: Core package (no internal dependencies)
# Level 1: All packages that depend on Core
# Level 2: All packages that depend on Level 1 packages
parameters:
- name: level1Products
type: object
default:
# Providers (no frontend)
- name: Umbraco.AI.OpenAI
changeVar: OpenaiChanged
hasNpm: false
- name: Umbraco.AI.Anthropic
changeVar: AnthropicChanged
hasNpm: false
- name: Umbraco.AI.Amazon
changeVar: AmazonChanged
hasNpm: false
- name: Umbraco.AI.Google
changeVar: GoogleChanged
hasNpm: false
- name: Umbraco.AI.MicrosoftFoundry
changeVar: MicrosoftfoundryChanged
hasNpm: false
# Add-ons (have frontend but don't export types)
- name: Umbraco.AI.Search
changeVar: SearchChanged
hasNpm: false
- name: Umbraco.AI.Prompt
changeVar: PromptChanged
hasNpm: false
- name: Umbraco.AI.Agent
changeVar: AgentChanged
hasNpm: true
# Deploy support (no frontend)
- name: Umbraco.AI.Deploy
changeVar: DeployChanged
hasNpm: false
- name: level2Products
type: object
default:
# Agent UI (depends on Agent - exports npm types)
- name: Umbraco.AI.Agent.UI
changeVar: AgentUiChanged
hasNpm: true
# Deploy extensions (depend on Deploy + their respective add-ons)
- name: Umbraco.AI.Prompt.Deploy
changeVar: PromptDeployChanged
hasNpm: false
- name: Umbraco.AI.Agent.Deploy
changeVar: AgentDeployChanged
hasNpm: false
# Automate (depends on Agent)
- name: Umbraco.AI.Automate
changeVar: AutomateChanged
hasNpm: false
- name: level3Products
type: object
default:
# Copilot (depends on Agent UI - exports npm types)
- name: Umbraco.AI.Agent.Copilot
changeVar: AgentCopilotChanged
hasNpm: true
trigger:
branches:
include:
- main
- dev
- release/*
- hotfix/*
- feature/*
pr:
branches:
include:
- main
- dev
variables:
- group: dependency-track
- name: NODE_VERSION
value: "22.x"
- name: DOTNET_NOLOGO
value: "true"
- name: DOTNET_CLI_TELEMETRY_OPTOUT
value: "true"
stages:
# ============================================================
# Build & Test everything
# ============================================================
- stage: Build
displayName: Build & Test
jobs:
- job: BuildAndTest
displayName: Build & Test
pool:
vmImage: "ubuntu-latest"
steps:
- checkout: self
fetchDepth: 0
- task: UseDotNet@2
displayName: Setup .NET
inputs:
useGlobalJson: true
- task: NodeTool@0
displayName: Setup Node.js
inputs:
versionSpec: $(NODE_VERSION)
- script: |
npm ci --include=optional
npm run build
displayName: Build frontend
- script: dotnet restore Umbraco.AI.slnx
displayName: Restore
- script: dotnet build Umbraco.AI.slnx --configuration Release --no-restore -p:DisableCloudBuildNumber=true
displayName: Build
- script: dotnet test Umbraco.AI.slnx --configuration Release --no-build --verbosity normal --logger trx --results-directory $(Agent.TempDirectory)/TestResults
displayName: Test
- task: PublishTestResults@2
displayName: Publish test results
condition: always()
inputs:
testResultsFormat: VSTest
testResultsFiles: "$(Agent.TempDirectory)/TestResults/**/*.trx"
mergeTestResults: true
- task: PublishPipelineArtifact@1
displayName: Upload build outputs
inputs:
targetPath: $(Build.SourcesDirectory)
artifact: build-outputs
publishLocation: pipeline
# ============================================================
# Generate & Upload SBOMs - Only runs on push to main/dev/hotfix/release
# Generates per-product SBOMs and uploads to Dependency-Track
# ============================================================
- stage: GenerateSBOM
displayName: Generate & Upload SBOMs
dependsOn: Build
condition: |
and(
succeeded(),
ne(variables['Build.Reason'], 'PullRequest')
)
jobs:
# Core product
- job: GenerateSBOM_Core
displayName: Generate SBOM - Umbraco.AI
pool:
vmImage: "ubuntu-latest"
steps:
- checkout: self
fetchDepth: 1
- task: NodeTool@0
displayName: Setup Node.js
inputs:
versionSpec: $(NODE_VERSION)
- template: .azure-pipelines/templates/generate-sbom.yml
parameters:
product: Umbraco.AI
# Level 1 products (matrix)
- job: GenerateSBOM_Level1
displayName: Generate SBOM - Level 1
pool:
vmImage: "ubuntu-latest"
strategy:
matrix:
${{ each product in parameters.level1Products }}:
${{ replace(replace(product.name, 'Umbraco.AI.', ''), '.', '_') }}:
product: ${{ product.name }}
maxParallel: 10
steps:
- checkout: self
fetchDepth: 1
- task: NodeTool@0
displayName: Setup Node.js
inputs:
versionSpec: $(NODE_VERSION)
- template: .azure-pipelines/templates/generate-sbom.yml
parameters:
product: $(product)
# Level 2 products (matrix)
- job: GenerateSBOM_Level2
displayName: Generate SBOM - Level 2
pool:
vmImage: "ubuntu-latest"
strategy:
matrix:
${{ each product in parameters.level2Products }}:
${{ replace(replace(product.name, 'Umbraco.AI.', ''), '.', '_') }}:
product: ${{ product.name }}
maxParallel: 10
steps:
- checkout: self
fetchDepth: 1
- task: NodeTool@0
displayName: Setup Node.js
inputs:
versionSpec: $(NODE_VERSION)
- template: .azure-pipelines/templates/generate-sbom.yml
parameters:
product: $(product)
# Level 3 products (matrix)
- job: GenerateSBOM_Level3
displayName: Generate SBOM - Level 3
pool:
vmImage: "ubuntu-latest"
strategy:
matrix:
${{ each product in parameters.level3Products }}:
${{ replace(replace(product.name, 'Umbraco.AI.', ''), '.', '_') }}:
product: ${{ product.name }}
maxParallel: 10
steps:
- checkout: self
fetchDepth: 1
- task: NodeTool@0
displayName: Setup Node.js
inputs:
versionSpec: $(NODE_VERSION)
- template: .azure-pipelines/templates/generate-sbom.yml
parameters:
product: $(product)
# ============================================================
# Collect all SBOMs into single artifact
# Downloads artifacts from all SBOM jobs and combines them
# ============================================================
- job: CollectSBOMs
displayName: Collect All SBOMs
dependsOn:
- GenerateSBOM_Core
- GenerateSBOM_Level1
- GenerateSBOM_Level2
- GenerateSBOM_Level3
condition: |
and(
not(failed()),
not(canceled())
)
pool:
vmImage: "ubuntu-latest"
steps:
- checkout: none
# Download Core SBOM
- task: DownloadPipelineArtifact@2
displayName: Download Umbraco.AI SBOM
inputs:
artifact: "Umbraco.AI-sbom"
targetPath: "$(Pipeline.Workspace)/sboms"
# Download Level 1 SBOMs
- ${{ each product in parameters.level1Products }}:
- task: DownloadPipelineArtifact@2
displayName: Download ${{ product.name }} SBOM
inputs:
artifact: "${{ product.name }}-sbom"
targetPath: "$(Pipeline.Workspace)/sboms"
# Download Level 2 SBOMs
- ${{ each product in parameters.level2Products }}:
- task: DownloadPipelineArtifact@2
displayName: Download ${{ product.name }} SBOM
inputs:
artifact: "${{ product.name }}-sbom"
targetPath: "$(Pipeline.Workspace)/sboms"
# Download Level 3 SBOMs
- ${{ each product in parameters.level3Products }}:
- task: DownloadPipelineArtifact@2
displayName: Download ${{ product.name }} SBOM
inputs:
artifact: "${{ product.name }}-sbom"
targetPath: "$(Pipeline.Workspace)/sboms"
# Flatten SBOM files into single directory
- task: Bash@3
displayName: Collect SBOM files
inputs:
targetType: inline
script: |
mkdir -p all-sboms
# Find all SBOM JSON files and move to single directory
if [ -d "$(Pipeline.Workspace)/sboms" ]; then
find "$(Pipeline.Workspace)/sboms" -name "*-bom.json" -exec mv {} all-sboms/ \;
fi
# List collected SBOMs
if [ -d "all-sboms" ] && [ "$(ls -A all-sboms 2>/dev/null)" ]; then
echo "Collected SBOMs:"
ls -la all-sboms/
else
echo "No SBOMs collected"
fi
- task: PublishPipelineArtifact@1
displayName: Upload combined SBOM artifact
inputs:
targetPath: $(Build.SourcesDirectory)/all-sboms
artifact: all-sboms
publishLocation: pipeline
# ============================================================
# Validate Changelogs - Only runs on release and hotfix branches
# Ensures CHANGELOGs are present and match version.json
# Runs in parallel with GenerateSBOM after Build
# ============================================================
- stage: ValidateChangelogs
displayName: Validate Changelogs
dependsOn: Build
# Only validate on release and hotfix branches (not main or dev)
condition: |
and(
succeeded(),
ne(variables['Build.Reason'], 'PullRequest'),
or(
startsWith(variables['Build.SourceBranch'], 'refs/heads/release/'),
startsWith(variables['Build.SourceBranch'], 'refs/heads/hotfix/')
)
)
jobs:
- job: ValidateChangelogFiles
displayName: Validate CHANGELOG.md Files
pool:
vmImage: "ubuntu-latest"
steps:
- checkout: self
fetchDepth: 0
- task: PowerShell@2
displayName: Validate changelogs
inputs:
filePath: .azure-pipelines/scripts/validate-changelogs.ps1
pwsh: true
failOnStderr: false
# ============================================================
# Pack Stage - Only runs on push to main/dev/hotfix/release branches
# Uses dynamic change detection to only pack products that changed
# Runs in parallel with GenerateSBOM after Build (through ValidateChangelogs dependency)
# ============================================================
- stage: Pack
displayName: Pack NuGet & NPM Packages
dependsOn:
- Build
- ValidateChangelogs
# Only pack on push (not PR) to main/dev/hotfix/release branches
# ValidateChangelogs may be skipped (on main/dev branches), which is OK
condition: |
and(
in(dependencies.Build.result, 'Succeeded'),
in(dependencies.ValidateChangelogs.result, 'Succeeded', 'Skipped'),
ne(variables['Build.Reason'], 'PullRequest'),
or(
startsWith(variables['Build.SourceBranch'], 'refs/heads/hotfix/'),
startsWith(variables['Build.SourceBranch'], 'refs/heads/release/'),
eq(variables['Build.SourceBranch'], 'refs/heads/main'),
eq(variables['Build.SourceBranch'], 'refs/heads/dev')
)
)
jobs:
# ============================================================
# Detect which products changed
# ============================================================
- job: DetectChanges
displayName: Detect Changed Products
pool:
vmImage: "ubuntu-latest"
steps:
- checkout: self
fetchDepth: 0
- task: PowerShell@2
displayName: Run change detection
name: detect
inputs:
filePath: .azure-pipelines/scripts/detect-changes.ps1
pwsh: true
- task: Bash@3
displayName: Summarize packed products + tag build
inputs:
targetType: inline
script: |
PRODUCTS="$(detect.AllChangedProducts)"
ANY="$(detect.AnyChanged)"
MAX_LEVEL="$(detect.MaxLevel)"
if [ -z "$PRODUCTS" ]; then
PRODUCTS="(none)"
fi
SUMMARY_FILE="$(Build.ArtifactStagingDirectory)/pack-summary.md"
{
echo "## Pack Summary"
echo ""
echo "- AnyChanged: ${ANY:-false}"
echo "- MaxLevel: ${MAX_LEVEL:-0}"
echo "- CoreChanged: $(detect.CoreChanged)"
echo "- Products: ${PRODUCTS}"
echo ""
echo "Artifacts (if produced):"
echo "- all-nuget-packages"
echo "- all-npm-packages"
} > "$SUMMARY_FILE"
echo "##vso[task.uploadsummary]$SUMMARY_FILE"
if [ "$PRODUCTS" = "(none)" ]; then
echo "##vso[build.addbuildtag]pack-none"
exit 0
fi
if [ "$(detect.CoreChanged)" = "true" ]; then
echo "##vso[build.addbuildtag]pack-core"
fi
IFS=',' read -ra ITEMS <<< "$PRODUCTS"
for item in "${ITEMS[@]}"; do
trimmed="$(echo "$item" | xargs)"
if [ -n "$trimmed" ]; then
name="$trimmed"
if [[ "$name" == Umbraco.AI.* ]]; then
name="${name#Umbraco.AI.}"
elif [[ "$name" == Umbraco.AI ]]; then
name="core"
fi
safe="$(echo "$name" | tr '[:upper:]' '[:lower:]' | tr '.' '-' | tr -cd 'a-z0-9-')"
echo "##vso[build.addbuildtag]pack-$safe"
fi
done
# ============================================================
# Pack Core (Level 0 - no internal dependencies)
# Conditional based on change detection
# ============================================================
- job: PackCore
displayName: Pack Umbraco.AI
dependsOn: DetectChanges
condition: eq(dependencies.DetectChanges.outputs['detect.CoreChanged'], 'true')
pool:
vmImage: "ubuntu-latest"
steps:
- checkout: self
fetchDepth: 0
- task: UseDotNet@2
displayName: Setup .NET
inputs:
useGlobalJson: true
- task: DownloadPipelineArtifact@2
displayName: Download build outputs
inputs:
artifact: build-outputs
path: $(Build.SourcesDirectory)
- template: .azure-pipelines/templates/pack-product.yml
parameters:
product: Umbraco.AI
# Use project references on dev (preview releases), NuGet packages on release/hotfix/main (validate ranges)
useProjectReferences: ${{ eq(variables['Build.SourceBranchName'], 'dev') }}
- template: .azure-pipelines/templates/upload-packages.yml
parameters:
product: Umbraco.AI
# ============================================================
# Pack Level 1 (Providers + Add-ons - depend on Core)
# Matrix generated from parameters.level1Products
# ============================================================
- job: PackLevel1
displayName: Pack Level 1
dependsOn:
- DetectChanges
- PackCore
condition: |
and(
not(failed()),
not(canceled()),
eq(dependencies.DetectChanges.outputs['detect.Level1Changed'], 'true')
)
pool:
vmImage: "ubuntu-latest"
strategy:
matrix:
# Generated from parameters.level1Products
${{ each product in parameters.level1Products }}:
${{ replace(replace(product.name, 'Umbraco.AI.', ''), '.', '_') }}:
product: ${{ product.name }}
changeVar: ${{ product.changeVar }}
maxParallel: 10
variables:
# Pass all per-product change flags as job variables
CoreChanged: $[ dependencies.DetectChanges.outputs['detect.CoreChanged'] ]
${{ each product in parameters.level1Products }}:
${{ product.changeVar }}: $[ dependencies.DetectChanges.outputs['detect.${{ product.changeVar }}'] ]
steps:
- checkout: self
fetchDepth: 0
- template: .azure-pipelines/templates/check-should-pack.yml
- template: .azure-pipelines/templates/setup-pack-job.yml
parameters:
downloadCore: true
downloadLevel1: false
- template: .azure-pipelines/templates/pack-product.yml
parameters:
product: $(product)
# Use project references on dev (preview releases), NuGet packages on release/hotfix/main (validate ranges)
useProjectReferences: ${{ eq(variables['Build.SourceBranchName'], 'dev') }}
condition: eq(variables['check.shouldPack'], 'true')
- template: .azure-pipelines/templates/upload-packages.yml
parameters:
product: $(product)
condition: eq(variables['check.shouldPack'], 'true')
# ============================================================
# Pack Level 2 (Agent UI - depends on Agent)
# Matrix generated from parameters.level2Products
# ============================================================
- job: PackLevel2
displayName: Pack Level 2
dependsOn:
- DetectChanges
- PackCore
- PackLevel1
condition: |
and(
not(failed()),
not(canceled()),
eq(dependencies.DetectChanges.outputs['detect.Level2Changed'], 'true')
)
pool:
vmImage: "ubuntu-latest"
strategy:
matrix:
# Generated from parameters.level2Products
${{ each product in parameters.level2Products }}:
${{ replace(replace(product.name, 'Umbraco.AI.', ''), '.', '_') }}:
product: ${{ product.name }}
changeVar: ${{ product.changeVar }}
maxParallel: 10
variables:
# Pass all per-product change flags as job variables
CoreChanged: $[ dependencies.DetectChanges.outputs['detect.CoreChanged'] ]
${{ each product in parameters.level1Products }}:
${{ product.changeVar }}: $[ dependencies.DetectChanges.outputs['detect.${{ product.changeVar }}'] ]
${{ each product in parameters.level2Products }}:
${{ product.changeVar }}: $[ dependencies.DetectChanges.outputs['detect.${{ product.changeVar }}'] ]
steps:
- checkout: self
fetchDepth: 0
- template: .azure-pipelines/templates/check-should-pack.yml
- template: .azure-pipelines/templates/setup-pack-job.yml
parameters:
downloadCore: true
downloadLevel1: true
level1Products: ${{ parameters.level1Products }}
- template: .azure-pipelines/templates/pack-product.yml
parameters:
product: $(product)
# Use project references on dev (preview releases), NuGet packages on release/hotfix/main (validate ranges)
useProjectReferences: ${{ eq(variables['Build.SourceBranchName'], 'dev') }}
condition: eq(variables['check.shouldPack'], 'true')
- template: .azure-pipelines/templates/upload-packages.yml
parameters:
product: $(product)
condition: eq(variables['check.shouldPack'], 'true')
# ============================================================
# Pack Level 3 (Copilot - depends on Agent UI)
# Matrix generated from parameters.level3Products
# ============================================================
- job: PackLevel3
displayName: Pack Level 3
dependsOn:
- DetectChanges
- PackCore
- PackLevel1
- PackLevel2
condition: |
and(
not(failed()),
not(canceled()),
eq(dependencies.DetectChanges.outputs['detect.Level3Changed'], 'true')
)
pool:
vmImage: "ubuntu-latest"
strategy:
matrix:
# Generated from parameters.level3Products
${{ each product in parameters.level3Products }}:
${{ replace(replace(product.name, 'Umbraco.AI.', ''), '.', '_') }}:
product: ${{ product.name }}
changeVar: ${{ product.changeVar }}
maxParallel: 10
variables:
# Pass all per-product change flags as job variables
CoreChanged: $[ dependencies.DetectChanges.outputs['detect.CoreChanged'] ]
${{ each product in parameters.level1Products }}:
${{ product.changeVar }}: $[ dependencies.DetectChanges.outputs['detect.${{ product.changeVar }}'] ]
${{ each product in parameters.level2Products }}:
${{ product.changeVar }}: $[ dependencies.DetectChanges.outputs['detect.${{ product.changeVar }}'] ]
${{ each product in parameters.level3Products }}:
${{ product.changeVar }}: $[ dependencies.DetectChanges.outputs['detect.${{ product.changeVar }}'] ]
steps:
- checkout: self
fetchDepth: 0
- template: .azure-pipelines/templates/check-should-pack.yml
- template: .azure-pipelines/templates/setup-pack-job.yml
parameters:
downloadCore: true
downloadLevel1: true
downloadLevel2: true
level1Products: ${{ parameters.level1Products }}
level2Products: ${{ parameters.level2Products }}
- template: .azure-pipelines/templates/pack-product.yml
parameters:
product: $(product)
# Use project references on dev (preview releases), NuGet packages on release/hotfix/main (validate ranges)
useProjectReferences: ${{ eq(variables['Build.SourceBranchName'], 'dev') }}
condition: eq(variables['check.shouldPack'], 'true')
- template: .azure-pipelines/templates/upload-packages.yml
parameters:
product: $(product)
condition: eq(variables['check.shouldPack'], 'true')
# ============================================================
# Collect all packages into single artifact
# Downloads artifacts from all pack jobs using ${{ each }}
# ============================================================
- job: CollectPackages
displayName: Collect All Packages
dependsOn:
- DetectChanges
- PackCore
- PackLevel1
- PackLevel2
- PackLevel3
condition: |
and(
not(failed()),
not(canceled()),
eq(dependencies.DetectChanges.outputs['detect.AnyChanged'], 'true')
)
pool:
vmImage: "ubuntu-latest"
variables:
# Map dependency outputs to job variables (dependencies context only works at job level)
CoreChanged: $[ dependencies.DetectChanges.outputs['detect.CoreChanged'] ]
${{ each product in parameters.level1Products }}:
${{ product.changeVar }}: $[ dependencies.DetectChanges.outputs['detect.${{ product.changeVar }}'] ]
${{ each product in parameters.level2Products }}:
${{ product.changeVar }}: $[ dependencies.DetectChanges.outputs['detect.${{ product.changeVar }}'] ]
${{ each product in parameters.level3Products }}:
${{ product.changeVar }}: $[ dependencies.DetectChanges.outputs['detect.${{ product.changeVar }}'] ]
steps:
- checkout: self
fetchDepth: 0
# Download Core NuGet packages (only if Core changed)
- task: DownloadPipelineArtifact@2
displayName: Download Umbraco.AI NuGet packages
condition: eq(variables.CoreChanged, 'true')
inputs:
artifact: "Umbraco.AI-packages"
targetPath: "$(Pipeline.Workspace)/nuget"
# Download Core npm packages (only if Core changed - Core always has npm packages)
- task: DownloadPipelineArtifact@2
displayName: Download Umbraco.AI npm packages
condition: eq(variables.CoreChanged, 'true')
inputs:
artifact: "Umbraco.AI-npm-packages"
targetPath: "$(Pipeline.Workspace)/npm"
# Download Level 1 NuGet packages (only if product changed)
- ${{ each product in parameters.level1Products }}:
- task: DownloadPipelineArtifact@2
displayName: Download ${{ product.name }} NuGet packages
condition: eq(variables.${{ product.changeVar }}, 'true')
inputs:
artifact: "${{ product.name }}-packages"
targetPath: "$(Pipeline.Workspace)/nuget"
# Download Level 1 npm packages (only for products that have npm packages)
- ${{ each product in parameters.level1Products }}:
- ${{ if eq(product.hasNpm, true) }}:
- task: DownloadPipelineArtifact@2
displayName: Download ${{ product.name }} npm packages
condition: eq(variables.${{ product.changeVar }}, 'true')
inputs:
artifact: "${{ product.name }}-npm-packages"
targetPath: "$(Pipeline.Workspace)/npm"
# Download Level 2 NuGet packages (only if product changed)
- ${{ each product in parameters.level2Products }}:
- task: DownloadPipelineArtifact@2
displayName: Download ${{ product.name }} NuGet packages
condition: eq(variables.${{ product.changeVar }}, 'true')
inputs:
artifact: "${{ product.name }}-packages"
targetPath: "$(Pipeline.Workspace)/nuget"
# Download Level 2 npm packages (only for products that have npm packages)
- ${{ each product in parameters.level2Products }}:
- ${{ if eq(product.hasNpm, true) }}:
- task: DownloadPipelineArtifact@2
displayName: Download ${{ product.name }} npm packages
condition: eq(variables.${{ product.changeVar }}, 'true')
inputs:
artifact: "${{ product.name }}-npm-packages"
targetPath: "$(Pipeline.Workspace)/npm"
# Download Level 3 NuGet packages (only if product changed)
- ${{ each product in parameters.level3Products }}:
- task: DownloadPipelineArtifact@2
displayName: Download ${{ product.name }} NuGet packages
condition: eq(variables.${{ product.changeVar }}, 'true')
inputs:
artifact: "${{ product.name }}-packages"
targetPath: "$(Pipeline.Workspace)/nuget"
# Download Level 3 npm packages (only for products that have npm packages)
- ${{ each product in parameters.level3Products }}:
- ${{ if eq(product.hasNpm, true) }}:
- task: DownloadPipelineArtifact@2
displayName: Download ${{ product.name }} npm packages
condition: eq(variables.${{ product.changeVar }}, 'true')
inputs:
artifact: "${{ product.name }}-npm-packages"
targetPath: "$(Pipeline.Workspace)/npm"
- task: PowerShell@2
displayName: Build pack manifest (projects -> version)
name: buildManifest
inputs:
targetType: inline
pwsh: true
script: |
$manifestDir = Join-Path $env:BUILD_SOURCESDIRECTORY "artifacts"
$manifestFile = Join-Path $manifestDir "pack-manifest.json"
New-Item -ItemType Directory -Force -Path $manifestDir | Out-Null
$entries = New-Object System.Collections.Generic.List[object]
$packages = @()
$nugetRoot = Join-Path $env:PIPELINE_WORKSPACE "nuget"
if (Test-Path $nugetRoot) {
Add-Type -AssemblyName System.IO.Compression.FileSystem
$files = Get-ChildItem -Path $nugetRoot -Recurse -Filter "*.nupkg" -File
foreach ($f in $files) {
$zip = [System.IO.Compression.ZipFile]::OpenRead($f.FullName)
try {
$nuspecEntry = $zip.Entries | Where-Object { $_.FullName -like "*.nuspec" } | Select-Object -First 1
if ($null -ne $nuspecEntry) {
$reader = New-Object System.IO.StreamReader($nuspecEntry.Open())
try {
$xml = [xml]$reader.ReadToEnd()
} finally {
$reader.Close()
}
$id = $xml.package.metadata.id
$version = $xml.package.metadata.version
if ($id -and $version) {
$packages += [pscustomobject]@{ id = $id; version = $version }
}
}
} finally {
$zip.Dispose()
}
}
}
function Add-VersionByProduct {
param([string]$Product)
$match = $packages | Where-Object { $_.id -eq $Product } | Select-Object -First 1
if (-not $match) {
$match = $packages | Where-Object { $_.id -like "$Product.*" } | Select-Object -First 1
}
if ($match) {
$entries.Add([pscustomobject]@{ name = $Product; version = $match.version })
}
}
if ("$(CoreChanged)" -eq "true") {
Add-VersionByProduct "Umbraco.AI"
}
$level1 = $env:LEVEL1_JSON | ConvertFrom-Json
foreach ($p in $level1) {
$changeVar = [string]$p.changeVar
$changed = [Environment]::GetEnvironmentVariable($changeVar)
if (-not $changed) {
$changed = [Environment]::GetEnvironmentVariable($changeVar.ToUpper())
}
if ($changed -eq "true") {
Add-VersionByProduct $p.name
}
}
$level2 = $env:LEVEL2_JSON | ConvertFrom-Json
foreach ($p in $level2) {
$changeVar = [string]$p.changeVar
$changed = [Environment]::GetEnvironmentVariable($changeVar)
if (-not $changed) {
$changed = [Environment]::GetEnvironmentVariable($changeVar.ToUpper())
}
if ($changed -eq "true") {
Add-VersionByProduct $p.name
}
}
$level3 = $env:LEVEL3_JSON | ConvertFrom-Json
foreach ($p in $level3) {
$changeVar = [string]$p.changeVar
$changed = [Environment]::GetEnvironmentVariable($changeVar)
if (-not $changed) {
$changed = [Environment]::GetEnvironmentVariable($changeVar.ToUpper())
}
if ($changed -eq "true") {
Add-VersionByProduct $p.name
}
}
$json = $entries | ConvertTo-Json -Depth 3
$json | Out-File -FilePath $manifestFile -Encoding utf8
Write-Host "Pack manifest written to $manifestFile"
Write-Host $json
env:
LEVEL1_JSON: ${{ convertToJson(parameters.level1Products) }}
LEVEL2_JSON: ${{ convertToJson(parameters.level2Products) }}
LEVEL3_JSON: ${{ convertToJson(parameters.level3Products) }}
- task: PublishPipelineArtifact@1
displayName: Upload pack manifest
inputs:
targetPath: $(Build.SourcesDirectory)/artifacts/pack-manifest.json
artifact: pack-manifest
publishLocation: pipeline
# Flatten and collect NuGet packages
- task: Bash@3
displayName: Collect NuGet packages
name: collectNuget
inputs:
targetType: inline
script: |
mkdir -p all-nuget-packages
# Find all .nupkg and .snupkg files and move to single directory (only if source dir exists)
if [ -d "$(Pipeline.Workspace)/nuget" ]; then
find "$(Pipeline.Workspace)/nuget" -name "*.nupkg" -exec mv {} all-nuget-packages/ \; 2>/dev/null || true
find "$(Pipeline.Workspace)/nuget" -name "*.snupkg" -exec mv {} all-nuget-packages/ \; 2>/dev/null || true
fi
# Check if any packages were collected
if [ -d "all-nuget-packages" ] && [ "$(ls -A all-nuget-packages 2>/dev/null)" ]; then
echo "##vso[task.setvariable variable=hasNugetPackages;isOutput=true]true"
echo "Collected NuGet packages:"
ls -la all-nuget-packages/
else
echo "##vso[task.setvariable variable=hasNugetPackages;isOutput=true]false"
echo "No NuGet packages collected"
fi
# Flatten and collect npm packages
- task: Bash@3
displayName: Collect npm packages
name: collectNpm
inputs:
targetType: inline
script: |
mkdir -p all-npm-packages
# Find all .tgz files and move to single directory (only if source dir exists)
if [ -d "$(Pipeline.Workspace)/npm" ]; then
find "$(Pipeline.Workspace)/npm" -name "*.tgz" -exec mv {} all-npm-packages/ \; 2>/dev/null || true
fi
# Check if any packages were collected
if [ -d "all-npm-packages" ] && [ "$(ls -A all-npm-packages 2>/dev/null)" ]; then
echo "##vso[task.setvariable variable=hasNpmPackages;isOutput=true]true"
echo "Collected npm packages:"
ls -la all-npm-packages/
else
echo "##vso[task.setvariable variable=hasNpmPackages;isOutput=true]false"
echo "No npm packages collected"
fi
- task: PublishPipelineArtifact@1
displayName: Upload combined NuGet artifact
condition: eq(variables['collectNuget.hasNugetPackages'], 'true')
inputs:
targetPath: $(Build.SourcesDirectory)/all-nuget-packages
artifact: all-nuget-packages
publishLocation: pipeline
- task: PublishPipelineArtifact@1
displayName: Upload combined npm artifact
condition: eq(variables['collectNpm.hasNpmPackages'], 'true')
inputs:
targetPath: $(Build.SourcesDirectory)/all-npm-packages
artifact: all-npm-packages
publishLocation: pipeline
# ============================================================
# Finalize - set build number after both parallel paths complete
# Waits for both GenerateSBOM and Pack stages
# ============================================================
- stage: Finalize
displayName: Finalize Build
dependsOn:
- GenerateSBOM
- Pack
condition: not(canceled())
jobs:
- job: SetBuildNumber
displayName: Set build number
pool:
vmImage: "ubuntu-latest"
steps:
- task: Bash@3
displayName: Set build number (branch + date)
inputs:
targetType: inline
script: |
BUILD_DATE=$(date -u +%Y%m%d)
echo "##vso[build.updatebuildnumber]$(Build.SourceBranchName)-${BUILD_DATE}-$(Build.BuildID)"