Skip to content

Commit

Permalink
Deploying AL-Go from main (6d6292c0fc1295bccd0ec2e91a916bce02210d0f) …
Browse files Browse the repository at this point in the history
…to main (#64)

Deploying AL-Go from main (6d6292c0fc1295bccd0ec2e91a916bce02210d0f) to
main

Co-authored-by: microsoft <[email protected]>
  • Loading branch information
bcbuild-github-agent and microsoft authored Oct 4, 2024
1 parent e0080d1 commit e3d7962
Show file tree
Hide file tree
Showing 15 changed files with 190 additions and 143 deletions.
6 changes: 6 additions & 0 deletions AL-Go-Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ function ReadSettings {
"defaultIndexMD" = "## Reference documentation\n\nThis is the generated reference documentation for [{REPOSITORY}](https://github.com/{REPOSITORY}).\n\nYou can use the navigation bar at the top and the table of contents to the left to navigate your documentation.\n\nYou can change this content by creating/editing the **{INDEXTEMPLATERELATIVEPATH}** file in your repository or use the alDoc:defaultIndexMD setting in your repository settings file (.github/AL-Go-Settings.json)\n\n{RELEASENOTES}"
"defaultReleaseMD" = "## Release reference documentation\n\nThis is the generated reference documentation for [{REPOSITORY}](https://github.com/{REPOSITORY}).\n\nYou can use the navigation bar at the top and the table of contents to the left to navigate your documentation.\n\nYou can change this content by creating/editing the **{INDEXTEMPLATERELATIVEPATH}** file in your repository or use the alDoc:defaultReleaseMD setting in your repository settings file (.github/AL-Go-Settings.json)\n\n{RELEASENOTES}"
}
"trustMicrosoftNuGetFeeds" = $true
}

