-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.build.ps1
More file actions
122 lines (94 loc) · 3.55 KB
/
Copy path.build.ps1
File metadata and controls
122 lines (94 loc) · 3.55 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
<#
.Synopsis
Build script invoked by Invoke-Build.
.Description
#>
param(
[Parameter(Mandatory = $false)]
[string]$Version,
[Parameter(Mandatory = $false)]
[string]$Instance,
[Parameter(Mandatory = $false)]
[switch]$Check
)
function Resolve-RepositoryPath {
param(
[Parameter(Mandatory = $true)]
[string]$Path
)
$resolvedPath = Resolve-Path $Path
return $resolvedPath.Path
}
function Get-NuGetApiKey {
if (-not [string]::IsNullOrWhiteSpace($env:NUGET_API_KEY)) {
return $env:NUGET_API_KEY
}
if (Get-Module -Name Microsoft.PowerShell.SecretManagement -ListAvailable) {
Import-Module -Name Microsoft.PowerShell.SecretManagement
$apiKey = Get-Secret -Name 'TIKSN-ROFSDB-NuGet-ApiKey' -AsPlainText -ErrorAction SilentlyContinue
if (-not [string]::IsNullOrWhiteSpace($apiKey)) {
return $apiKey
}
}
return $null
}
task Init {
$script:solution = Resolve-RepositoryPath './src/ROFSDB.slnx'
$script:NextVersion = $null
$script:trashFolder = Join-Path -Path . -ChildPath '.trash'
if ([string]::IsNullOrWhiteSpace($Instance)) {
$Instance = Get-Date -Format 'yyyyMMddHHmmss'
}
$script:trashFolder = Join-Path -Path $script:trashFolder -ChildPath $Instance
New-Item -Path $script:trashFolder -ItemType Directory -Force | Out-Null
$script:trashFolder = Resolve-RepositoryPath $script:trashFolder
}
task Clean Init, {
Exec { dotnet clean $script:solution }
}
task Restore Clean, {
Exec { dotnet restore $script:solution }
}
task Format Restore, {
if ($Check -or $env:CI) {
Exec { dotnet format whitespace $script:solution --verify-no-changes }
Exec { dotnet format style $script:solution --severity info --verify-no-changes }
Exec { dotnet format analyzers $script:solution --severity info --verify-no-changes }
}
else {
Exec { dotnet format whitespace $script:solution }
Exec { dotnet format style $script:solution --severity info }
Exec { dotnet format analyzers $script:solution --severity info }
}
}
task Version Init, {
if ([string]::IsNullOrWhiteSpace($Version)) {
return
}
$script:NextVersion = $Version
Write-Build Green "Package version: $script:NextVersion"
}
task Build Format, Version, {
if ([string]::IsNullOrWhiteSpace($script:NextVersion)) {
Exec { dotnet build $script:solution --configuration Release --no-restore }
}
else {
Exec { dotnet build $script:solution --configuration Release --no-restore -p:Version=$script:NextVersion }
}
}
task Test Build, {
$project = Resolve-RepositoryPath './src/ROFSDB.Tests/ROFSDB.Tests.csproj'
Exec { dotnet test $project --configuration Release --no-build }
}
task Pack Test, Version, {
Assert (-not [string]::IsNullOrWhiteSpace($script:NextVersion)) 'Version is required for package creation.'
$project = Resolve-RepositoryPath './src/ROFSDB/ROFSDB.csproj'
Exec { dotnet pack $project --configuration Release --no-build --output $script:trashFolder -p:Version=$script:NextVersion }
}
task Publish Pack, {
$apiKey = Get-NuGetApiKey
Assert (-not [string]::IsNullOrWhiteSpace($apiKey)) 'NUGET_API_KEY environment variable or TIKSN-ROFSDB-NuGet-ApiKey SecretManagement secret is required to publish.'
$nupkg = Join-Path -Path $script:trashFolder -ChildPath "ROFSDB.$script:NextVersion.nupkg"
$nupkg = Resolve-RepositoryPath $nupkg
Exec { dotnet nuget push $nupkg --api-key $apiKey --source https://api.nuget.org/v3/index.json }
}