Skip to content

Commit

Permalink
Substitution pattern problem (#655)
Browse files Browse the repository at this point in the history
When using regex and the substitution pattern has replacements starting
with a number (branch, repo, SHA, ...) regex will fail.
This lead to wrong deployment to preview ealier.

---------

Co-authored-by: freddydk <freddydk@users.noreply.github.com>
  • Loading branch information
freddydk and freddydk authored Aug 11, 2023
1 parent 7efe5a3 commit 2fe6957
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Actions/CheckForUpdates/CheckForUpdates.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,13 @@ try {

# Replace URL's to actions repository first
$regex = "^(.*)https:\/\/raw\.githubusercontent\.com\/microsoft\/AL-Go-Actions\/$originalBranch(.*)$"
$replace = "`$1https://raw.githubusercontent.com/$($templateOwner)/AL-Go/$($templateBranch)/Actions`$2"
$replace = "`${1}https://raw.githubusercontent.com/$($templateOwner)/AL-Go/$($templateBranch)/Actions`${2}"
$lines = $lines | ForEach-Object { $_ -replace $regex, $replace }

# Replace the owner and repo names in the workflow
"actionsRepo","perTenantExtensionRepo","appSourceAppRepo" | ForEach-Object {
$regex = "^(.*)$($originalOwnerAndRepo."$_")(.*)$originalBranch(.*)$"
$replace = "`$1$($templateOwner)/$($templateRepos."$_")`$2$($templateBranch)`$3"
$replace = "`${1}$($templateOwner)/$($templateRepos."$_")`${2}$($templateBranch)`${3}"
$lines = $lines | ForEach-Object { $_ -replace $regex, $replace }
}
$srcContent = $lines -join "`n"
Expand Down
4 changes: 2 additions & 2 deletions Internal/Collect.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ try {
$lines = ([string](Get-ContentLF -path $dstFile)).Split("`n")
"actionsRepo", "perTenantExtensionRepo", "appSourceAppRepo" | ForEach-Object {
$regex = "^(.*)$($config.githubOwner)\/$($config."$_")(.*)$($config.branch)(.*)$"
$replace = "`$1$($originalOwnerAndRepo."$_")`$2$originalBranch`$3"
$replace = "`${1}$($originalOwnerAndRepo."$_")`${2}$originalBranch`${3}"
$lines = $lines | ForEach-Object { $_ -replace $regex, $replace }
}
if ($_.Name -eq "AL-Go-Helper.ps1") {
$lines = $lines | ForEach-Object { $_ -replace '^(\s*)\$defaultBcContainerHelperVersion(\s*)=(\s*)"(.*)"(.*)$', "`$1`$defaultBcContainerHelperVersion`$2=`$3""""`$5" }
$lines = $lines | ForEach-Object { $_ -replace '^(\s*)\$defaultBcContainerHelperVersion(\s*)=(\s*)"(.*)"(.*)$', "`${1}`$defaultBcContainerHelperVersion`${2}=`${3}""""`${5}" }
}
[System.IO.File]::WriteAllText($srcFile, "$($lines -join "`n")`n")
}
Expand Down
6 changes: 3 additions & 3 deletions Internal/Deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,18 @@ try {
# When deploying to a release branch, these URLs are replaced by the following code
if ($config.branch -eq 'preview') {
$regex = "^(.*)https:\/\/raw\.githubusercontent\.com\/microsoft\/AL-Go-Actions\/$originalBranch(.*)$"
$replace = "`$1https://raw.githubusercontent.com/$srcOwnerAndRepo/$($srcSHA)/Actions`$2"
$replace = "`${1}https://raw.githubusercontent.com/$srcOwnerAndRepo/$($srcSHA)/Actions`${2}"
$lines = $lines | ForEach-Object { $_ -replace $regex, $replace }
}

# Replace the owner and repo names in the workflow
$regex = "^(.*)$($originalOwnerAndRepo."$_")(.*)$originalBranch(.*)$"
$replace = "`$1$useRepo`$2$($useBranch)`$3"
$replace = "`${1}$useRepo`${2}$($useBranch)`${3}"
$lines = $lines | ForEach-Object { $_ -replace $regex, $replace }
}
if ($_.Name -eq "AL-Go-Helper.ps1" -and ($config.ContainsKey("defaultBcContainerHelperVersion") -and $config.defaultBcContainerHelperVersion)) {
# replace defaultBcContainerHelperVersion (even if a version is set)
$lines = $lines | ForEach-Object { $_ -replace '^(\s*)\$defaultBcContainerHelperVersion(\s*)=(\s*)"(.*)" # (.*)$', "`$1`$defaultBcContainerHelperVersion`$2=`$3""$($config.defaultBcContainerHelperVersion)"" # `$5" }
$lines = $lines | ForEach-Object { $_ -replace '^(\s*)\$defaultBcContainerHelperVersion(\s*)=(\s*)"(.*)" # (.*)$', "`${1}`$defaultBcContainerHelperVersion`${2}=`${3}""$($config.defaultBcContainerHelperVersion)"" # `${5}" }
}
[System.IO.File]::WriteAllText($dstFile, "$($lines -join "`n")`n")
}
Expand Down
4 changes: 2 additions & 2 deletions e2eTests/e2eTestHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,12 @@ function CreateAlGoRepository {

# Replace URL's to actions repository first
$regex = "^(.*)https:\/\/raw\.githubusercontent\.com\/microsoft\/AL-Go-Actions\/main(.*)$"
$replace = "`$1https://raw.githubusercontent.com/$($templateOwner)/AL-Go/$($templateBranch)/Actions`$2"
$replace = "`${1}https://raw.githubusercontent.com/$($templateOwner)/AL-Go/$($templateBranch)/Actions`${2}"
$lines = $lines | ForEach-Object { $_ -replace $regex, $replace }

# Replace AL-Go-Actions references
$regex = "^(.*)microsoft\/AL-Go-Actions(.*)main(.*)$"
$replace = "`$1$($templateOwner)/AL-Go/Actions`$2$($templateBranch)`$3"
$replace = "`${1}$($templateOwner)/AL-Go/Actions`${2}$($templateBranch)`${3}"
$lines = $lines | ForEach-Object { $_ -replace $regex, $replace }

$content = "$($lines -join "`n")`n"
Expand Down

0 comments on commit 2fe6957

Please sign in to comment.