Skip to content

Commit

Permalink
use GhTokenWorkflow in end 2 end (#1156)
Browse files Browse the repository at this point in the history
Co-authored-by: freddydk <freddydk@users.noreply.github.com>
  • Loading branch information
freddydk and freddydk authored Aug 5, 2024
1 parent 381a1e2 commit 8f5985d
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 15 deletions.
30 changes: 21 additions & 9 deletions e2eTests/Test-AL-Go.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,18 @@ if ($appSourceApp) {
$runs++
}

SetRepositorySecret -repository $repository -name 'GHTOKENWORKFLOW' -value $token

# Add Existing Test App
RunAddExistingAppOrTestApp @project1Param -url $sampleTestApp1 -wait -branch $branch | Out-Null
RunAddExistingAppOrTestApp @project1Param -url $sampleTestApp1 -wait -branch $branch -useGhTokenWorkflow | Out-Null
$runs++

# Merge and run CI/CD + Tests
MergePRandPull -branch $branch | Out-Null
# PR Build
CancelAllWorkflows -repository $repository -branch $branch
$runs++

# Wait for CI/CD to finish
$run = RunCICD -wait -branch $branch
# Merge and run CI/CD
$run = MergePRandPull -branch $branch -wait
$runs++

if ($useCompilerFolder) {
Expand All @@ -146,7 +148,7 @@ TestNumberOfRuns -expectedNumberOfRuns $runs -repository $repository
Test-ArtifactsFromRun -runid $run.id -expectedArtifacts @{"Apps"=2;"TestApps"=1} -expectedNumberOfTests $expectedNumberOfTests -folder 'artifacts' -repoVersion '1.0' -appVersion ''

# Create Release
RunCreateRelease -appVersion "1.0.$($runs-2).0" -name 'v1.0' -tag '1.0.0' -wait -branch $branch | Out-Null
RunCreateRelease -appVersion "1.0.$($runs-3).0" -name 'v1.0' -tag '1.0.0' -wait -branch $branch | Out-Null
$runs++

# Create New App
Expand Down Expand Up @@ -190,8 +192,14 @@ if ($adminCenterApiToken -and -not $multiProject) {
}

# Increment version number on one project
RunIncrementVersionNumber @p2ProjectsParam -versionNumber 2.1 -wait -branch $branch | Out-Null
RunIncrementVersionNumber @p2ProjectsParam -versionNumber 2.1 -wait -branch $branch -useGhTokenWorkflow | Out-Null
$runs++

# Wait for PR build to succeed
WaitAllWorkflows -repository $repository -top 1
$runs++

# Merge and run CI/CD + Tests
$run = MergePRandPull -branch $branch -wait
$runs++
if ($multiProject) {
Expand Down Expand Up @@ -225,11 +233,15 @@ Test-ArtifactsFromRun -runid $run.id -expectedArtifacts @{"Apps"=3;"TestApps"=2}

# Update AL-Go System Files
$repoSettings = Get-Content ".github\AL-Go-Settings.json" -Encoding UTF8 | ConvertFrom-Json
SetRepositorySecret -repository $repository -name 'GHTOKENWORKFLOW' -value $token
RunUpdateAlGoSystemFiles -templateUrl $repoSettings.templateUrl -wait -repository $repository -branch $branch | Out-Null
$runs++

# PR Build
$runs++

# Merge and run CI/CD + Tests
MergePRandPull -branch $branch -wait | Out-Null
$runs += 2
$runs++
if (!(Test-Path "$($project1Folder).AL-Go\*.ps1")) { throw "Local PowerShell scripts in the .AL-Go folder was not updated by Update AL-Go System Files" }
if (!(Test-Path ".github\workflows\AddExistingAppOrTestApp.yaml")) { throw "AddExistingAppOrTestApp.yaml was not updated by Update AL-Go System Files" }

Expand Down
2 changes: 2 additions & 0 deletions e2eTests/Workflows/RunAddExistingAppOrTestApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[string] $project,
[string] $url,
[switch] $directCommit,
[switch] $useGhTokenWorkflow,
[switch] $wait,
[string] $repository,
[string] $branch = "main"
Expand All @@ -13,6 +14,7 @@
"project" = $project
"url" = $url
"directCommit" = @("true","false")[!$directCommit]
"useGhTokenWorkflow" = @("true","false")[!$useGhTokenWorkflow]
}
RunWorkflow -name $workflowName -parameters $parameters -wait:$wait -branch $branch -repository $repository
}
2 changes: 2 additions & 0 deletions e2eTests/Workflows/RunCreateApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[string] $publisher,
[string] $idrange,
[switch] $directCommit,
[switch] $useGhTokenWorkflow,
[switch] $wait,
[string] $repository,
[string] $branch = "main"
Expand All @@ -17,6 +18,7 @@
"publisher" = $publisher
"idrange" = $idrange
"directCommit" = @("true","false")[!$directCommit]
"useGhTokenWorkflow" = @("true","false")[!$useGhTokenWorkflow]
}
RunWorkflow -name $workflowName -parameters $parameters -wait:$wait -branch $branch -repository $repository
}
2 changes: 2 additions & 0 deletions e2eTests/Workflows/RunCreateOnlineDevelopmentEnvironment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[string] $environmentName,
[switch] $reUseExistingEnvironment,
[switch] $directCommit,
[switch] $useGhTokenWorkflow,
[switch] $wait,
[string] $repository,
[string] $branch = "main"
Expand All @@ -13,6 +14,7 @@
"environmentName" = $environmentName
"reUseExistingEnvironment" = @("true","false")[!$reUseExistingEnvironment]
"directCommit" = @("true","false")[!$directCommit]
"useGhTokenWorkflow" = @("true","false")[!$useGhTokenWorkflow]
}
RunWorkflow -name $workflowName -parameters $parameters -wait:$wait -branch $branch -repository $repository
}
2 changes: 2 additions & 0 deletions e2eTests/Workflows/RunCreateRelease.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[switch] $createReleaseBranch,
[string] $updateVersionNumber = '',
[switch] $directCommit,
[switch] $useGhTokenWorkflow,
[switch] $wait,
[string] $repository,
[string] $branch = "main"
Expand All @@ -23,6 +24,7 @@
"createReleaseBranch" = @("true","false")[!$createReleaseBranch]
"updateVersionNumber" = $updateVersionNumber
"directCommit" = @("true","false")[!$directCommit]
"useGhTokenWorkflow" = @("true","false")[!$useGhTokenWorkflow]
}
RunWorkflow -name $workflowName -parameters $parameters -wait:$wait -branch $branch -repository $repository
}
2 changes: 2 additions & 0 deletions e2eTests/Workflows/RunCreateTestApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[string] $publisher,
[string] $idrange,
[switch] $directCommit,
[switch] $useGhTokenWorkflow,
[switch] $wait,
[string] $repository,
[string] $branch = "main"
Expand All @@ -17,6 +18,7 @@
"publisher" = $publisher
"idrange" = $idrange
"directCommit" = @("true","false")[!$directCommit]
"useGhTokenWorkflow" = @("true","false")[!$useGhTokenWorkflow]
}
RunWorkflow -name $workflowName -parameters $parameters -wait:$wait -branch $branch -repository $repository
}
2 changes: 2 additions & 0 deletions e2eTests/Workflows/RunIncrementVersionNumber.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[string] $projects,
[string] $versionNumber,
[switch] $directCommit,
[switch] $useGhTokenWorkflow,
[switch] $wait,
[string] $repository,
[string] $branch = "main"
Expand All @@ -13,6 +14,7 @@
"projects" = $projects
"versionNumber" = $versionNumber
"directCommit" = @("true","false")[!$directCommit]
"useGhTokenWorkflow" = @("true","false")[!$useGhTokenWorkflow]
}
RunWorkflow -name $workflowName -parameters $parameters -wait:$wait -branch $branch -repository $repository
}
14 changes: 8 additions & 6 deletions e2eTests/e2eTestHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,15 @@ function WaitAllWorkflows {
Param(
[string] $repository,
[switch] $noDelay,
[switch] $noError
[switch] $noError,
[int] $top = 999
)
if (-not $noDelay.IsPresent) {
Start-Sleep -Seconds 60
}
$runs = gh api /repos/$repository/actions/runs | ConvertFrom-Json
foreach($run in $runs.workflow_runs) {
$workflowRuns = $runs.workflow_runs | Select-Object -First $top
foreach($run in $workflowRuns) {
WaitWorkflow -repository $repository -runid $run.id -noDelay -noError:$noError
}
}
Expand All @@ -268,7 +270,7 @@ function WaitWorkflow {
$status = ""
do {
if ($delay) {
Start-Sleep -Seconds 120
Start-Sleep -Seconds 60
}
WaitForRateLimit -headers $headers
$url = "https://api.github.com/repos/$repository/actions/runs/$runid"
Expand All @@ -283,7 +285,7 @@ function WaitWorkflow {
} while ($run.status -eq "queued" -or $run.status -eq "in_progress")
Write-Host
Write-Host $run.conclusion
if ($run.conclusion -ne "Success") {
if ($run.conclusion -ne "Success" -and $run.conclusion -ne "cancelled") {
if (-not $noError.IsPresent) { throw "Workflow $($run.name), conclusion $($run.conclusion), url = $($run.html_url)" }
}
}
Expand Down Expand Up @@ -466,10 +468,10 @@ function CreateAlGoRepository {
$content = Get-ContentLF -Path $_.FullName
$srcPattern = "runs-on: [ windows-latest ]`n"
$replacePattern = "runs-on: [ $runson ]`n"
$content = $content.Replace($srcPattern, $replacePattern)
$content = "$content`n".Replace($srcPattern, $replacePattern).TrimEnd("`n")
$srcPattern = "shell: powershell`n"
$replacePattern = "shell: $shell`n"
$content = $content.Replace($srcPattern, $replacePattern)
$content = "$content`n".Replace($srcPattern, $replacePattern).TrimEnd("`n")
[System.IO.File]::WriteAllText($_.FullName, $content)
}
}
Expand Down

0 comments on commit 8f5985d

Please sign in to comment.