-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathCalculateArtifactNames.ps1
56 lines (48 loc) · 1.94 KB
/
CalculateArtifactNames.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
Param(
[Parameter(HelpMessage = "Name of the built project", Mandatory = $true)]
[string] $project,
[Parameter(HelpMessage = "Build mode used when building the artifacts", Mandatory = $true)]
[string] $buildMode,
[Parameter(HelpMessage = "Suffix to add to the artifacts names", Mandatory = $false)]
[string] $suffix
)
function Set-OutputVariable([string] $name, [string] $value) {
Write-Host "Assigning $value to $name"
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "$name=$value"
}
$settings = $env:Settings | ConvertFrom-Json
if ($project -eq ".") {
$project = $settings.repoName
}
$branchName = $ENV:GITHUB_HEAD_REF
# $ENV:GITHUB_HEAD_REF is specified only for pull requests, so if it is not specified, use GITHUB_REF_NAME
if (!$branchName) {
$branchName = $ENV:GITHUB_REF_NAME
}
$branchName = $branchName.Replace('\', '_').Replace('/', '_')
$projectName = $project.Replace('\', '_').Replace('/', '_')
# If the buildmode is default, then we don't want to add it to the artifact name
if ($buildMode -eq 'Default') {
$buildMode = ''
}
Set-OutputVariable -name "BuildMode" -value $buildMode
if ($suffix) {
# Add the date to the suffix
$suffix = "$suffix-$([DateTime]::UtcNow.ToString('yyyyMMdd'))"
}
else {
$repoVersion = [System.Version]$settings.repoVersion
$appBuild = $settings.appBuild
if ($appBuild -eq -1) {
$appBuild = $repoVersion.Build
if ($repoVersion.Build -eq -1) {
$appBuild = 0
}
}
$suffix = "$($repoVersion.Major).$($repoVersion.Minor).$($appBuild).$($settings.appRevision)"
}
'Apps', 'Dependencies', 'TestApps', 'TestResults', 'BcptTestResults', 'PageScriptingTestResults', 'PageScriptingTestResultDetails', 'BuildOutput', 'ContainerEventLog', 'PowerPlatformSolution' | ForEach-Object {
$name = "$($_)ArtifactsName"
$value = "$($projectName)-$($branchName)-$buildMode$_-$suffix"
Set-OutputVariable -name $name -value $value
}