# Read settings from files and merge them into the settings object
Expand Down Expand Up @@ -768,6 +769,11 @@ function ReadSettings {
if ($settings.shell -ne "powershell" -and $settings.shell -ne "pwsh") {
throw "Invalid value for setting: shell: $($settings.githubRunnerShell)"
}
if (($settings.githubRunner -like "ubuntu-*") -and ($settings.githubRunnerShell -eq "powershell")) {
Write-Host "Switching shell to pwsh for ubuntu"
$settings.githubRunnerShell = "pwsh"
}

if($settings.projectName -eq '') {
$settings.projectName = $project # Default to project path as project name
}
Expand Down
3 changes: 1 addition & 2 deletions AL-Go-TestRepoHelper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ function Test-SettingsJson {
Test-Property -settingsDescription $settingsDescription -json $json -key 'templateUrl' -should
}
if ($type -eq 'Project') {
# GitHubRunner should not be in a project settings file (only read from repo or workflow settings)
Test-Property -settingsDescription $settingsDescription -json $json -key 'githubRunner' -shouldnot
# Test for things that should / should not exist in a project settings file
Test-Property -settingsDescription $settingsDescription -json $json -key 'bcContainerHelperVersion' -shouldnot
}
if ($type -eq 'Workflow') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
function DownloadAlDoc {
if ("$ENV:aldocPath" -eq "") {
$ENV:aldocCommand = ''
Write-Host "Locating aldoc"
$artifactUrl = Get-BCArtifactUrl -type sandbox -country core -select Latest -accept_insiderEula
Write-Host "Downloading aldoc"
Expand All @@ -13,6 +14,14 @@ function DownloadAlDoc {
Remove-Item -Path "$($tempFolder).zip" -Force
if ($IsLinux) {
$ENV:aldocPath = Join-Path $tempFolder 'extension/bin/linux/aldoc'
if (Test-Path $ENV:aldocPath) {
& /usr/bin/env sudo pwsh -command "& chmod +x $ENV:aldocPath"
}
else {
# If the executable isn't found, use dotnet to run the dll
$ENV:aldocPath = Join-Path $tempFolder 'extension/bin/linux/aldoc.dll'
$ENV:aldocCommand = 'dotnet'
}
}
else {
$ENV:aldocPath = Join-Path $tempFolder 'extension/bin/win32/aldoc.exe'
Expand All @@ -21,12 +30,11 @@ function DownloadAlDoc {
throw "aldoc tool not found at $ENV:aldocPath"
}
if ($IsLinux) {
& /usr/bin/env sudo pwsh -command "& chmod +x $ENV:aldocPath"
}
Write-Host "Installing/Updating docfx"
CmdDo -command dotnet -arguments @("tool","update","--global docfx --version 2.75.3") -messageIfCmdNotFound "dotnet not found. Please install it from https://dotnet.microsoft.com/download"
}
return $ENV:aldocPath
return $ENV:aldocPath, $ENV:aldocCommand
}

function SanitizeFileName([string] $fileName) {
Expand Down Expand Up @@ -167,7 +175,15 @@ function GenerateDocsSite {
}
$indexContent = ReplacePlaceHolders -str $indexTemplate -version $version -releaseNotes $releaseNotes -indexTemplateRelativePath $thisTemplateRelativePath

$alDocPath = DownloadAlDoc
$aldocPath, $aldocCommand = DownloadAlDoc
if ($aldocCommand) {
$aldocArguments = @($aldocPath)
}
else {
$aldocArguments = @()
$aldocCommand = $aldocPath
}

$docfxPath = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
New-Item -Path $docfxPath -ItemType Directory | Out-Null
try {
Expand All @@ -181,14 +197,14 @@ function GenerateDocsSite {
}
$apps = @($apps | Select-Object -Unique)

$arguments = @(
$arguments = $aldocArguments + @(
"init"
"--output ""$docfxpath"""
"--loglevel $loglevel"
"--targetpackages ""$($apps -join '","')"""
)
Write-Host "invoke aldoc $arguments"
CmdDo -command $aldocPath -arguments $arguments
Write-Host "invoke $aldocCommand $arguments"
CmdDo -command $aldocCommand -arguments $arguments

# Update docfx.json
Write-Host "Update docfx.json"
Expand All @@ -214,14 +230,14 @@ function GenerateDocsSite {
Get-Content $tocYmlFile | Out-Host

$apps | ForEach-Object {
$arguments = @(
$arguments = $aldocArguments + @(
"build"
"--output ""$docfxpath"""
"--loglevel $loglevel"
"--source ""$_"""
)
Write-Host "invoke aldoc $arguments"
CmdDo -command $aldocPath -arguments $arguments
Write-Host "invoke $aldocCommand $arguments"
CmdDo -command $aldocCommand -arguments $arguments
}

# Set release notes
Expand Down
36 changes: 28 additions & 8 deletions CheckForUpdates/CheckForUpdates.HelperFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,14 @@ function DownloadTemplateRepository {

# Construct API URL
$apiUrl = $templateUrl.Split('@')[0] -replace "^(https:\/\/github\.com\/)(.*)$", "$ENV:GITHUB_API_URL/repos/`$2"
$branch = $templateUrl.Split('@')[1]

Write-Host "TemplateUrl: $templateUrl"
Write-Host "TemplateSha: $($templateSha.Value)"
Write-Host "DownloadLatest: $downloadLatest"

if ($downloadLatest) {
# Get Branches from template repository
$response = InvokeWebRequest -Headers $headers -Uri "$apiUrl/branches?per_page=100" -retry
$branchInfo = ($response.content | ConvertFrom-Json) | Where-Object { $_.Name -eq $branch }
if (!$branchInfo) {
throw "$templateUrl doesn't exist"
}
$templateSha.Value = $branchInfo.commit.sha
# Get latest commit SHA from the template repository
$templateSha.Value = GetLatestTemplateSha -headers $headers -apiUrl $apiUrl -templateUrl $templateUrl
Write-Host "Latest SHA for $($templateUrl): $($templateSha.Value)"
}
$archiveUrl = "$apiUrl/zipball/$($templateSha.Value)"
Expand All @@ -47,6 +41,32 @@ function DownloadTemplateRepository {
return $tempName
}

function GetLatestTemplateSha {
Param(
[hashtable] $headers,
[string] $apiUrl,
[string] $templateUrl
)
$branch = $templateUrl.Split('@')[1]

try {
$response = InvokeWebRequest -Headers $headers -Uri "$apiUrl/branches?per_page=100" -retry
$branchInfo = ($response.content | ConvertFrom-Json) | Where-Object { $_.Name -eq $branch }
} catch {
if ($_.Exception.Message -like "*401*") {
throw "Failed to update AL-Go System Files. Make sure that the personal access token, defined in the secret called GhTokenWorkflow, is not expired and it has permission to update workflows. (Error was $($_.Exception.Message))"
} else {
throw $_.Exception.Message
}
}

if (!$branchInfo) {
throw "$templateUrl doesn't exist"
}

return $branchInfo.commit.sha
}

function ModifyCICDWorkflow {
Param(
[Yaml] $yaml,
Expand Down
7 changes: 3 additions & 4 deletions CheckForUpdates/CheckForUpdates.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,9 @@ $removeFiles = @()
# Every build job might spin up multiple jobs in parallel to build the projects without unresolved deependencies
$depth = 1
if ($repoSettings.useProjectDependencies -and $projects.Count -gt 1) {
$buildAlso = @{}
$projectDependencies = @{}
$projectsOrder = AnalyzeProjectDependencies -baseFolder $baseFolder -projects $projects -buildAlso ([ref]$buildAlso) -projectDependencies ([ref]$projectDependencies)
$depth = $projectsOrder.Count
Import-Module (Join-Path -Path $PSScriptRoot -ChildPath "..\DetermineProjectsToBuild\DetermineProjectsToBuild.psm1" -Resolve) -DisableNameChecking
$allProjects, $projectsToBuild, $projectDependencies, $buildOrder = Get-ProjectsToBuild -baseFolder $baseFolder -buildAllProjects $true -maxBuildDepth 100
$depth = $buildOrder.Count
Write-Host "Calculated dependency depth to be $depth"
}

Expand Down
113 changes: 25 additions & 88 deletions Deliver/Deliver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ foreach ($thisProject in $projectList) {
"RepoSettings" = $settings
"ProjectSettings" = $projectSettings
}
#Calculate the folders per artifact type

#Calculate the folders per artifact type
'Apps', 'TestApps', 'Dependencies' | ForEach-Object {
Expand Down Expand Up @@ -226,9 +225,24 @@ foreach ($thisProject in $projectList) {
Write-Host "Calling custom script: $customScript"
. $customScript -parameters $parameters
}
elseif ($deliveryTarget -eq "GitHubPackages") {
$githubPackagesCredential = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($secrets.githubPackagesContext)) | ConvertFrom-Json
'Apps' | ForEach-Object {
elseif ($deliveryTarget -eq 'GitHubPackages' -or $deliveryTarget -eq 'NuGet') {
$preReleaseTag = ''
try {
$nuGetAccount = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($secrets."$($deliveryTarget)Context")) | ConvertFrom-Json | ConvertTo-HashTable
if ($deliveryTarget -eq 'NuGet' -and $type -eq 'CD') {
# When doing continuous delivery to NuGet, we always use the preview tag
# When doing a release, we do not add a preview tag
$preReleaseTag = 'preview'
}
$nuGetServerUrl = $nuGetAccount.ServerUrl
Write-Host $nuGetAccount.ServerUrl
$nuGetToken = $nuGetAccount.Token
Write-Host "$($deliveryTarget)Context secret OK"
}
catch {
throw "$($deliveryTarget)Context secret is malformed. Needs to be formatted as Json, containing serverUrl and token as a minimum."
}
'Apps','TestApps' | ForEach-Object {
$folder = @(Get-ChildItem -Path (Join-Path $artifactsFolder "$project-$refname-$($_)-*.*.*.*") | Where-Object { $_.PSIsContainer })
if ($folder.Count -gt 1) {
$folder | Out-Host
Expand All @@ -237,93 +251,16 @@ foreach ($thisProject in $projectList) {
elseif ($folder.Count -eq 1) {
Get-Item -Path (Join-Path $folder[0] "*.app") | ForEach-Object {
$parameters = @{
"gitHubRepository" = "$ENV:GITHUB_SERVER_URL/$ENV:GITHUB_REPOSITORY"
"includeNuGetDependencies" = $true
"dependencyIdTemplate" = "AL-Go-{id}"
"packageId" = "AL-Go-{id}"
"gitHubRepository" = "$ENV:GITHUB_SERVER_URL/$ENV:GITHUB_REPOSITORY"
"preReleaseTag" = $preReleaseTag
"appFile" = $_.FullName
}
$parameters.appFiles = $_.FullName
$package = New-BcNuGetPackage @parameters
Push-BcNuGetPackage -nuGetServerUrl $gitHubPackagesCredential.serverUrl -nuGetToken $gitHubPackagesCredential.token -bcNuGetPackage $package
Push-BcNuGetPackage -nuGetServerUrl $nuGetServerUrl -nuGetToken $nuGetToken -bcNuGetPackage $package
}
}
}
}
elseif ($deliveryTarget -eq "NuGet") {
try {
$nuGetAccount = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($secrets.nuGetContext)) | ConvertFrom-Json | ConvertTo-HashTable
$nuGetServerUrl = $nuGetAccount.ServerUrl
$nuGetToken = $nuGetAccount.Token
Write-Host "NuGetContext secret OK"
}
catch {
throw "NuGetContext secret is malformed. Needs to be formatted as Json, containing serverUrl and token as a minimum."
}
$appsfolder = @(Get-ChildItem -Path (Join-Path $artifactsFolder "$project-$refname-Apps-*.*.*.*") | Where-Object { $_.PSIsContainer })
if ($appsFolder.Count -eq 0) {
throw "Internal error - unable to locate apps folder"
}
elseif ($appsFolder.Count -gt 1) {
$appsFolder | Out-Host
throw "Internal error - multiple apps folders located"
}
$testAppsFolder = @(Get-ChildItem -Path (Join-Path $artifactsFolder "$project-$refname-TestApps-*.*.*.*") | Where-Object { $_.PSIsContainer })
if ($testAppsFolder.Count -gt 1) {
$testAppsFolder | Out-Host
throw "Internal error - multiple testApps folders located"
}
$dependenciesFolder = @(Get-ChildItem -Path (Join-Path $artifactsFolder "$project-$refname-Dependencies-*.*.*.*") | Where-Object { $_.PSIsContainer })
if ($dependenciesFolder.Count -gt 1) {
$dependenciesFolder | Out-Host
throw "Internal error - multiple dependencies folders located"
}

$parameters = @{
"gitHubRepository" = "$ENV:GITHUB_SERVER_URL/$ENV:GITHUB_REPOSITORY"
}
$parameters.appFiles = @(Get-Item -Path (Join-Path $appsFolder[0] "*.app") | ForEach-Object { $_.FullName })
if ($testAppsFolder.Count -gt 0) {
$parameters.testAppFiles = @(Get-Item -Path (Join-Path $testAppsFolder[0] "*.app") | ForEach-Object { $_.FullName })
}
if ($dependenciesFolder.Count -gt 0) {
$parameters.dependencyAppFiles = @(Get-Item -Path (Join-Path $dependenciesFolder[0] "*.app") | ForEach-Object { $_.FullName })
}
if ($nuGetAccount.Keys -contains 'PackageName') {
$parameters.packageId = $nuGetAccount.PackageName.replace('{project}', $projectName).replace('{owner}', $ENV:GITHUB_REPOSITORY_OWNER).replace('{repo}', $settings.repoName)
}
else {
if ($thisProject -and ($thisProject -eq '.')) {
$parameters.packageId = "$($ENV:GITHUB_REPOSITORY_OWNER)-$($settings.repoName)"
}
else {
$parameters.packageId = "$($ENV:GITHUB_REPOSITORY_OWNER)-$($settings.repoName)-$ProjectName"
}
}
if ($type -eq 'CD') {
$parameters.packageId += "-preview"
}
$parameters.packageVersion = [System.Version]$appsFolder[0].Name.SubString($appsFolder[0].Name.IndexOf("-Apps-") + 6)
if ($nuGetAccount.Keys -contains 'PackageTitle') {
$parameters.packageTitle = $nuGetAccount.PackageTitle
}
else {
$parameters.packageTitle = $parameters.packageId
}
if ($nuGetAccount.Keys -contains 'PackageDescription') {
$parameters.packageDescription = $nuGetAccount.PackageDescription
}
else {
$parameters.packageDescription = $parameters.packageTitle
}
if ($nuGetAccount.Keys -contains 'PackageAuthors') {
$parameters.packageAuthors = $nuGetAccount.PackageAuthors
}
else {
$parameters.packageAuthors = $actor
}
$package = New-BcNuGetPackage @parameters
Push-BcNuGetPackage -nuGetServerUrl $nuGetServerUrl -nuGetToken $nuGetToken -bcNuGetPackage $package
}
elseif ($deliveryTarget -eq "Storage") {
InstallAzModuleIfNeeded -name 'Az.Storage'
try {
Expand Down Expand Up @@ -457,9 +394,9 @@ foreach ($thisProject in $projectList) {
}
$depfolder = $depfolder[0].FullName
$libraryAppFiles += @(Get-ChildItem -path $depFolder | Where-Object {
$name = $_.name
$appSourceIncludeDependencies | Where-Object { $name -like $_ }
} | ForEach-Object { $_.FullName })
$name = $_.name
$appSourceIncludeDependencies | Where-Object { $name -like $_ }
} | ForEach-Object { $_.FullName })
}

Write-Host "Main App File:"
Expand Down
32 changes: 23 additions & 9 deletions DetermineDeliveryTargets/DetermineDeliveryTargets.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ Param(
[bool] $checkContextSecrets
)

function ContinuousDelivery([string] $deliveryTarget) {
$settingsName = "DeliverTo$deliveryTarget"
if ($deliveryTarget -eq 'AppSource' -and $settings.type -eq "AppSource App") {
# For multi-project repositories, ContinuousDelivery can be set on the projects
foreach($project in ($projectsJson | ConvertFrom-Json)) {
$projectSettings = ReadSettings -project $project
if ($projectSettings.deliverToAppSource.ContinuousDelivery -or ($projectSettings.Contains('AppSourceContinuousDelivery') -and $projectSettings.AppSourceContinuousDelivery)) {
Write-Host "Project $project is setup for Continuous Delivery to AppSource"
return $true
}
}
return $false
}
elseif ($settings.Contains($settingsName) -and $settings."$settingsName".Contains('ContinuousDelivery')) {
return $settings."$settingsName".ContinuousDelivery
}
else {
return $true
}
}

function IncludeBranch([string] $deliveryTarget) {
$settingsName = "DeliverTo$deliveryTarget"
if ($settings.Contains($settingsName) -and $settings."$settingsName".Contains('Branches')) {
Expand All @@ -26,22 +47,15 @@ function IncludeDeliveryTarget([string] $deliveryTarget) {
Write-Host "- Secret '$contextName' not found"
return $false
}
return (IncludeBranch -deliveryTarget $deliveryTarget)
return (IncludeBranch -deliveryTarget $deliveryTarget) -and (ContinuousDelivery -deliveryTarget $deliveryTarget)
}

. (Join-Path -Path $PSScriptRoot -ChildPath "..\AL-Go-Helper.ps1" -Resolve)

$settings = $env:Settings | ConvertFrom-Json | ConvertTo-HashTable -recurse
$deliveryTargets = @('GitHubPackages','NuGet','Storage')
if ($settings.type -eq "AppSource App") {
# For multi-project repositories, we will add deliveryTarget AppSource if any project has AppSourceContinuousDelivery set to true
($projectsJson | ConvertFrom-Json) | ForEach-Object {
$projectSettings = ReadSettings -project $_
if ($projectSettings.deliverToAppSource.ContinuousDelivery -or ($projectSettings.Contains('AppSourceContinuousDelivery') -and $projectSettings.AppSourceContinuousDelivery)) {
Write-Host "Project $_ is setup for Continuous Delivery to AppSource"
$deliveryTargets += @("AppSource")
}
}
$deliveryTargets += @("AppSource")
}
# Include custom delivery targets
$namePrefix = 'DeliverTo'
Expand Down
Loading

0 comments on commit e3d7962

Please sign in to comment.