-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
release-GlobalToolTest.yml
129 lines (100 loc) · 4.38 KB
/
release-GlobalToolTest.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
parameters:
jobName: ""
displayName: ""
imageName: ""
globalToolExeName: 'pwsh.exe'
globalToolPackageName: 'PowerShell.Windows.x64'
jobs:
- job: ${{ parameters.jobName }}
displayName: ${{ parameters.displayName }}
pool:
# test
vmImage: ${{ parameters.imageName }}
steps:
- checkout: self
clean: true
- task: DownloadPipelineArtifact@2
inputs:
source: specific
project: PowerShellCore
pipeline: '696'
preferTriggeringPipeline: true
runVersion: latestFromBranch
runBranch: '$(Build.SourceBranch)'
artifact: finalResults
patterns: '**/*.nupkg'
path: '$(Pipeline.Workspace)/releasePipeline/finalResults'
- pwsh: |
$dotnetMetadataPath = "$(Build.SourcesDirectory)/DotnetRuntimeMetadata.json"
$dotnetMetadataJson = Get-Content $dotnetMetadataPath -Raw | ConvertFrom-Json
# Channel is like: $Channel = "5.0.1xx-preview2"
$Channel = $dotnetMetadataJson.sdk.channel
$sdkVersion = (Get-Content "$(Build.SourcesDirectory)/global.json" -Raw | ConvertFrom-Json).sdk.version
Import-Module "$(Build.SourcesDirectory)/build.psm1" -Force
Find-Dotnet
if(-not (Get-PackageSource -Name 'dotnet' -ErrorAction SilentlyContinue))
{
$nugetFeed = ([xml](Get-Content $(Build.SourcesDirectory)/nuget.config -Raw)).Configuration.packagesources.add | Where-Object { $_.Key -eq 'dotnet' } | Select-Object -ExpandProperty Value
if ($nugetFeed) {
Register-PackageSource -Name 'dotnet' -Location $nugetFeed -ProviderName NuGet
Write-Verbose -Message "Register new package source 'dotnet'" -verbose
}
}
## Install latest version from the channel
#Install-Dotnet -Channel "$Channel" -Version $sdkVersion
Start-PSBootstrap
Write-Verbose -Message "Installing .NET SDK completed." -Verbose
displayName: Install .NET
- pwsh: |
$branch = $ENV:BUILD_SOURCEBRANCH
$version = $branch -replace '^.*(release[-/])v'
$vstsCommandString = "vso[task.setvariable variable=PowerShellVersion]$version"
Write-Verbose -Message "Version is $version" -Verbose
Write-Host -Object "##$vstsCommandString"
displayName: Set PowerShell Version
- pwsh: |
$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
Import-Module "$(Build.SourcesDirectory)/build.psm1" -Force
Start-PSBootstrap -Force
$toolPath = New-Item -ItemType Directory "$(System.DefaultWorkingDirectory)/toolPath" | Select-Object -ExpandProperty FullName
dotnet tool install --add-source "$ENV:PIPELINE_WORKSPACE/releasePipeline/finalResults" --tool-path $toolPath --version '$(PowerShellVersion)' '${{ parameters.globalToolPackageName }}'
Get-ChildItem -Path $toolPath
displayName: Install global tool
- pwsh: |
$toolPath = "$(System.DefaultWorkingDirectory)/toolPath/${{ parameters.globalToolExeName }}"
if (-not (Test-Path $toolPath))
{
throw "Tool is not installed at $toolPath"
}
else
{
Write-Verbose -Verbose "Tool found at: $toolPath"
}
displayName: Validate tool is installed
- pwsh: |
Import-Module "$(Build.SourcesDirectory)/build.psm1" -Force
Start-PSBootstrap -Force
$exeName = if ($IsWindows) { "pwsh.exe" } else { "pwsh" }
$toolPath = "$(System.DefaultWorkingDirectory)/toolPath/${{ parameters.globalToolExeName }}"
$env:DOTNET_ROOT = if ($IsWindows) { "$env:LOCALAPPDATA\Microsoft\dotnet" } else { "$env:HOME/.dotnet" }
Write-Verbose -Verbose "DOTNET_ROOT: $env:DOTNET_ROOT"
Get-ChildItem $env:DOTNET_ROOT
$versionFound = & $toolPath -c '$PSVersionTable.PSVersion.ToString()'
if ( '$(PowerShellVersion)' -ne $versionFound)
{
throw "Expected version of global tool not found. Installed version is $versionFound"
}
else
{
write-verbose -verbose "Found expected version: $versionFound"
}
$dateYear = & $toolPath -c '(Get-Date).Year'
if ( $dateYear -ne [DateTime]::Now.Year)
{
throw "Get-Date returned incorrect year: $dateYear"
}
else
{
write-verbose -verbose "Got expected year: $dateYear"
}
displayName: Basic validation