Skip to content

Commit ed4184c

Browse files
aholstrup1Copilot
andauthored
Support running E2E tests locally (#1727)
My previous PR #1717 broke E2E runs from local enlistments. This PR fixes that. When running E2E tests locally we will use whatever account is authenticated on gh cli to run the E2E tests. --------- Co-authored-by: Copilot <[email protected]>
1 parent 3a6322f commit ed4184c

File tree

15 files changed

+71
-53
lines changed

15 files changed

+71
-53
lines changed

Scenarios/Contribute.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ You can also run the end to end tests directly from VS Code, by providing the fo
103103
|$global:SecureLicenseFileUrl| SecureString | Direct download URL to a license file |
104104
|$global:pteTemplate| String | URL for your PTE template (like `freddyk/AL-Go-PTE@main` or `freddydk/AL-Go@main\|Templates/Per Tenant Extension` for using your AL-Go fork directly) |
105105
|$global:appSourceTemplate| String | URL for your PTE template (like `freddyk/AL-Go-AppSource@main` or `freddydk/AL-Go@main\|Templates/AppSource App` for using your AL-Go fork directly) |
106+
|$global:SecureAzureConnectionSecret| SecureString | A JSON string containing the Azure_Credentials set up with [federated credentials](https://github.com/microsoft/AL-Go/blob/main/Scenarios/secrets.md#federated-credential) |
107+
|$global:SecureGitHubPackagesToken| SecureString | A classic PAT with read/write access to GitHub packages in the organization the E2E tests are running in. |
106108

107109
## GitHub Codespaces
108110

e2eTests/Test-AL-Go-Upgrade.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Param(
66
[string] $repoName = [System.IO.Path]::GetFileNameWithoutExtension([System.IO.Path]::GetTempFileName()),
77
[string] $e2eAppId,
88
[string] $e2eAppKey,
9-
[string] $algoauthapp = ($Global:SecureALGOAUTHAPP | Get-PlainText),
9+
[string] $algoauthapp = ($global:SecureALGOAUTHAPP | Get-PlainText),
1010
[string] $contentPath = "pte",
1111
[string] $release = "v2.2",
1212
[string] $template = $global:pteTemplate,

e2eTests/Test-AL-Go.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Param(
66
[string] $repoName = [System.IO.Path]::GetFileNameWithoutExtension([System.IO.Path]::GetTempFileName()),
77
[string] $e2eAppId,
88
[string] $e2eAppKey,
9-
[string] $algoauthapp = ($Global:SecureALGOAUTHAPP | Get-PlainText),
9+
[string] $algoauthapp = ($global:SecureALGOAUTHAPP | Get-PlainText),
1010
[string] $template = $global:pteTemplate,
1111
[string] $adminCenterApiToken = ($global:SecureAdminCenterApiToken | Get-PlainText),
1212
[switch] $multiProject,

e2eTests/e2eTestHelper.psm1

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,21 @@ function SetTokenAndRepository {
3333
invoke-git config --global core.autocrlf false
3434
}
3535

36-
if ($appKey -and $appId) {
36+
if (-not $github) {
37+
# Running locally - Ensure the user is authenticated with the GitHub CLI.
38+
# This is required for local runs to perform GitHub-related operations.
39+
invoke-gh auth status
40+
} elseif ($appKey -and $appId) {
41+
# Running in GitHub Actions
3742
$token = @{ "GitHubAppClientId" = $appId; "PrivateKey" = ($appKey -join '') } | ConvertTo-Json -Compress -Depth 99
43+
} else {
44+
throw "GitHub App ID and Private Key not set. In order to run end to end tests, you need a Secret called E2E_PRIVATE_KEY and a variable called E2E_APP_ID."
3845
}
46+
3947
# Repository isn't created yet so authenticating towards the .github repository
48+
if (-not $github) {
49+
gh auth refresh --scopes repo,admin:org,workflow,write:packages,read:packages,delete:packages,user,delete_repo
50+
}
4051
RefreshToken -token $token -repository "$githubOwner/.github"
4152
}
4253

@@ -49,30 +60,31 @@ function RefreshToken {
4960
[Parameter(Mandatory = $false)]
5061
[switch] $force
5162
)
63+
if ($github) {
64+
if ($token) {
65+
$script:token = $token
66+
}
5267

53-
if ($token) {
54-
$script:token = $token
55-
}
56-
57-
if ($script:token -eq "DefaultToken") {
58-
throw "Token not set."
59-
}
68+
if ($script:token -eq "DefaultToken") {
69+
throw "Token not set."
70+
}
6071

61-
# Check if the last token refresh was more than 30 minutes ago
62-
if ((-not $force) -and ($script:lastTokenRefresh -ne 0) -and (([DateTime]::Now - $script:lastTokenRefresh).TotalMinutes -lt 30)) {
63-
return
64-
}
72+
# Check if the last token refresh was more than 30 minutes ago
73+
if ((-not $force) -and ($script:lastTokenRefresh -ne 0) -and (([DateTime]::Now - $script:lastTokenRefresh).TotalMinutes -lt 30)) {
74+
return
75+
}
6576

66-
Write-Host "Authenticating with GitHub using token"
67-
$realToken = GetAccessToken -token $script:token -repository $repository -repositories @()
68-
$script:lastTokenRefresh = [DateTime]::Now
69-
if ($github) {
77+
Write-Host "Authenticating with GitHub using token"
78+
$realToken = GetAccessToken -token $script:token -repository $repository -repositories @()
79+
$script:lastTokenRefresh = [DateTime]::Now
80+
$ENV:GITHUB_TOKEN = $realToken
81+
$ENV:GH_TOKEN = $realToken
82+
invoke-gh auth setup-git # Use GitHub CLI as a credential helper
83+
} else {
84+
$realToken = gh auth token
7085
$ENV:GITHUB_TOKEN = $realToken
7186
$ENV:GH_TOKEN = $realToken
7287
invoke-gh auth setup-git # Use GitHub CLI as a credential helper
73-
}
74-
else {
75-
$realToken | invoke-gh auth login --with-token
7688
}
7789
}
7890

@@ -513,7 +525,11 @@ function CreateAlGoRepository {
513525
invoke-git commit --allow-empty -m 'init'
514526
invoke-git branch -M $branch
515527
if ($githubOwner) {
516-
invoke-git remote set-url origin "https://$($githubOwner)@github.com/$repository.git"
528+
if ($github) {
529+
invoke-git remote set-url origin "https://$($githubOwner)@github.com/$repository.git"
530+
} else {
531+
invoke-git remote set-url origin "https://github.com/$repository"
532+
}
517533
}
518534
invoke-git push --set-upstream origin $branch
519535
if (!$github) {

e2eTests/scenarios/BCApps/runtest.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Param(
77
[string] $repoName = [System.IO.Path]::GetFileNameWithoutExtension([System.IO.Path]::GetTempFileName()),
88
[string] $e2eAppId,
99
[string] $e2eAppKey,
10-
[string] $algoauthapp = ($Global:SecureALGOAUTHAPP | Get-PlainText),
10+
[string] $algoauthapp = ($global:SecureALGOAUTHAPP | Get-PlainText),
1111
[string] $pteTemplate = $global:pteTemplate,
1212
[string] $appSourceTemplate = $global:appSourceTemplate,
1313
[string] $adminCenterApiToken = ($global:SecureAdminCenterApiToken | Get-PlainText),

e2eTests/scenarios/BuildModes/runtest.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ Param(
77
[string] $repoName = [System.IO.Path]::GetFileNameWithoutExtension([System.IO.Path]::GetTempFileName()),
88
[string] $e2eAppId,
99
[string] $e2eAppKey,
10-
[string] $algoauthapp = ($Global:SecureALGOAUTHAPP | Get-PlainText),
10+
[string] $algoauthapp = ($global:SecureALGOAUTHAPP | Get-PlainText),
1111
[string] $pteTemplate = $global:pteTemplate,
1212
[string] $appSourceTemplate = $global:appSourceTemplate,
1313
[string] $adminCenterApiToken = ($global:SecureAdminCenterApiToken | Get-PlainText),
14-
[string] $azureConnectionSecret,
15-
[string] $githubPackagesToken
14+
[string] $azureConnectionSecret = ($global:SecureAzureConnectionSecret | Get-PlainText),
15+
[string] $githubPackagesToken = ($global:SecureGitHubPackagesToken | Get-PlainText)
1616
)
1717

1818
Write-Host -ForegroundColor Yellow @'

e2eTests/scenarios/FederatedCredentials/runtest.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ Param(
77
[string] $repoName = [System.IO.Path]::GetFileNameWithoutExtension([System.IO.Path]::GetTempFileName()),
88
[string] $e2eAppId,
99
[string] $e2eAppKey,
10-
[string] $algoauthapp = ($Global:SecureALGOAUTHAPP | Get-PlainText),
10+
[string] $algoauthapp = ($global:SecureALGOAUTHAPP | Get-PlainText),
1111
[string] $pteTemplate = $global:pteTemplate,
1212
[string] $appSourceTemplate = $global:appSourceTemplate,
1313
[string] $adminCenterApiToken = ($global:SecureAdminCenterApiToken | Get-PlainText),
14-
[string] $azureConnectionSecret,
15-
[string] $githubPackagesToken
14+
[string] $azureConnectionSecret = ($global:SecureAzureConnectionSecret | Get-PlainText),
15+
[string] $githubPackagesToken = ($global:SecureGitHubPackagesToken | Get-PlainText)
1616
)
1717

1818
Write-Host -ForegroundColor Yellow @'

e2eTests/scenarios/GitHubPackages/runtest.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ Param(
77
[string] $repoName = [System.IO.Path]::GetFileNameWithoutExtension([System.IO.Path]::GetTempFileName()),
88
[string] $e2eAppId,
99
[string] $e2eAppKey,
10-
[string] $algoauthapp = ($Global:SecureALGOAUTHAPP | Get-PlainText),
10+
[string] $algoauthapp = ($global:SecureALGOAUTHAPP | Get-PlainText),
1111
[string] $pteTemplate = $global:pteTemplate,
1212
[string] $appSourceTemplate = $global:appSourceTemplate,
1313
[string] $adminCenterApiToken = ($global:SecureAdminCenterApiToken | Get-PlainText),
14-
[string] $azureConnectionSecret,
15-
[string] $githubPackagesToken
14+
[string] $azureConnectionSecret = ($global:SecureAzureConnectionSecret | Get-PlainText),
15+
[string] $githubPackagesToken = ($global:SecureGitHubPackagesToken | Get-PlainText)
1616
)
1717

1818
Write-Host -ForegroundColor Yellow @'

e2eTests/scenarios/IncludeDependencies/runtest.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ Param(
77
[string] $repoName = [System.IO.Path]::GetFileNameWithoutExtension([System.IO.Path]::GetTempFileName()),
88
[string] $e2eAppId,
99
[string] $e2eAppKey,
10-
[string] $algoauthapp = ($Global:SecureALGOAUTHAPP | Get-PlainText),
10+
[string] $algoauthapp = ($global:SecureALGOAUTHAPP | Get-PlainText),
1111
[string] $pteTemplate = $global:pteTemplate,
1212
[string] $appSourceTemplate = $global:appSourceTemplate,
1313
[string] $adminCenterApiToken = ($global:SecureAdminCenterApiToken | Get-PlainText),
14-
[string] $azureConnectionSecret,
15-
[string] $githubPackagesToken
14+
[string] $azureConnectionSecret = ($global:SecureAzureConnectionSecret | Get-PlainText),
15+
[string] $githubPackagesToken = ($global:SecureGitHubPackagesToken | Get-PlainText)
1616
)
1717

1818
Write-Host -ForegroundColor Yellow @'

e2eTests/scenarios/IncrementalBuilds/runtest.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ Param(
77
[string] $repoName = [System.IO.Path]::GetFileNameWithoutExtension([System.IO.Path]::GetTempFileName()),
88
[string] $e2eAppId,
99
[string] $e2eAppKey,
10-
[string] $algoauthapp = ($Global:SecureALGOAUTHAPP | Get-PlainText),
10+
[string] $algoauthapp = ($global:SecureALGOAUTHAPP | Get-PlainText),
1111
[string] $pteTemplate = $global:pteTemplate,
1212
[string] $appSourceTemplate = $global:appSourceTemplate,
1313
[string] $adminCenterApiToken = ($global:SecureAdminCenterApiToken | Get-PlainText),
14-
[string] $azureConnectionSecret,
15-
[string] $githubPackagesToken
14+
[string] $azureConnectionSecret = ($global:SecureAzureConnectionSecret | Get-PlainText),
15+
[string] $githubPackagesToken = ($global:SecureGitHubPackagesToken | Get-PlainText)
1616
)
1717

1818
Write-Host -ForegroundColor Yellow @'

0 commit comments

Comments
 (0)