Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for indirect template + customizations #853

Open
wants to merge 140 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
1fede69
move customizationcap.
freddydk Dec 12, 2023
ad207da
use type
freddydk Dec 12, 2023
2c0e1c2
use additional
freddydk Dec 12, 2023
e9fc847
realtemplate
freddydk Dec 12, 2023
cb81cfa
dump
freddydk Dec 12, 2023
7c3046b
use correct settings
freddydk Dec 12, 2023
cfe76e8
use correct template
freddydk Dec 12, 2023
753c7fc
add subfolder
freddydk Dec 12, 2023
f03dbd3
release notes
freddydk Dec 12, 2023
c5ee954
lf
freddydk Dec 12, 2023
811cc63
lines
freddydk Dec 12, 2023
5971157
exp
freddydk Dec 12, 2023
8fe0008
docs
freddydk Dec 13, 2023
32b5586
aspit
freddydk Dec 13, 2023
2bcc4ae
remove bold
freddydk Dec 13, 2023
dc918e3
Merge branch 'main' into customize
freddydk Dec 13, 2023
f262369
Merge branch 'main' into customize
freddydk Dec 13, 2023
3c6f7cd
do not use AL-Go name in package name
freddydk Dec 15, 2023
fba7d14
Merge branch 'customize' of https://github.com/freddydk/AL-Go into cu…
freddydk Dec 15, 2023
3c81b0f
Merge branch 'main' into customize
freddydk Feb 10, 2024
4b20113
Merge branch 'main' into customize
freddydk Feb 23, 2024
849bd2f
Merge branch 'main' into customize
freddydk Apr 13, 2024
bac90bf
Merge branch 'main' into customize
freddydk May 14, 2024
61fe36d
Merge branch 'main' into customize
freddydk May 15, 2024
2280f29
Merge branch 'main' into customize
freddydk Jun 7, 2024
703d51f
Merge branch 'main' into customize
freddydk Jun 24, 2024
9445fdd
Merge branch 'main' into customize
freddydk Jun 24, 2024
418d40f
pre-commit
freddydk Jun 24, 2024
fbe3a36
Merge branch 'main' into customize
freddydk Jun 26, 2024
e769c70
Merge branch 'main' into customize
freddydk Jul 24, 2024
2efb6a5
back
freddydk Jul 24, 2024
cbe78ef
Merge branch 'main' into customize
freddydk Jul 25, 2024
bcc2f3e
add permissions
freddydk Jul 25, 2024
2c62b84
add
freddydk Jul 25, 2024
496db91
add
freddydk Jul 25, 2024
4445277
dumps
freddydk Jul 25, 2024
7ef5d3d
add merge
freddydk Jul 25, 2024
6e8b95c
merge
freddydk Jul 25, 2024
422386d
use pso
freddydk Jul 25, 2024
40e20fd
use prop
freddydk Jul 25, 2024
846626e
test
freddydk Jul 25, 2024
82361a8
no idx
freddydk Jul 25, 2024
0936282
no idx
freddydk Jul 25, 2024
b156693
lower case
freddydk Jul 25, 2024
af146b7
add permissions
freddydk Jul 25, 2024
b9219b7
updates
freddydk Jul 27, 2024
dd36934
content parameter
freddydk Jul 27, 2024
f6c2dfb
use str
freddydk Jul 27, 2024
2992605
fix needs
freddydk Jul 27, 2024
b3534d5
add end 2 end test scenario and unit tests
freddydk Jul 30, 2024
5f34aed
precommit
freddydk Jul 30, 2024
99fb554
Merge branch 'main' into customize
freddydk Aug 5, 2024
418d259
Merge branch 'main' into customize
freddydk Aug 7, 2024
f19dda6
add pipeline init and finalize
freddydk Aug 7, 2024
a2e7b2b
support cicdauthcontext
freddydk Aug 8, 2024
91041b1
env name
freddydk Aug 8, 2024
492cfb5
dump
freddydk Aug 8, 2024
699ff4d
remove dump
freddydk Aug 9, 2024
260c2f3
Merge branch 'main' into customize
freddydk Aug 9, 2024
b2e47b1
fix tests
freddydk Aug 9, 2024
563c22f
Merge branch 'customize' of https://github.com/freddydk/AL-Go into cu…
freddydk Aug 9, 2024
1cc3a94
fix aldoc if
freddydk Aug 11, 2024
b48f675
Replace template owner
freddydk Aug 11, 2024
7c986d9
remove jekyll
freddydk Aug 11, 2024
39023cf
modify readme
freddydk Aug 11, 2024
0c69b29
dump readme
freddydk Aug 11, 2024
821aa81
dump
freddydk Aug 11, 2024
525048b
replace
freddydk Aug 11, 2024
1066788
merge if permissions are present
freddydk Aug 13, 2024
8258572
check
freddydk Aug 13, 2024
32e7f1b
check not ''
freddydk Aug 13, 2024
ddd95b1
add dump
freddydk Aug 13, 2024
96818d7
remove unused files not present in template
freddydk Aug 13, 2024
c97f705
move unused check
freddydk Aug 13, 2024
01b6d49
add customALGoSystemFiles
freddydk Aug 18, 2024
c43ea9a
Apply custom files
freddydk Aug 19, 2024
fd03c25
add to updates files
freddydk Aug 19, 2024
9ac3f24
relative
freddydk Aug 19, 2024
362ec0f
remove path
freddydk Aug 19, 2024
977f94b
do not dump custom algo system files
freddydk Aug 19, 2024
4ccfc85
compare
freddydk Aug 19, 2024
48cd019
define existing
freddydk Aug 19, 2024
5b70630
dump modified files
freddydk Aug 19, 2024
f83caa2
syntax
freddydk Aug 19, 2024
7646df4
use basefolder
freddydk Aug 19, 2024
c23d28c
doc
freddydk Aug 19, 2024
c7c49d8
upd
freddydk Aug 19, 2024
f8a1310
update custom and unused algo system files
freddydk Aug 22, 2024
4317c17
Support private template repo
freddydk Aug 22, 2024
57acb7c
use ghtokenworkflow
freddydk Aug 22, 2024
5573506
dump content
freddydk Aug 22, 2024
3ec676b
only update changed settings files
freddydk Aug 22, 2024
0d39e96
decode
freddydk Aug 22, 2024
3451a4a
indirect
freddydk Aug 22, 2024
37b7ecb
insert
freddydk Aug 22, 2024
78fb7a8
Merge branch 'main' into customize
freddydk Aug 22, 2024
dccb8e4
remove jekyll
freddydk Aug 22, 2024
6b51661
Merge branch 'customize' of https://github.com/freddydk/AL-Go into cu…
freddydk Aug 22, 2024
570628a
revert
freddydk Aug 22, 2024
e599e38
update
freddydk Aug 22, 2024
5cc070b
update release notes
freddydk Aug 22, 2024
cde82c9
rev
freddydk Aug 22, 2024
3decba8
Merge branch 'main' into customize
freddydk Aug 22, 2024
d60be05
psa
freddydk Aug 22, 2024
a1a2a6b
Merge branch 'customize' of https://github.com/freddydk/AL-Go into cu…
freddydk Aug 22, 2024
fa4a71b
remove
freddydk Aug 22, 2024
6685835
move
freddydk Aug 22, 2024
99265e6
remove fake button
freddydk Aug 22, 2024
0969502
use preview
freddydk Aug 22, 2024
a2dbcfd
precommit
freddydk Aug 22, 2024
a01e57a
dump token length
freddydk Aug 22, 2024
46da82c
add ghTokenWorkflow parameter
freddydk Aug 22, 2024
fa5a2d4
add ght
freddydk Aug 22, 2024
5c40c15
use token
freddydk Aug 22, 2024
000ae79
dump with token is used
freddydk Aug 22, 2024
26149de
check if permissions
freddydk Aug 22, 2024
51d5da5
Merge branch 'main' into customize
freddydk Aug 26, 2024
2457a21
Merge branch 'main' into customize
freddydk Aug 27, 2024
0e6e7c3
Update Scenarios/CustomizingALGoForGitHub.md
freddydk Sep 2, 2024
858865e
Update Scenarios/CustomizingALGoForGitHub.md
freddydk Sep 2, 2024
114bdc3
Merge branch 'main' into customize
freddydk Sep 3, 2024
f252f29
empty line
freddydk Sep 3, 2024
2e7722a
Update Scenarios/CustomizingALGoForGitHub.md
freddydk Sep 9, 2024
a76dc7d
Update Scenarios/settings.md
freddydk Sep 9, 2024
ab27cdb
Merge branch 'main' into customize
freddydk Sep 9, 2024
ddef716
prop
freddydk Sep 13, 2024
2ca9c43
merge
freddydk Oct 13, 2024
dc4580f
merge
freddydk Oct 13, 2024
1e857e3
Merge branch 'main' into customize
freddydk Oct 13, 2024
2cf539e
remove
freddydk Oct 29, 2024
5e06f58
Merge branch 'main' into customize
freddydk Oct 29, 2024
3ad4cbe
feat: add needsContext as env to build process (#206)
PatrickSchiefer Oct 29, 2024
1355bca
modify default
freddydk Oct 29, 2024
3fa79d6
feat: add needContext to Build job (#208)
PatrickSchiefer Oct 29, 2024
72c3749
Merge branch 'main' into customize
freddydk Nov 1, 2024
c5762f7
Merge branch 'main' into customize
freddydk Nov 1, 2024
23561ca
Merge branch 'main' into customize
freddydk Dec 10, 2024
ce76955
Merge branch 'main' into customize
freddydk Dec 16, 2024
d2b9fa9
Merge branch 'main' into customize
freddydk Dec 18, 2024
bbd9cd2
move
freddydk Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ function IsDirectALGo {

function GetSrcFolder {
Param(
[hashtable] $repoSettings,
[string] $repoType,
[string] $templateUrl,
[string] $templateFolder,
[string] $srcPath
Expand All @@ -291,7 +291,7 @@ function GetSrcFolder {
return ''
}
if (IsDirectALGo -templateUrl $templateUrl) {
switch ($repoSettings.type) {
switch ($repoType) {
"PTE" {
$typePath = "Per Tenant Extension"
}
Expand Down
91 changes: 82 additions & 9 deletions Actions/CheckForUpdates/CheckForUpdates.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
# ContainerHelper is used for determining project folders and dependencies
DownloadAndImportBcContainerHelper

$anchors = @{
"_BuildALGoProject.yaml" = @{
"BuildALGoProject" = @(
@{ "Step" = 'Read settings'; "Before" = $false }
@{ "Step" = 'Read secrets'; "Before" = $false }
@{ "Step" = 'Build'; "Before" = $true }
@{ "Step" = 'Build'; "Before" = $false }
@{ "Step" = 'Cleanup'; "Before" = $true }
)
}
}

if ($update -eq 'Y') {
if (-not $token) {
throw "A personal access token with permissions to modify Workflows is needed. You must add a secret called GhTokenWorkflow containing a personal access token. You can Generate a new token from https://github.com/settings/tokens. Make sure that the workflow scope is checked."
Expand Down Expand Up @@ -64,19 +76,48 @@
$downloadLatest = $true
}

$realTemplateFolder = $null
$templateFolder = DownloadTemplateRepository -headers $headers -templateUrl $templateUrl -templateSha ([ref]$templateSha) -downloadLatest $downloadLatest
Write-Host "Template Folder: $templateFolder"

$templateBranch = $templateUrl.Split('@')[1]
$templateOwner = $templateUrl.Split('/')[3]

$indirectTemplateRepoSettings = @{}
$indirectTemplateProjectSettings = @{}

$isDirectALGo = IsDirectALGo -templateUrl $templateUrl
if (-not $isDirectALGo) {
$ALGoSettingsFile = Join-Path $templateFolder "*/$repoSettingsFile"
if (Test-Path -Path $ALGoSettingsFile -PathType Leaf) {
$templateRepoSettings = Get-Content $ALGoSettingsFile -Encoding UTF8 | ConvertFrom-Json | ConvertTo-HashTable -Recurse
$myRepoSettingsFile = Join-Path $templateFolder "*/$RepoSettingsFile"
if (Test-Path -Path $myRepoSettingsFile -PathType Leaf) {
$templateRepoSettings = Get-Content $myRepoSettingsFile -Encoding UTF8 | ConvertFrom-Json | ConvertTo-HashTable -Recurse
if ($templateRepoSettings.Keys -contains "templateUrl" -and $templateRepoSettings.templateUrl -ne $templateUrl) {
throw "The specified template repository is not a template repository, but instead another AL-Go repository. This is not supported."
# The template repository is a url to another AL-Go repository (an indirect template repository)
# TemplateUrl and TemplateSha from .github/AL-Go-Settings.json in the indirect template reposotiry points to the "real" template repository
# Copy files and folders from the indirect template repository, but grab the unmodified file from the "real" template repository if it exists and apply customizations
Write-Host "Indirect AL-Go template repository detected, downloading the 'real' template repository"
$realTemplateUrl = $templateRepoSettings.templateUrl
if ($templateRepoSettings.Keys -contains "templateSha") {
$realTemplateSha = $templateRepoSettings.templateSha
}
else {
$realTemplateSha = ""
}
# Download the "real" template repository - use downloadLatest if no TemplateSha is specified in the indirect template repository
$realTemplateFolder = DownloadTemplateRepository -headers $headers -templateUrl $realTemplateUrl -templateSha ([ref]$realTemplateSha) -downloadLatest ($realTemplateSha -eq '')
Write-Host "Real Template Folder: $realTemplateFolder"

# Set TemplateBranch and TemplateOwner
# Keep TemplateUrl and TemplateSha pointing to the indirect template repository
$templateBranch = $realTemplateUrl.Split('@')[1]
$templateOwner = $realTemplateUrl.Split('/')[3]

$indirectTemplateRepoSettings = $templateRepoSettings
$myALGoSettingsFile = Join-Path $templateFolder "*/$ALGoSettingsFile"
if (Test-Path $myALGoSettingsFile -PathType Leaf) {
Write-Host "Read project settings from indirect template repository"
$indirectTemplateProjectSettings = Get-Content $myALGoSettingsFile -Encoding UTF8 | ConvertFrom-Json | ConvertTo-HashTable -Recurse
}
}
}
}
Expand Down Expand Up @@ -128,10 +169,21 @@
$srcPath = $checkfile.srcPath
$dstPath = $checkfile.dstPath
$dstFolder = Join-Path $baseFolder $dstPath
$srcFolder = GetSrcFolder -repoSettings $repoSettings -templateUrl $templateUrl -templateFolder $templateFolder -srcPath $srcPath
$srcFolder = GetSrcFolder -repoType $repoSettings.type -templateUrl $templateUrl -templateFolder $templateFolder -srcPath $srcPath
$realSrcFolder = $null
if ($realTemplateFolder) {
$realSrcFolder = GetSrcFolder -repoType $repoSettings.type -templateUrl $realTemplateUrl -templateFolder $realTemplateFolder -srcPath $srcPath
}
if ($srcFolder) {
Push-Location -Path $srcFolder
try {
if ($srcPath -eq '.AL-Go' -and $type -eq "script" -and $realSrcFolder) {
Write-Host "Update Project Settings"
# Copy individual settings from the indirect template repository .AL-Go/settings.json (if the setting doesn't exist in the project folder)
$projectSettingsFile = Join-Path $dstFolder "settings.json"
UpdateSettingsFile -settingsFile $projectSettingsFile -updateSettings @{} -additionalSettings $indirectTemplateProjectSettings
$updateFiles += @{ "DstFile" = Join-Path $dstPath "settings.json"; "content" = (Get-Content -Path $projectSettingsFile -Encoding UTF8 -Raw) }
}
# Loop through all files in the template repository matching the pattern
Get-ChildItem -Path $srcFolder -Filter $checkfile.pattern | ForEach-Object {
# Read the template file and modify it based on the settings
Expand All @@ -140,24 +192,41 @@
Write-Host "- $filename"
$dstFile = Join-Path $dstFolder $fileName
$srcFile = $_.FullName
$realSrcFile = $srcFile
$isFileDirectALGo = $isDirectALGo
Write-Host "SrcFolder: $srcFolder"
if ($realSrcFolder) {
# if SrcFile is an indirect template repository, we need to find the file in the "real" template repository
$fname = Join-Path $realSrcFolder (Resolve-Path $srcFile -Relative)
if (Test-Path -Path $fname -PathType Leaf) {
Write-Host "File is available in the 'real' template repository"
$realSrcFile = $fname
$isFileDirectALGo = IsDirectALGo -templateUrl $realTemplateUrl
}
}
if ($type -eq "workflow") {
# for workflow files, we might need to modify the file based on the settings
$srcContent = GetWorkflowContentWithChangesFromSettings -srcFile $srcFile -repoSettings $repoSettings -depth $depth
$srcContent = GetWorkflowContentWithChangesFromSettings -srcFile $realSrcFile -repoSettings $repoSettings -depth $depth
}
else {
# For non-workflow files, just read the file content
$srcContent = Get-ContentLF -Path $srcFile
$srcContent = Get-ContentLF -Path $realSrcFile
}

# Replace static placeholders
$srcContent = $srcContent.Replace('{TEMPLATEURL}', $templateUrl)

if ($isDirectALGo) {
if ($isFileDirectALGo) {
# If we are using direct AL-Go repo, we need to change the owner to the remplateOwner, the repo names to AL-Go and AL-Go/Actions and the branch to templateBranch
ReplaceOwnerRepoAndBranch -srcContent ([ref]$srcContent) -templateOwner $templateOwner -templateBranch $templateBranch
}

if ($type -eq 'workflow' -and $realSrcFile -ne $srcFile) {
# Apply customizations from indirect template repository
Write-Host "Apply customizations from indirect template repository: $srcFile"
[Yaml]::ApplyCustomizations([ref] $srcContent, $srcFile, $anchors)
}

Fixed Show fixed Hide fixed
$dstFileExists = Test-Path -Path $dstFile -PathType Leaf
if ($unusedALGoSystemFiles -contains $fileName) {
# file is not used by ALGo, remove it if it exists
Expand All @@ -167,6 +236,10 @@
}
}
elseif ($dstFileExists) {
if ($type -eq 'workflow') {
Write-Host "Apply customizations from my repository: $dstFile"
[Yaml]::ApplyCustomizations([ref] $srcContent,$dstFile, $anchors)
}
# file exists, compare and add to $updateFiles if different
$dstContent = Get-ContentLF -Path $dstFile
if ($dstContent -cne $srcContent) {
Expand Down Expand Up @@ -204,7 +277,7 @@

invoke-git status

UpdateSettingsFile -settingsFile (Join-Path ".github" "AL-Go-Settings.json") -updateSettings @{ "templateUrl" = $templateUrl; "templateSha" = $templateSha }
UpdateSettingsFile -settingsFile (Join-Path ".github" "AL-Go-Settings.json") -updateSettings @{ "templateUrl" = $templateUrl; "templateSha" = $templateSha } -additionalSettings $indirectTemplateRepoSettings

# Update the files
# Calculate the release notes, while updating
Expand Down
Loading
Loading