-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
azure-pipelines.yml
843 lines (694 loc) · 29.9 KB
/
azure-pipelines.yml
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
trigger:
branches:
include:
- pages-source
paths:
exclude:
- README.md
- LICENSE
- LICENSE-CODE
- .gitignore
- .markdownlint.json
- docfx.json
- CNAME
- toc.yml
# PR always trigger build
pr:
autoCancel: true
resources:
repositories:
- repository: templates
type: github
name: nanoframework/nf-tools
endpoint: nanoframework
pool:
vmImage: 'windows-latest'
variables:
DOTNET_NOLOGO: true
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
# need this here in order to persist GitHub credentials
- checkout: self
persistCredentials: true
fetchDepth: 1
# setup GitHub credentials and prefs
- script: |
git config --global user.email "nfbot"
git config --global user.name "[email protected]"
git config --global core.autocrlf true
displayName: Setup git identity
# get commit message
- powershell: |
#####################
# grab commit message
if($env:System_PullRequest_PullRequestId -ne $null)
{
# PR build
"Building from PR" | Write-Host
# get PR message
$prUrl = "https://api.github.com/repos/$env:Build_Repository_Name/pulls/$env:System_PullRequest_PullRequestNumber"
$commit = Invoke-RestMethod -Uri $prUrl -ContentType "application/json" -Method GET -Headers @{Authorization = "Bearer $(GitHubToken)"}
$commitMessage = $commit.body
}
else
{
# not a PR, get subject and commit message for commit
"Building from merge" | Write-Host
$commitMessage = git log --format='%B' -1
}
# need to flatten message by removing new lines
$commitMessage = $commitMessage.Replace("`r`n", " ")
"Commit message is: '$commitMessage'" | Write-Host
# set variable to forward to jobs
echo "##vso[task.setvariable variable=COMMIT_MESSAGE;isOutput=true]$commitMessage"
###########################
# get list of changed files
if($env:System_PullRequest_PullRequestId -ne $null)
{
# get files changed in PR
$commit = Invoke-RestMethod -Uri "https://api.github.com/repos/$env:Build_Repository_Name/pulls/$env:System_PullRequest_PullRequestNumber/files" -ContentType "application/json" -Method GET -Headers @{Authorization = "Bearer $(GitHubToken)"}
# filter removed files
$files = $commit.where{$_.status -ne 'removed'}
# get file names only
$files = $files | % {$_.filename}
Write-host "Files changed:"
$files | % { Write-host $_ }
Write-host ""
if(
(($files.where{$_.Contains('/')}).Count -eq 0) -Or
(($files.where{$_.StartsWith('x-cross')}).Count -gt 0)
)
{
# files at:
# - repo root
# - x-cross folder
echo "##vso[task.setvariable variable=BUILD_ALL;isOutput=true]true"
Write-host "Building ALL"
}
else
{
echo "##vso[task.setvariable variable=BUILD_ALL;isOutput=true]false"
Write-host "Only content files changed, skipping build"
}
}
else
{
# this is not a PR, need to build everything
echo "##vso[task.setvariable variable=BUILD_ALL;isOutput=true]true"
}
name: BuildOptions
displayName: Get commit details
# clone class libs repos
# fetch only the last 100 commits (if available) to be (reasonaly) sure that we have the history up to the last tag
- powershell: |
git clone https://github.com/nanoframework/CoreLibrary.git --recursive --depth 100 -b main libs/CoreLibrary
git clone https://github.com/nanoframework/nanoFramework.Device.Can.git --depth 100 -b main libs/nanoFramework.Device.Can
git clone https://github.com/nanoframework/nanoFramework.Device.OneWire.git --depth 100 -b main libs/nanoFramework.Device.OneWire
git clone https://github.com/nanoframework/nanoFramework.Networking.Thread.git --depth 100 -b main libs/nanoFramework.Networking.Thread
git clone https://github.com/nanoframework/nanoFramework.Runtime.Events.git --depth 100 -b main libs/nanoFramework.Runtime.Events
git clone https://github.com/nanoframework/nanoFramework.Runtime.Native.git --depth 100 -b main libs/nanoFramework.Runtime.Native
git clone https://github.com/nanoframework/nanoFramework.WebServer -b main libs/nanoFramework.WebServer
git clone https://github.com/nanoframework/nanoFramework.DependencyInjection -b main libs/nanoFramework.DependencyInjection
git clone https://github.com/nanoframework/nanoFramework.Hosting -b main libs/nanoFramework.Hosting
git clone https://github.com/nanoframework/System.Device.Dac.git --depth 100 -b main libs/System.Device.Dac
git clone https://github.com/nanoframework/System.Device.Gpio.git --depth 100 -b main libs/System.Device.Gpio
git clone https://github.com/nanoframework/System.Device.I2c.git --depth 100 -b main libs/System.Device.I2c
git clone https://github.com/nanoframework/System.Device.I2s.git --depth 100 -b main libs/System.Device.I2s
git clone https://github.com/nanoframework/System.IO.FileSystem.git --depth 100 -b main libs/System.IO.FileSystem
git clone https://github.com/nanoframework/System.IO.Streams.git --depth 100 -b main libs/System.IO.Streams
git clone https://github.com/nanoframework/System.Runtime.Serialization.git --depth 100 -b main libs/System.Runtime.Serialization
git clone https://github.com/nanoframework/System.Device.Pwm.git --depth 100 -b main libs/System.Device.Pwm
git clone https://github.com/nanoframework/System.Device.Spi.git --depth 100 -b main libs/System.Device.Spi
git clone https://github.com/nanoframework/Windows.Storage.git --depth 100 -b main libs/Windows.Storage
git clone https://github.com/nanoframework/Windows.Storage.Streams.git --depth 100 -b main libs/Windows.Storage.Streams
git clone https://github.com/nanoframework/System.Device.Adc.git --depth 100 -b main libs/System.Device.Adc
git clone https://github.com/nanoframework/System.Device.WiFi.git --depth 100 -b main libs/System.Device.WiFi
git clone https://github.com/nanoframework/System.Device.UsbClient.git -b main System.Device.UsbClient
git clone https://github.com/nanoframework/nanoFramework.Benchmark -b main libs/nanoFramework.Benchmark
git clone https://github.com/nanoframework/nanoFramework.Graphics -b main libs/nanoFramework.Graphics
git clone https://github.com/nanoframework/nanoFramework.GiantGecko.Adc -b main nanoFramework.GiantGecko.Adc
git clone https://github.com/nanoframework/nanoFramework.Hardware.Esp32 -b main libs/nanoFramework.Hardware.Esp32
git clone https://github.com/nanoframework/nanoFramework.Hardware.Esp32.Rmt -b main libs/nanoFramework.Hardware.Esp32.Rmt
git clone https://github.com/nanoframework/nanoFramework.Hardware.GiantGecko -b main nanoFramework.Hardware.GiantGecko
git clone https://github.com/nanoframework/nanoFramework.Json -b main libs/nanoFramework.Json
git clone https://github.com/nanoframework/nanoFramework.Hardware.Stm32 -b main libs/nanoFramework.Hardware.Stm32
git clone https://github.com/nanoframework/nanoFramework.ResourceManager -b main libs/nanoFramework.ResourceManager
git clone https://github.com/nanoframework/nanoFramework.Networking.Sntp -b main libs/nanoFramework.Networking.Sntp
git clone https://github.com/nanoframework/System.Collections -b main libs/System.Collections
git clone https://github.com/nanoframework/System.Text -b main libs/System.Text
git clone https://github.com/nanoframework/System.Net -b main libs/System.Net
git clone https://github.com/nanoframework/System.Net.Http -b main libs/System.Net.Http
git clone https://github.com/nanoframework/System.Net.WebSockets -b main libs/System.Net.WebSockets
git clone https://github.com/nanoframework/nanoFramework.TI.EasyLink -b main libs/nanoFramework.TI.EasyLink
git clone https://github.com/nanoframework/nanoFramework.Hardware.TI -b main libs/nanoFramework.Hardware.TI
git clone https://github.com/nanoframework/System.Math -b main libs/System.Math
git clone https://github.com/nanoframework/nanoFramework.Logging -b main libs/nanoFramework.Logging
git clone https://github.com/nanoframework/System.IO.Ports.git --depth 100 -b main libs/System.IO.Ports
git clone https://github.com/nanoframework/nanoFramework.m2mqtt.git -b main libs/nanoFramework.M2Mqtt
git clone https://github.com/nanoframework/System.Text.RegularExpressions.git --depth 100 -b main libs/System.Text.RegularExpressions
git clone https://github.com/nanoframework/nanoFramework.Azure.Devices.git -b main libs/nanoFramework.Azure.Devices
git clone https://github.com/nanoframework/nanoFramework.Aws.IoTCore.Devices.git -b main libs/nanoFramework.Aws.IoTCore.Devices
git clone https://github.com/nanoframework/nanoFramework.SignalR.Client.git -b main libs/nanoFramework.SignalR.Client
git clone https://github.com/nanoframework/System.Net.Sockets.TcpClient.git -b main libs/System.Net.Sockets.TcpClient
git clone https://github.com/nanoframework/System.Net.Sockets.UdpClient.git -b main libs/System.Net.Sockets.UdpClient
git clone https://github.com/nanoframework/System.Device.UsbClient.git -b main libs/System.Device.UsbClient
git clone https://github.com/nanoframework/nanoFramework.GiantGecko.Adc.git -b main libs/nanoFramework.GiantGecko.Adc
git clone https://github.com/nanoframework/nanoFramework.Hardware.GiantGecko.git -b main libs/nanoFramework.Hardware.GiantGecko
git clone https://github.com/nanoframework/System.IO.Hashing.git -b main libs/System.IO.Hashing
git clone https://github.com/nanoframework/System.Security.Cryptography.git -b main libs/System.Security.Cryptography
git clone https://github.com/nanoframework/System.Device.I2c.Slave.git -b main libs/System.Device.I2c.Slave
git clone https://github.com/nanoframework/nanoFramework.System.Runtime.git -b main libs/nanoFramework.System.Runtime
displayName: Clone repos of class libs
condition: >-
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
# clone IoT bindings repo and Samples
- powershell: |
git clone https://github.com/nanoframework/nanoFramework.IoT.Device.git -b develop nanoFramework.IoT.Device
git clone https://github.com/nanoframework/Samples.git -b main Samples
displayName: Clone IoT binding repo and Samples
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
# Clean all solutions that are not needed to build nor generate documentation
- task: PowerShell@2
displayName: Delete unnecessary solutions
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
inputs:
targetType: 'inline'
script: |
Remove-Item -Force libs\CoreLibrary\nanoFramework.TestFramework\nanoFramework.TestAdapter.sln
Remove-Item -Force libs\nanoFramework.M2Mqtt\nanoFramework.Mqtt.TestApps.sln
- powershell: choco install docfx-companion-tools -y
displayName: Install the docfx helpers
condition: succeeded()
# install docfx
- task: DotNetCoreCLI@2
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
displayName: Install docfx
inputs:
command: custom
custom: tool
arguments: install -g docfx
# Create the README in /devices folder with all IoT.Device bindings
# Run the Generator to physically move the files first
- task: DotNetCoreCLI@2
displayName: 'Generate all the devices README files'
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
inputs:
command: 'run'
projects: 'nanoFramework.IoT.Device\src\GenerateDocFxStructure'
arguments: '-- -d $(System.DefaultWorkingDirectory)\devicesdetails -m $(System.DefaultWorkingDirectory)\devicesimages -s nanoFramework.IoT.Device/devices -v -r https://github.com/nanoFramework/nanoFramework.IoT.Device/tree/develop/devices -i packages,tests,bin,obj'
# build the TOC and adjust the README.md
- powershell: |
&DocFxTocGenerator -d $(System.DefaultWorkingDirectory)\devicesdetails -si
# Define the file path
$filePath = "$(System.DefaultWorkingDirectory)\devicesdetails\README.md"
# Read the content of the file
$content = Get-Content -Path $filePath -Raw
# Perform the replacement using regex to add /README.md to all the device links
$newContent = $content -replace '\(([a-zA-Z\d\.]+)\)', '($1/README.md)'
# Write the updated content back to the file
Set-Content -Path $filePath -Value $newContent
displayName: 'Building automatically toc.yml for devices'
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
# Create the README index
# 1. adjust the settings
- powershell: |
# Define the path to the Configuration.json file
$jsonFilePath = "$(System.DefaultWorkingDirectory)/Samples/device-listing/Configuration.json"
# Read the content of the JSON file
$jsonContent = Get-Content -Path $jsonFilePath | ConvertFrom-Json
# Update the values
$jsonContent.AddReadme = $true
# Convert the updated object back to JSON
$jsonContent | ConvertTo-Json | Set-Content -Path $jsonFilePath
displayName: Adjust configuration to build README
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
# 2. copy the README to the Sampes/samples folder
- powershell: |
Copy-Item -Path $(System.DefaultWorkingDirectory)\samplesdetails\README.md -Destination $(System.DefaultWorkingDirectory)\Samples\README.md
Remove-Item -Force $(System.DefaultWorkingDirectory)\samplesdetails\README.md
displayName: Copy samples README to samples folder
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
# 3. generate dynamically the list
- task: DotNetCoreCLI@2
displayName: Generate samples README
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
inputs:
command: custom
custom: run
projects: '$(System.DefaultWorkingDirectory)/Samples/device-listing/device-listing.csproj'
workingDirectory: '$(System.DefaultWorkingDirectory)\Samples\samples'
# 4. copy the README to the Sampes/samples folder
- powershell: |
Copy-Item -Path $(System.DefaultWorkingDirectory)\Samples\README.md -Destination $(System.DefaultWorkingDirectory)\Samples\samples\README.md
# adjust all the links to point to the right place so removing /samples/ from the links
$filePath = "$(System.DefaultWorkingDirectory)\Samples\samples\README.md"
# Get the original encoding of the file
$sr = New-Object System.IO.StreamReader($filePath, $true)
[char[]] $buffer = new-object char[] 3
$sr.Read($buffer, 0, 3)
$originalEncoding = $sr.CurrentEncoding
$sr.Close()
# Making it simple as we only want to preserve UTF8 encoding
if ( $originalEncoding.BodyName -eq "utf-8" ) {
$fileEncoding = "UTF8"
}
else {
$fileEncoding = "ASCII"
}
# Read the content of the file using the original encoding
$content = Get-Content -Path $filePath -Raw -Encoding $fileEncoding
# Perform the replacement using regex to add /README.md to all the device links
$newContent = $content -replace '\(samples/', '\('
# Write the updated content back to the file
Set-Content -Path $filePath -Value $newContent -Encoding $fileEncoding
displayName: Copy samples README to samples folder
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
# Create the README in /samples folder with all Samples readme
# Run the Generator to physically move the files first
- task: DotNetCoreCLI@2
displayName: 'Generate all the samples README files'
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
inputs:
command: 'run'
projects: 'nanoFramework.IoT.Device\src\GenerateDocFxStructure'
arguments: '-- -d $(System.DefaultWorkingDirectory)\samplesdetails -m $(System.DefaultWorkingDirectory)\samplesimages -s Samples/samples -v -r https://github.com/nanoframework/Samples/tree/main/samples -i packages,tests,bin,obj'
# 5. Build the TOC
- powershell: |
&DocFxTocGenerator -d $(System.DefaultWorkingDirectory)\samplesdetails -si
displayName: 'Building automatically toc.yml for samples'
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
# Build the TOC for all the content folder
- powershell: |
&DocFxTocGenerator -d $(System.DefaultWorkingDirectory)\content -s -r -g
displayName: 'Building automatically toc.yml for main content'
condition: succeeded()
# Check the links
- powershell: |
&DocLinkChecker -d $(System.DefaultWorkingDirectory)\content -t
displayName: 'Check internal links in the core repo'
condition: succeeded()
# Scan markdown files on style consistency
- powershell: |
npm install -g markdownlint-cli
markdownlint -c $(System.DefaultWorkingDirectory)/.markdownlint.json $(System.DefaultWorkingDirectory)/content
displayName: 'Execute Markdownlint'
condition: succeeded()
# we then need to add the root index page to the toc
- powershell: |
# read all lines into `$fileContents`
$filePath = "$(System.DefaultWorkingDirectory)\content\toc.yml"
$fileContents = Get-Content $filePath
# append text to desired line
$textToAdd = "items:
- name: Home
href: ../index.md"
$fileContents[1] = $fileContents[1].Replace("items:", $textToAdd)
# write all lines back to file
$fileContents | Set-Content $filePath
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
displayName: Adjust TOC to add main index
# install specific version of nuget CLI
- template: azure-pipelines-templates/install-nuget.yml@templates
- task: Cache@2
displayName: Cache NuGet packages
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
continueOnError: true
inputs:
key: 'nuget | **/packages.lock.json'
path: $(UserProfile)/.nuget/packages
# restore all solutions
- task: NuGetCommand@2
displayName: NuGet restore all class libs
retryCountOnTaskFailure: 3
inputs:
restoreSolution: 'libs/**/*.sln'
feedsToUse: 'select'
# Build part
- task: InstallNanoMSBuildComponents@1
displayName: Install nanoFramework MSBuild components
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
inputs:
GitHubToken: $(GitHubToken)
# this is required for IoT bindings build
- task: DotNetCoreCLI@2
displayName: Install nanovc tool
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
inputs:
command: custom
custom: tool
arguments: install -g nanovc --add-source https://pkgs.dev.azure.com/nanoframework/feed/_packaging/sandbox/nuget/v3/index.json
# This will build all class libraries in the libs folder
- task: VSBuild@1
displayName: Build all class libs
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
retryCountOnTaskFailure: 3
inputs:
solution: 'libs/**/*.sln'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
msbuildArchitecture: 'x64'
maximumCpuCount: true
# This should build all the bindings in nanoFramework.IoT.Device in the devices directory
- task: PowerShell@2
displayName: Build all from nanoFramework.IoT.Device
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
inputs:
workingDirectory: 'nanoFramework.IoT.Device\devices'
targetType: 'filePath'
filePath: 'nanoFramework.IoT.Device\.pipeline-assets\pipeline-build-solutions.PS1'
env:
MY_GITHUBTOKEN: $(GitHubToken)
DEVICE_TO_BUILD: 'ALL'
# Clean what's not needed from IoT.Device and adjust the nugets to remove nerdbank to help build
- task: PowerShell@2
displayName: Delete generated device folder from IoT.Device and clean references
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
inputs:
targetType: 'inline'
script: |
Remove-Item -Recurse -Force nanoFramework.IoT.Device\src\devices_generated
Remove-Item -Recurse -Force nanoFramework.IoT.Device\src\nanoFramework.IoT.Device.CodeConverter
Remove-Item -Recurse -Force nanoFramework.IoT.Device\src\GenerateDocFxStructure
cd nanoFramework.IoT.Device\devices
$Nerdbank = '<package id="Nerdbank.GitVersioning"'
$Files = Get-ChildItem -Filter "packages.config" -Recurse
foreach ($File in $Files) {
$FullPath = $File | % { $_.FullName }
$ToReplace = Get-Content $FullPath
$Replaced = $ToReplace `
| Where-Object { $_ -notmatch $Nerdbank }
Set-Content -path $FullPath -Value $Replaced
}
# Replace the intrument key
- powershell: |
. ./common.ps1
$fileToReplace = "$(System.DefaultWorkingDirectory)/templates/material/public/main.js"
$sourceString = "INTRUMENT_KEY"
$instrumentKey = "$(InstrumentKey)"
Find-ReplaceInFile -filePath $fileToReplace -sourceString $sourceString -targetString $instrumentKey
displayName: Replace intrument key
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
# run docfx
- powershell: |
&docfx metadata docfx.json
if ($lastexitcode -ne 0)
{
throw [System.Exception] "docfx build failed with exit code $lastexitcode."
}
&docfx build docfx.json
if ($lastexitcode -ne 0)
{
throw [System.Exception] "docfx build failed with exit code $lastexitcode."
}
displayName: Run docfx
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
# Replace the links to improve doc for dynamic content in devicedetails
- powershell: |
. ./common.ps1
# Set the source and target strings
$sourceString = "https://github.com/nanoframework/nanoframework.github.io/blob/pages-source/devicesdetails"
$targetString = "https://github.com/nanoframework/nanoframework.IoT.Device/blob/develop/devices"
# Set the root directory where you want to perform the search and replace
$rootDirectory = "_site/devicesdetails"
if (Check-DirectoryExists -rootDirectory $rootDirectory) {
Find-ReplaceInFiles -rootDirectory $rootDirectory -sourceString $sourceString -targetString $targetString
} else {
Write-HostMessage -message "Directory $rootDirectory does not exist."
}
displayName: Replace dynamically links in devicesdetails
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
# Replace the links to improve doc for dynamic content in samples
- powershell: |
. ./common.ps1
# Set the source and target strings
$sourceString = "https://github.com/nanoframework/nanoframework.github.io/blob/pages-source/samplesdetails"
$targetString = "https://github.com/nanoframework/Samples/blob/main/samples"
# Set the root directory where you want to perform the search and replace
$rootDirectory = "_site/samplesdetails"
if (Check-DirectoryExists -rootDirectory $rootDirectory) {
Find-ReplaceInFiles -rootDirectory $rootDirectory -sourceString $sourceString -targetString $targetString
} else {
Write-HostMessage -message "Directory $rootDirectory does not exist."
}
displayName: Replace dynamically links in samplesdetails
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
# Patch the transformed samplesdetails/README.html as margdig used by DocFX do not transform the links properly
- powershell: |
# Definte the file path to adjust
$filePath = "$(System.DefaultWorkingDirectory)/_site/samplesdetails/README.html"
# Making it simple as we only want to preserve UTF8 encoding
$fileEncoding = "UTF8"
# Read the content of the file using the original encoding
$content = Get-Content -Path $filePath -Raw -Encoding $fileEncoding
# Perform the replacement using regex to replace the MArkdown links by HTML links
$newContent = $content -replace '\[(.*)\]\((.*)\.md\)', '<a href="$2.html">$1</a>'
# Write the updated content back to the file
Set-Content -Path $filePath -Value $newContent -Encoding $fileEncoding
displayName: Fixing the samplesdetails/README.html links
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
# Make an artifact for debug purpose
- task: ArchiveFiles@2
displayName: Zipping _site directory
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
inputs:
rootFolderOrFile: '$(Build.SourcesDirectory)\_site'
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/site.zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts@1
displayName: Publish deployable artifacts
condition: >-
and(
succeeded(),
or(
eq(variables['BUILD_ALL'], 'true'),
contains(variables['BuildOptions.COMMIT_MESSAGE'], '***BUILD_ALL***'),
eq(variables['BuildOptions.BUILD_ALL'], 'true')
)
)
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: site
ArtifactType: Container
# commit changes (only if this is NOT a PR build)
- powershell: |
git clone https://github.com/nanoframework/nanoframework.github.io.git -b master origin_site -q
Copy-Item _site/* origin_site -recurse -Force
cd origin_site > $null
$auth = "basic $([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("nfbot:$(GitHubToken)")))"
git add . -A > $null
git commit -m "Update documentation from PR" -q > $null
git -c http.extraheader="AUTHORIZATION: $auth" push origin master -q > $null
failOnStderr: false
ignoreLASTEXITCODE: true
condition: >-
and(
succeeded(),
eq(variables['System.PullRequest.PullRequestId'], '')
)
displayName: Commit changes in website
# step from template @ nf-tools repo
# report error
- template: azure-pipelines-templates/discord-webhook-task.yml@templates
parameters:
status: 'failure'
webhookUrl: '$(DiscordWebhook)'
message: ''