forked from microsoft/AL-Go
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Action for downloading project dependencies (microsoft#578)
Fixes microsoft#450 - Define a separate action for fetching project dependencies (`DownloadProjectDependencies`). - `RunPipeline` only installs the apps that are output from `DownloadProjectDependencies`. - `Get-Dependencies` works with the provided build mode. - [x] Documentation - [x] Release notes - [x] Propagate changes to workflows
- Loading branch information
Showing
10 changed files
with
261 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
Actions/DownloadProjectDependencies/DownloadProjectDependencies.Action.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
Param( | ||
[Parameter(HelpMessage = "The project for which to download dependencies", Mandatory = $true)] | ||
[string] $project, | ||
[string] $baseFolder, | ||
[string] $buildMode = 'Default', | ||
[string] $projectsDependenciesJson, | ||
[string] $destinationPath, | ||
[string] $token | ||
) | ||
|
||
function DownloadDependenciesFromProbingPaths($baseFolder, $project, $destinationPath) { | ||
$projectSettings = ReadSettings -baseFolder $baseFolder -project $project | ||
|
||
$probingPaths = $projectSettings.appDependencyProbingPaths | ConvertFrom-Json | ||
|
||
$downloadedDependencies = @() | ||
if ($probingPaths) { | ||
$downloadedDependencies += Get-Dependencies -probingPathsJson $repo.appDependencyProbingPaths -saveToPath $destinationPath | Where-Object { $_ } | ||
} | ||
|
||
return $downloadedDependencies | ||
} | ||
|
||
function DownloadDependenciesFromCurrentBuild($baseFolder, $project, $projectsDependencies, $buildMode, $destinationPath) { | ||
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 = @($dependencyProjects | ForEach-Object { | ||
$dependencyProject = $_ | ||
|
||
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'; | ||
} | ||
|
||
$currentBranch = $ENV:GITHUB_REF_NAME | ||
|
||
$baseBranch = $ENV:GITHUB_BASE_REF_NAME | ||
# $ENV:GITHUB_BASE_REF_NAME is specified only for pull requests, so if it is not specified, use the current branch | ||
if(!$baseBranch) { | ||
$baseBranch = $currentBranch | ||
} | ||
|
||
return @{ | ||
"release_status" = "thisBuild" | ||
"version" = "latest" | ||
"buildMode" = $dependencyBuildMode | ||
"projects" = $dependencyProject | ||
"repo" = "$ENV:GITHUB_SERVER_URL/$ENV:GITHUB_REPOSITORY" | ||
"branch" = $currentBranch | ||
"baseBranch" = $baseBranch | ||
"authTokenSecret" = $token | ||
} | ||
}) | ||
|
||
# For each probing path, download the dependencies | ||
$downloadedDependencies = @() | ||
$dependeciesProbingPaths | ForEach-Object { | ||
$probingPath = $_ | ||
|
||
$buildMode = $probingPath.buildMode | ||
$project = $probingPath.projects | ||
$branch = $probingPath.branch | ||
$baseBranch = $probingPath.baseBranch | ||
|
||
Write-Host "Downloading dependencies for project '$project'. BuildMode: $buildMode, Branch: $branch, Base Branch: $baseBranch" | ||
|
||
$dependency = Get-Dependencies -probingPathsJson $probingPath -saveToPath $destinationPath | Where-Object { $_ } | ||
$downloadedDependencies += $dependency | ||
} | ||
|
||
return $downloadedDependencies | ||
} | ||
|
||
$ErrorActionPreference = "Stop" | ||
Set-StrictMode -Version 2.0 | ||
|
||
. (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 -destinationPath $destinationPath | ||
Write-Host "::endgroup::" | ||
|
||
Write-Host "::group::Downloading project dependencies from probing paths" | ||
$downloadedDependencies += DownloadDependenciesFromProbingPaths -baseFolder $baseFolder -project $project -destinationPath $destinationPath | ||
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 -Path $env:GITHUB_OUTPUT -Value "DownloadedApps=$DownloadedAppsJson" | ||
Add-Content -Path $env:GITHUB_OUTPUT -Value "DownloadedTestApps=$DownloadedTestAppsJson" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Download project dependencies | ||
Downloads artifacts from AL-Go projects, that are dependencies of a given AL-Go project. | ||
|
||
The action constructs arrays of paths to .app files, that are dependencies of the apps in an AL-Go project. | ||
|
||
## Parameters | ||
### project | ||
The AL-Go project for which to download dependencies | ||
|
||
### buildMode | ||
The build mode to use to downloaded to most appropriate dependencies. | ||
If a dependency project isn't built in the provided build mode, then the artifacts from the default mode will be used. | ||
|
||
### projectsDependenciesJson | ||
A JSON-formatted object that maps a project to an array of its dependencies. | ||
|
||
## Outputs | ||
### DownloadedApps: | ||
A JSON-formatted list of paths to .app files, that dependencies of the apps. | ||
|
||
### DownloadedTestApps: | ||
A JSON-formatted list of paths to .app files, that dependencies of the test apps. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Download Project Dependencies | ||
author: Microsoft Corporation | ||
description: Downloads the dependencies of an AL-Go project | ||
inputs: | ||
shell: | ||
description: Shell in which you want to run the action (powershell or pwsh) | ||
required: false | ||
default: powershell | ||
project: | ||
description: Project for which to download dependencies | ||
required: true | ||
buildMode: | ||
description: Build mode used when building the artifacts | ||
required: true | ||
projectsDependenciesJson: | ||
description: A JSON object that matches eash project with its dependency projects | ||
required: true | ||
outputs: | ||
DownloadedApps: | ||
description: A JSON-formatted array of paths to .app files of the apps that were downloaded | ||
value: ${{ steps.DownloadDependencies.outputs.DownloadedApps }} | ||
DownloadedTestApps: | ||
description: A JSON-formatted array of paths to .app files of the test apps that were downloaded | ||
value: ${{ steps.DownloadDependencies.outputs.DownloadedTestApps }} | ||
runs: | ||
using: composite | ||
steps: | ||
- name: Download artifacts from current build | ||
uses: actions/download-artifact@v3 | ||
with: | ||
path: ${{ github.workspace }}/.dependencies | ||
|
||
- name: Download project dependencies | ||
shell: ${{ inputs.shell }} | ||
id: DownloadDependencies | ||
env: | ||
_project: ${{ inputs.project }} | ||
_buildMode: ${{ inputs.buildMode }} | ||
_projectsDependenciesJson: ${{ inputs.projectsDependenciesJson }} | ||
_baseFolder: ${{ github.workspace }} | ||
_destinationPath: ${{ github.workspace }}/.dependencies | ||
_gitHubToken: ${{ github.token }} | ||
run: | ||
try { | ||
${{ github.action_path }}/DownloadProjectDependencies.Action.ps1 -project $ENV:_project -buildMode $ENV:_buildMode -projectsDependenciesJson $ENV:_projectsDependenciesJson -baseFolder $ENV:_baseFolder -destinationPath $ENV:_destinationPath -token $ENV:_gitHubToken | ||
} | ||
catch { | ||
Write-Host "::Error::Unexpected error when running action ($($_.Exception.Message.Replace("`r",'').Replace("`n",' ')))" | ||
exit 1 | ||
} | ||
branding: | ||
icon: terminal | ||
color: blue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.