Skip to content

Commit

Permalink
Refactor CheckForUpdates (#753)
Browse files Browse the repository at this point in the history
Refactor CheckForUpdates and modify all Y/N string input fields to type:
boolean in all workflows.
This PR also adds the TemplateSha to .github/AL-Go-Settings to allow for
not downloading latest version of AL-Go system files, but instead update
the existing files based on settings changes.

---------

Co-authored-by: freddydk <[email protected]>
Co-authored-by: Maria Zhelezova <[email protected]>
Co-authored-by: Alexander Holstrup <[email protected]>
  • Loading branch information
4 people authored Nov 28, 2023
1 parent 8df6c4a commit fab5350
Show file tree
Hide file tree
Showing 86 changed files with 1,689 additions and 1,426 deletions.
62 changes: 0 additions & 62 deletions .github/workflows/Collect.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions .github/workflows/E2E.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ on:
default: ''
runTestMatrix:
description: Run the end to end test scenario for the full test matrix
required: false
type: boolean
default: true
runScenarios:
description: Run the end to end scenario tests
required: false
type: boolean
default: true
runUpgradeTests:
description: Run the end to end upgrade tests
required: false
type: boolean
default: true
bcContainerHelperVersion:
Expand Down
73 changes: 59 additions & 14 deletions Actions/AL-Go-Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ function ReadSettings {
"obsoleteTagMinAllowedMajorMinor" = ""
"memoryLimit" = ""
"templateUrl" = ""
"templateSha" = ""
"templateBranch" = ""
"appDependencyProbingPaths" = @()
"useProjectDependencies" = $false
Expand Down Expand Up @@ -1253,7 +1254,9 @@ function CloneIntoNewFolder {
Param(
[string] $actor,
[string] $token,
[string] $branch
[string] $updateBranch = $ENV:GITHUB_REF_NAME,
[string] $newBranchPrefix = '',
[bool] $directCommit
)

$baseFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
Expand All @@ -1275,13 +1278,16 @@ function CloneIntoNewFolder {
invoke-git clone $serverUrl

Set-Location *
invoke-git checkout $ENV:GITHUB_REF_NAME
invoke-git checkout $updateBranch

if ($branch) {
$branch = ''
if (!$directCommit) {
$branch = "$newBranchPrefix/$updateBranch/$((Get-Date).ToUniversalTime().ToString(`"yyMMddHHmmss`"))" # e.g. create-development-environment/main/210101120000
invoke-git checkout -b $branch
}

$serverUrl
$branch
}

function CommitFromNewFolder {
Expand All @@ -1292,21 +1298,29 @@ function CommitFromNewFolder {
)

invoke-git add *
if ($commitMessage.Length -gt 250) {
$commitMessage = "$($commitMessage.Substring(0,250))...)"
}
invoke-git commit --allow-empty -m "'$commitMessage'"
if ($branch) {
invoke-git push -u $serverUrl $branch
try {
invoke-gh pr create --fill --head $branch --repo $env:GITHUB_REPOSITORY --base $ENV:GITHUB_REF_NAME
$status = invoke-git -returnValue status --porcelain=v1
if ($status) {
if ($commitMessage.Length -gt 250) {
$commitMessage = "$($commitMessage.Substring(0,250))...)"
}
invoke-git commit --allow-empty -m "$commitMessage"
if ($branch) {
invoke-git push -u $serverUrl $branch
try {
invoke-gh pr create --fill --head $branch --repo $env:GITHUB_REPOSITORY --base $ENV:GITHUB_REF_NAME
}
catch {
OutputError("GitHub actions are not allowed to create Pull Requests (see GitHub Organization or Repository Actions Settings). You can create the PR manually by navigating to $($env:GITHUB_SERVER_URL)/$($env:GITHUB_REPOSITORY)/tree/$branch")
}
}
catch {
OutputError("GitHub actions are not allowed to create Pull Requests (see GitHub Organization or Repository Actions Settings). You can create the PR manually by navigating to $($env:GITHUB_SERVER_URL)/$($env:GITHUB_REPOSITORY)/tree/$branch")
else {
invoke-git push $serverUrl
}
return $true
}
else {
invoke-git push $serverUrl
Write-Host "No changes detected in files"
return $false
}
}

Expand Down Expand Up @@ -2222,3 +2236,34 @@ function RetryCommand {
}
}
}

function GetProjectsFromRepository {
Param(
[string] $baseFolder,
[string[]] $projectsFromSettings,
[string] $selectProjects = ''
)
if ($projectsFromSettings) {
$projects = $projectsFromSettings
}
else {
# For multiple projects, get all folders in two levels below the base folder containing an .AL-Go folder with a settings.json file
$projects = @(Get-ChildItem -Path $baseFolder -Recurse -Depth 2 -Force | Where-Object { $_.PSIsContainer -and (Test-Path (Join-Path $_.FullName ".AL-Go/settings.json") -PathType Leaf) } | ForEach-Object { $_.FullName.Substring($baseFolder.length+1) })
# To support single project repositories, we check for the .AL-Go folder in the root
if (Test-Path (Join-Path $baseFolder ".AL-Go/settings.json") -PathType Leaf) {
$projects += @(".")
}
}
if ($selectProjects) {
# Filter the project list based on the projects parameter
if ($selectProjects.StartsWith('[')) {
$selectProjects = ($selectProjects | ConvertFrom-Json) -join ","
}
$projectArr = $selectProjects.Split(',').Trim()
$projects = @($projects | Where-Object { $project = $_; if ($projectArr | Where-Object { $project -like $_ }) { $project } })
if ($projects.Count -eq 0) {
throw "No projects matches '$selectProjects'"
}
}
return $projects
}
11 changes: 3 additions & 8 deletions Actions/AddExistingApp/AddExistingApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[string] $url,
[Parameter(HelpMessage = "Set the branch to update", Mandatory = $false)]
[string] $updateBranch,
[Parameter(HelpMessage = "Direct Commit (Y/N)", Mandatory = $false)]
[Parameter(HelpMessage = "Direct Commit?", Mandatory = $false)]
[bool] $directCommit
)

Expand Down Expand Up @@ -82,12 +82,7 @@ $telemetryScope = $null

try {
. (Join-Path -Path $PSScriptRoot -ChildPath "..\AL-Go-Helper.ps1" -Resolve)
$branch = ''
if (!$directcommit) {
# If not direct commit, create a new branch with name, relevant to the current date and base branch, and switch to it
$branch = "add-existing-app/$updateBranch/$((Get-Date).ToUniversalTime().ToString(`"yyMMddHHmmss`"))" # e.g. add-existing-app/main/210101120000
}
$serverUrl = CloneIntoNewFolder -actor $actor -token $token -branch $branch
$serverUrl, $branch = CloneIntoNewFolder -actor $actor -token $token -updateBranch $updateBranch -DirectCommit $directCommit -newBranchPrefix 'add-existing-app'
$baseFolder = (Get-Location).path
DownloadAndImportBcContainerHelper -baseFolder $baseFolder

Expand Down Expand Up @@ -219,7 +214,7 @@ try {
}
}
Set-Location $baseFolder
CommitFromNewFolder -serverUrl $serverUrl -commitMessage "Add existing apps ($($appNames -join ', '))" -branch $branch
CommitFromNewFolder -serverUrl $serverUrl -commitMessage "Add existing apps ($($appNames -join ', '))" -branch $branch | Out-Null

TrackTrace -telemetryScope $telemetryScope
}
Expand Down
2 changes: 1 addition & 1 deletion Actions/AddExistingApp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ none
| project | | Project name if the repository is setup for multiple projects | . |
| url | Yes | Direct Download Url of .app or .zip file to add to the repository | |
| updateBranch | | Which branch should the app be added to | github.ref_name |
| directCommit | | Y if the action should create a direct commit against the branch or N to create a Pull Request | N |
| directCommit | | true if the action should create a direct commit against the branch or false to create a Pull Request | false |

## OUTPUT
none
6 changes: 3 additions & 3 deletions Actions/AddExistingApp/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ inputs:
required: false
default: ${{ github.ref_name }}
directCommit:
description: Direct Commit (Y/N)
description: Direct Commit?
required: false
default: 'N'
default: 'false'
runs:
using: composite
steps:
Expand All @@ -51,7 +51,7 @@ runs:
run: |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
try {
${{ github.action_path }}/AddExistingApp.ps1 -actor $ENV:_actor -token $ENV:_token -parentTelemetryScopeJson $ENV:_parentTelemetryScopeJson -project $ENV:_project -url $ENV:_url -updateBranch $ENV:_updateBranch -directCommit ($ENV:_directCommit -eq 'Y')
${{ github.action_path }}/AddExistingApp.ps1 -actor $ENV:_actor -token $ENV:_token -parentTelemetryScopeJson $ENV:_parentTelemetryScopeJson -project $ENV:_project -url $ENV:_url -updateBranch $ENV:_updateBranch -directCommit ($ENV:_directCommit -eq 'true')
}
catch {
Write-Host "::ERROR::Unexpected error when running action. Error Message: $($_.Exception.Message.Replace("`r",'').Replace("`n",' ')), StackTrace: $($_.ScriptStackTrace.Replace("`r",'').Replace("`n",' <- '))";
Expand Down
Loading

0 comments on commit fab5350

Please sign in to comment.