-
Notifications
You must be signed in to change notification settings - Fork 28
/
DownloadProjectDependencies.Action.ps1
142 lines (116 loc) · 5.88 KB
/
DownloadProjectDependencies.Action.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
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
Param(
[Parameter(HelpMessage = "The project for which to download dependencies", Mandatory = $true)]
[string] $project,
[string] $baseFolder,
[string] $buildMode = 'Default',
[string] $projectsDependenciesJson,
[string] $baselineWorkflowRunID = '0',
[string] $destinationPath,
[string] $token
)
function DownloadDependenciesFromProbingPaths {
param(
$baseFolder,
$project,
$destinationPath,
$token
)
$settings = $env:Settings | ConvertFrom-Json | ConvertTo-HashTable -recurse
$settings = AnalyzeRepo -settings $settings -baseFolder $baseFolder -project $project -doNotCheckArtifactSetting -doNotIssueWarnings
$settings = CheckAppDependencyProbingPaths -settings $settings -token $token -baseFolder $baseFolder -project $project
if ($settings.ContainsKey('appDependencyProbingPaths') -and $settings.appDependencyProbingPaths) {
return GetDependencies -probingPathsJson $settings.appDependencyProbingPaths -saveToPath $destinationPath | Where-Object { $_ }
}
}
function DownloadDependenciesFromCurrentBuild {
param(
$baseFolder,
$project,
$projectsDependencies,
$buildMode,
$baselineWorkflowRunID,
$destinationPath,
$token
)
Write-Host "Downloading dependencies for project '$project'"
$dependencyProjects = @()
if ($projectsDependencies.Keys -contains $project) {
$dependencyProjects = @($projectsDependencies."$project")
}
Write-Host "Dependency projects: $($dependencyProjects -join ', ')"
# For each dependency project, calculate the corresponding probing path
$dependeciesProbingPaths = @()
foreach($dependencyProject in $dependencyProjects) {
Write-Host "Reading settings for project '$dependencyProject'"
$dependencyProjectSettings = ReadSettings -baseFolder $baseFolder -project $dependencyProject
$dependencyBuildMode = $buildMode
if (!($dependencyProjectSettings.buildModes -contains $dependencyBuildMode)) {
# Download the default build mode if the specified build mode is not supported for the dependency project
Write-Host "Build mode '$dependencyBuildMode' is not supported for project '$dependencyProject'. Using the default build mode."
$dependencyBuildMode = 'Default';
}
$headBranch = $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 (!$headBranch) {
$headBranch = $ENV:GITHUB_REF_NAME
}
$baseBranch = $ENV:GITHUB_BASE_REF
# $ENV:GITHUB_BASE_REF is specified only for pull requests, so if it is not specified, use GITHUB_REF_NAME
if (!$baseBranch) {
$baseBranch = $ENV:GITHUB_REF_NAME
}
$dependeciesProbingPaths += @(@{
"release_status" = "thisBuild"
"version" = "latest"
"buildMode" = $dependencyBuildMode
"projects" = $dependencyProject
"repo" = "$ENV:GITHUB_SERVER_URL/$ENV:GITHUB_REPOSITORY"
"branch" = $headBranch
"baseBranch" = $baseBranch
"baselineWorkflowID" = $baselineWorkflowRunID
"authTokenSecret" = $token
})
}
# For each probing path, download the dependencies
$downloadedDependencies = @()
foreach($probingPath in $dependeciesProbingPaths) {
$buildMode = $probingPath.buildMode
$project = $probingPath.projects
$branch = $probingPath.branch
$baseBranch = $probingPath.baseBranch
$baselineWorkflowRunID = $probingPath.baselineWorkflowID
Write-Host "Downloading dependencies for project '$project'. BuildMode: $buildMode, Branch: $branch, Base Branch: $baseBranch, Baseline Workflow ID: $baselineWorkflowRunID"
$dependency = GetDependencies -probingPathsJson $probingPath -saveToPath $destinationPath | Where-Object { $_ }
$downloadedDependencies += $dependency
}
return $downloadedDependencies
}
. (Join-Path -Path $PSScriptRoot -ChildPath "..\AL-Go-Helper.ps1" -Resolve)
Write-Host "Downloading dependencies for project '$project'. BuildMode: $buildMode, Base Folder: $baseFolder, Destination Path: $destinationPath"
$downloadedDependencies = @()
Write-Host "::group::Downloading project dependencies from current build"
$projectsDependencies = $projectsDependenciesJson | ConvertFrom-Json | ConvertTo-HashTable
$downloadedDependencies += DownloadDependenciesFromCurrentBuild -baseFolder $baseFolder -project $project -projectsDependencies $projectsDependencies -buildMode $buildMode -baselineWorkflowRunID $baselineWorkflowRunID -destinationPath $destinationPath -token $token
Write-Host "::endgroup::"
Write-Host "::group::Downloading project dependencies from probing paths"
$downloadedDependencies += DownloadDependenciesFromProbingPaths -baseFolder $baseFolder -project $project -destinationPath $destinationPath -token $token
Write-Host "::endgroup::"
Write-Host "Downloaded dependencies: $($downloadedDependencies -join ', ')"
$downloadedApps = @()
$downloadedTestApps = @()
# Split the downloaded dependencies into apps and test apps
$downloadedDependencies | ForEach-Object {
# naming convention: app, (testapp)
if ($_.startswith('(')) {
$DownloadedTestApps += $_
}
else {
$DownloadedApps += $_
}
}
Write-Host "Downloaded dependencies apps: $($DownloadedApps -join ', ')"
Write-Host "Downloaded dependencies test apps: $($DownloadedTestApps -join ', ')"
$DownloadedAppsJson = ConvertTo-Json $DownloadedApps -Depth 99 -Compress
$DownloadedTestAppsJson = ConvertTo-Json $DownloadedTestApps -Depth 99 -Compress
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "DownloadedApps=$DownloadedAppsJson"
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "DownloadedTestApps=$DownloadedTestAppsJson"