-
Notifications
You must be signed in to change notification settings - Fork 5
/
nightly-publish-main_configure.ps1
104 lines (89 loc) · 3.08 KB
/
nightly-publish-main_configure.ps1
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
param (
[Parameter(Mandatory=$true)]
[string]$RepoName,
[Parameter(Mandatory=$true)]
[string]$OrgName,
[Parameter(Mandatory=$true)]
[string]$GitHubToken,
[string]$Branch = "",
[string]$GitHubUser = "",
[string]$GitHubEmail = "",
[Parameter(Mandatory=$true)]
[string]$GitHubOutput,
[bool]$DryRun = $False,
[string]$BuildPlatform
)
. ./constants.ps1
if ($GitHubUser -eq "") {
$GitHubUser = $DefaultGitUser
}
if ($GitHubEmail -eq "") {
$GitHubEmail = $DefaultGitEmail
}
# This token is used by the gh command.
Write-Output "Setting GITHUB_TOKEN"
$env:GITHUB_TOKEN="$GitHubToken"
Write-Output "::group::Configure Git"
./steps/configure-git.ps1 -GitHubToken $GitHubToken -GitHubUser $GitHubUser -GitHubEmail $GitHubEmail
Write-Output "::endgroup::"
Write-Output "::group::Clone $RepoName"
./steps/clone-repo.ps1 -RepoName $RepoName -OrgName $OrgName -Branch $Branch
Write-Output "::endgroup::"
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
Write-Output "::group::Get Next Package Version"
./steps/run-repo-script.ps1 -RepoName $RepoName -OrgName $OrgName -ScriptName "get-next-package-version.ps1" -Options @{VariableName = "Version"} -DryRun $DryRun
Write-Output version=$Version
$IsValid = [bool]([regex]::Match($Version, '^(\d+)\.(\d+)\.(\d+)(-SNAPSHOT)?$'))
if ($IsValid -eq $False) {
Write-Error "The package version was not valid: '$Version'"
exit 1
}
Write-Output version=$Version | Out-File -FilePath $GitHubOutput -Encoding utf8 -Append
Write-Output "::endgroup::"
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
Write-Output "::group::Package Update Required"
try {
./steps/package-update-required.ps1 -RepoName $RepoName -Version $Version
} finally {
if ($LASTEXITCODE -eq 0) {
Write-Output update_required=true | Out-File -FilePath $GitHubOutput -Encoding utf8 -Append
} else {
Write-Output update_required=false | Out-File -FilePath $GitHubOutput -Encoding utf8 -Append
# Set a zero exit code as we don't want to fail just because an update is not required.
$LASTEXITCODE = 0
}
}
Write-Output "::endgroup::"
Write-Output "::group::Get Options"
$OptionsFile = [IO.Path]::Combine($pwd, $RepoName, "ci", "options.json")
$Options = Get-Content $OptionsFile | ConvertFrom-Json
Write-Output $Options
$RequiredOptions = @()
foreach ($element in $Options)
{
if ($element.PackageRequirement) {
$element | Add-Member -Name "Version" -Value $Version -MemberType NoteProperty
$RequiredOptions += $element
}
}
if ($RequiredOptions.Count -eq 0) {
# As there are no prebuild steps, add an empty one to ensure the YAML is still valid.
$RequiredOptions += @{
"Name" = "No Prebuild"
"PackageRequirement" = $False
"Image" = $BuildPlatform
}
}
$RequiredOptions = $RequiredOptions | ConvertTo-Json -AsArray
$RequiredOptions = $RequiredOptions -replace "`r`n", "" -replace "`n", ""
Write-Host $RequiredOptions
Write-Output options=$RequiredOptions | Out-File -FilePath $GitHubOutput -Encoding utf8 -Append
Write-Output $RequiredOptions
Write-Output "::endgroup::"
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}