-
Notifications
You must be signed in to change notification settings - Fork 181
Refactor FederatedCredentials e2e test to use stable repository with config-based disabling #2104
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
base: main
Are you sure you want to change the base?
Changes from all commits
8dfba0e
5d230ac
0cccc74
817d4a8
3caaa49
2309402
5664fcb
094ce51
1a02db0
626a791
6b92fde
ab19c26
44d1b6c
e1e4509
755542e
abe45b6
0c3ffe4
b82ea64
3dc0c90
1694b3a
28516a8
348e87f
204f17b
b8d28e8
c1c8df4
bf74eae
aecb2c2
054ed9f
51f0c57
0aeecb3
fc1714d
b8a2625
13bcc5e
4c8d486
9c9aa2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [ | ||
| { | ||
| "scenario": "FederatedCredentials", | ||
| "reason": "Azure resource migration work in progress" | ||
| } | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,18 +29,23 @@ Write-Host -ForegroundColor Yellow @' | |
| # This test uses the bcsamples-bingmaps.appsource repository and will deliver a new build of the app to AppSource. | ||
| # The bcsamples-bingmaps.appsource repository is setup to use an Azure KeyVault for secrets and app signing. | ||
| # | ||
| # During the test, the bcsamples-bingmaps.appsource repository will be copied to a new repository called tmp-bingmaps.appsource. | ||
| # tmp-bingmaps.appsource has access to the same Azure KeyVault as bcsamples-bingmaps.appsource using federated credentials. | ||
| # The test requires a stable temporary repository called e2e-bingmaps.appsource that must be manually created | ||
| # with federated credentials configured before running this test. | ||
| # This is required because federated credentials no longer work with repository name-based matching, | ||
| # so the repository must remain stable to maintain the federated credential configuration. | ||
| # e2e-bingmaps.appsource has access to the same Azure KeyVault as bcsamples-bingmaps.appsource using federated credentials. | ||
| # The bcSamples-bingmaps.appsource repository is setup for continuous delivery to AppSource | ||
| # tmp-bingmaps.appsource also has access to the Entra ID app registration for delivering to AppSource using federated credentials. | ||
| # e2e-bingmaps.appsource also has access to the Entra ID app registration for delivering to AppSource using federated credentials. | ||
| # This test will deliver another build of the latest app version already delivered to AppSource (without go-live) | ||
| # | ||
| # This test tests the following scenario: | ||
| # | ||
| # - Create a new repository called tmp-bingmaps.appsource (based on bcsamples-bingmaps.appsource) | ||
| # - Update AL-Go System Files in branch main in tmp-bingmaps.appsource | ||
| # - Update version numbers in app.json in tmp-bingmaps.appsource in order to not be lower than the version number in AppSource (and not be higher than the next version from bcsamples-bingmaps.appsource) | ||
| # - Wait for CI/CD in branch main in repository tmp-bingmaps.appsource | ||
| # - Verify that the repository e2e-bingmaps.appsource exists (error out if not) | ||
| # - Reset the repository to match bcsamples-bingmaps.appsource for deterministic state | ||
| # - Clean up old workflow runs to ensure proper workflow tracking | ||
| # - Update AL-Go System Files in branch main in e2e-bingmaps.appsource | ||
| # - Update version numbers in app.json in e2e-bingmaps.appsource in order to not be lower than the version number in AppSource (and not be higher than the next version from bcsamples-bingmaps.appsource) | ||
| # - Wait for CI/CD in branch main in repository e2e-bingmaps.appsource | ||
| # - Check that artifacts are created and signed | ||
| # - Check that the app is delivered to AppSource | ||
| '@ | ||
|
|
@@ -55,40 +60,115 @@ if ($linux) { | |
| Remove-Module e2eTestHelper -ErrorAction SilentlyContinue | ||
| Import-Module (Join-Path $PSScriptRoot "..\..\e2eTestHelper.psm1") -DisableNameChecking | ||
|
|
||
| $repository = "$githubOwner/tmp-bingmaps.appsource" | ||
| $repository = "$githubOwner/e2e-bingmaps.appsource" | ||
| $template = "https://github.com/$appSourceTemplate" | ||
| $sourceRepository = 'microsoft/bcsamples-bingmaps.appsource' # E2E test will create a copy of this repository | ||
|
|
||
| # Create temp repository from sourceRepository | ||
| # Setup authentication and repository | ||
| SetTokenAndRepository -github:$github -githubOwner $githubOwner -appId $e2eAppId -appKey $e2eAppKey -repository $repository | ||
|
|
||
| gh api repos/$repository --method HEAD | ||
| if ($LASTEXITCODE -eq 0) { | ||
| Write-Host "Repository $repository already exists. Deleting it." | ||
| gh repo delete $repository --yes | Out-Host | ||
| Start-Sleep -Seconds 30 | ||
| # Check if the repository already exists | ||
| # This repository must exist with federated credentials already configured | ||
| try { | ||
| invoke-gh api repos/$repository --method HEAD -silent | Out-Null | ||
| } | ||
| catch { | ||
| throw "Repository $repository does not exist. The repository must be created manually with federated credentials configured before running this test." | ||
| } | ||
|
|
||
| # Repository exists - reuse it and reset to source state | ||
| # This is required because federated credentials no longer work with repository name-based matching, | ||
| # so the repository must remain stable across test runs | ||
| Write-Host "Repository $repository exists. Reusing and resetting to match source." | ||
|
|
||
| # Reset the repository to match the source repository | ||
| ResetRepositoryToSource -repository $repository -sourceRepository $sourceRepository -branch 'main' | ||
|
|
||
| CreateAlGoRepository ` | ||
| -github:$github ` | ||
| -template "https://github.com/$sourceRepository" ` | ||
| -repository $repository ` | ||
| -addRepoSettings @{"ghTokenWorkflowSecretName" = "e2eghTokenWorkflow" } | ||
| # Clean up workflow runs to ensure proper workflow tracking | ||
| CleanupWorkflowRuns -repository $repository | ||
|
|
||
| # Always set/update secrets (they may have changed or repo may have been reset) | ||
| SetRepositorySecret -repository $repository -name 'Azure_Credentials' -value $azureCredentials | ||
|
|
||
| # Capture previous workflow run IDs before making any changes | ||
| # This follows the established pattern from CommitAndPush function | ||
| Write-Host "Capturing previous workflow runs..." | ||
| $previousRuns = invoke-gh api /repos/$repository/actions/runs -silent -returnValue | ConvertFrom-Json | ||
| $previousRunIds = $previousRuns.workflow_runs | Where-Object { $_.event -eq 'push' } | Select-Object -ExpandProperty id | ||
| if ($previousRunIds) { | ||
| Write-Host "Previous run IDs: $($previousRunIds -join ', ')" | ||
| } | ||
| else { | ||
| Write-Host "No previous runs found" | ||
| } | ||
mazhelez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Re-apply the custom repository settings that were lost during reset | ||
| $tempPath = [System.IO.Path]::GetTempPath() | ||
| $repoPath = Join-Path $tempPath ([System.Guid]::NewGuid().ToString()) | ||
| New-Item $repoPath -ItemType Directory | Out-Null | ||
| Push-Location $repoPath | ||
| try { | ||
| Write-Host "Re-applying repository settings..." | ||
| invoke-gh repo clone $repository . | ||
| $repoSettingsFile = ".github\AL-Go-Settings.json" | ||
| if (Test-Path $repoSettingsFile) { | ||
| Add-PropertiesToJsonFile -path $repoSettingsFile -properties @{"ghTokenWorkflowSecretName" = "e2eghTokenWorkflow"} | ||
| invoke-git add $repoSettingsFile | ||
| invoke-git commit -m "Update repository settings for test" --quiet | ||
| invoke-git push --quiet | ||
| Write-Host "Settings push completed. This will trigger a CI/CD workflow run." | ||
| } | ||
| else { | ||
| Write-Host "Warning: .github\AL-Go-Settings.json not found after cloning. Settings may not be applied correctly." | ||
| } | ||
| } | ||
| finally { | ||
| Pop-Location | ||
| Remove-Item -Path $repoPath -Force -Recurse -ErrorAction SilentlyContinue | ||
| } | ||
mazhelez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # Upgrade AL-Go System Files to test version | ||
| RunUpdateAlGoSystemFiles -directCommit -wait -templateUrl $template -repository $repository | Out-Null | ||
| RunUpdateAlGoSystemFiles -directCommit -wait -repository $repository | Out-Null | ||
|
|
||
| # Wait for CI/CD workflow to start (triggered by Update AL-Go System Files) | ||
| # This follows the established pattern from CommitAndPush: poll until a new run appears | ||
| Write-Host "Waiting for CI/CD workflow to start (triggered by Update AL-Go System Files push)..." | ||
|
|
||
| # Poll for new workflow run that wasn't in the previous list | ||
| $maxAttempts = 60 # 10 minutes maximum wait (60 * 10 seconds) | ||
| $attempts = 0 | ||
| $run = $null | ||
|
|
||
| while ($attempts -lt $maxAttempts) { | ||
| Start-Sleep -Seconds 10 | ||
| $attempts++ | ||
|
|
||
| $currentRuns = invoke-gh api /repos/$repository/actions/runs -silent -returnValue | ConvertFrom-Json | ||
| # Find new push workflow runs that weren't in our previous list | ||
| $newRuns = $currentRuns.workflow_runs | Where-Object { | ||
| $_.event -eq 'push' -and $previousRunIds -notcontains $_.id | ||
| } | ||
|
|
||
| if ($newRuns) { | ||
| # Get the most recent new run (first one, since API returns newest first) | ||
| $run = $newRuns | Select-Object -First 1 | ||
| Write-Host "Found new CI/CD workflow run: $($run.id) (created at $($run.created_at))" | ||
| break | ||
| } | ||
|
|
||
| Write-Host "Waiting for new CI/CD workflow run to appear (attempt $attempts/$maxAttempts)..." | ||
| } | ||
|
Comment on lines
+105
to
+160
|
||
|
|
||
| if (-not $run) { | ||
| throw "Error: Timeout waiting for CI/CD workflow run to start after Update AL-Go System Files completed." | ||
| } | ||
|
|
||
mazhelez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Wait for CI/CD to complete | ||
| Start-Sleep -Seconds 60 | ||
| $runs = invoke-gh api /repos/$repository/actions/runs -silent -returnValue | ConvertFrom-Json | ||
| $run = $runs.workflow_runs | Select-Object -First 1 | ||
| Write-Host "Waiting for CI/CD workflow run $($run.id) to complete..." | ||
| WaitWorkflow -repository $repository -runid $run.id -noError | ||
|
|
||
| # The CI/CD workflow should fail because the version number of the app in thie repository is lower than the version number in AppSource | ||
| # The CI/CD workflow should fail because the version number of the app in the repository is lower than the version number in AppSource | ||
|
||
| # Reason being that major.minor from the original bcsamples-bingmaps.appsource is the same and the build number in the newly created repository is lower than the one in AppSource | ||
| # This error is expected we will grab the version number from AppSource, add one to revision number (by switching to versioningstrategy 3 in the tmp repo) and use it in the next run | ||
| # This error is expected we will grab the version number from AppSource, add one to revision number (by switching to versioningstrategy 3 in the e2e-bingmaps.appsource repo) and use it in the next run | ||
| $MatchArr = Test-LogContainsFromRun -repository $repository -runid $run.id -jobName 'Deliver to AppSource' -stepName 'Deliver' -expectedText '(?m)^.*The new version number \((\d+(?:\.\d+){3})\) is lower than the existing version number \((\d+(?:\.\d+){3})\) in Partner Center.*$' -isRegEx | ||
| $appSourceVersion = [System.Version]$MatchArr[2] | ||
| $newVersion = [System.Version]::new($appSourceVersion.Major, $appSourceVersion.Minor, $appSourceVersion.Build, 0) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.