Skip to content

Commit

Permalink
2 secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
freddydk committed Jan 14, 2025
1 parent a788755 commit 632e1ad
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 69 deletions.
20 changes: 12 additions & 8 deletions .github/workflows/E2E.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ jobs:
Write-Host "::Error::In order to run end to end tests, you need a Secret called E2EPAT containing a valid Personal Access Token with the following permissions: admin:org, delete_repo, repo, workflow, packages:write"
$err = $true
}
if ('${{ Secrets.ALGOAUTHAPP }}' -eq '') {
Write-Host "::Error::In order to run end to end tests, you need a Secret called ALGOAUTHAPP containing a json structure as described in this app: https://github.com/organizations/BusinessCentralApps/settings/apps/al-go-authentication"
$err = $true
}
if ('${{ Secrets.adminCenterApiCredentials }}' -eq '') {
Write-Host "::Error::In order to run end to end tests, you need a Secret called adminCenterApiCredentials containing API access credentials for BC Admin Center"
$err = $true
Expand Down Expand Up @@ -113,7 +117,7 @@ jobs:
id: setup
run: |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
. (Join-Path "." "e2eTests/SetupRepositories.ps1") -githubOwner '${{ needs.Check.outputs.githubowner }}' -token '${{ Secrets.E2EPAT }}' -bcContainerHelperVersion '${{ github.event.inputs.bcContainerHelperVersion }}'
. (Join-Path "." "e2eTests/SetupRepositories.ps1") -githubOwner '${{ needs.Check.outputs.githubowner }}' -e2epat '${{ Secrets.E2EPAT }}' -token '${{ Secrets.ALGOAUTHAPP }}' -bcContainerHelperVersion '${{ github.event.inputs.bcContainerHelperVersion }}'
Analyze:
runs-on: [ ubuntu-latest ]
Expand All @@ -139,7 +143,7 @@ jobs:
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
$modulePath = Join-Path "." "e2eTests\e2eTestHelper.psm1" -resolve
Import-Module $modulePath -DisableNameChecking
SetTokenAndRepository -github -githubOwner '${{ needs.Check.outputs.githubowner }}' -token '${{ Secrets.E2EPAT }}' -repository "microsoft/AL-Go"
SetTokenAndRepository -github -githubOwner '${{ needs.Check.outputs.githubowner }}' -e2epat '${{ Secrets.E2EPAT }}' -token '${{ Secrets.ALGOAUTHAPP }}' -repository "microsoft/AL-Go"
$maxParallel = [int]'${{ needs.Check.outputs.maxParallel }}'
$publicTestruns = @{
Expand Down Expand Up @@ -226,7 +230,7 @@ jobs:
- name: Run test on Windows
run: |
try {
. (Join-Path "." "e2eTests/scenarios/${{ matrix.scenario }}/runtest.ps1") -github -githubOwner '${{ needs.Check.outputs.githubowner }}' -repoName '${{ steps.calculateParams.outputs.repoName }}' -token '${{ Secrets.E2EPAT }}' -pteTemplate '${{ needs.Check.outputs.githubowner }}/${{ needs.SetupRepositories.outputs.perTenantExtensionRepo }}' -appSourceTemplate '${{ needs.Check.outputs.githubowner }}/${{ needs.SetupRepositories.outputs.appSourceAppRepo }}' -adminCenterApiToken '${{ Secrets.adminCenterApiCredentials }}'
. (Join-Path "." "e2eTests/scenarios/${{ matrix.scenario }}/runtest.ps1") -github -githubOwner '${{ needs.Check.outputs.githubowner }}' -repoName '${{ steps.calculateParams.outputs.repoName }}' -e2epat '${{ Secrets.E2EPAT }}' -token '${{ Secrets.ALGOAUTHAPP }}' -pteTemplate '${{ needs.Check.outputs.githubowner }}/${{ needs.SetupRepositories.outputs.perTenantExtensionRepo }}' -appSourceTemplate '${{ needs.Check.outputs.githubowner }}/${{ needs.SetupRepositories.outputs.appSourceAppRepo }}' -adminCenterApiToken '${{ Secrets.adminCenterApiCredentials }}'
}
catch {
Write-Host $_.Exception.Message
Expand Down Expand Up @@ -262,7 +266,7 @@ jobs:
- name: Run tests
run: |
try {
. (Join-Path "." "e2eTests/scenarios/${{ matrix.scenario }}/runtest.ps1") -github -linux -githubOwner '${{ needs.Check.outputs.githubowner }}' -repoName '${{ steps.calculateParams.outputs.repoName }}' -token '${{ Secrets.E2EPAT }}' -pteTemplate '${{ needs.Check.outputs.githubowner }}/${{ needs.SetupRepositories.outputs.perTenantExtensionRepo }}' -appSourceTemplate '${{ needs.Check.outputs.githubowner }}/${{ needs.SetupRepositories.outputs.appSourceAppRepo }}' -adminCenterApiToken '${{ Secrets.adminCenterApiCredentials }}'
. (Join-Path "." "e2eTests/scenarios/${{ matrix.scenario }}/runtest.ps1") -github -linux -githubOwner '${{ needs.Check.outputs.githubowner }}' -repoName '${{ steps.calculateParams.outputs.repoName }}' -e2epat '${{ Secrets.E2EPAT }}' -token '${{ Secrets.ALGOAUTHAPP }}' -pteTemplate '${{ needs.Check.outputs.githubowner }}/${{ needs.SetupRepositories.outputs.perTenantExtensionRepo }}' -appSourceTemplate '${{ needs.Check.outputs.githubowner }}/${{ needs.SetupRepositories.outputs.appSourceAppRepo }}' -adminCenterApiToken '${{ Secrets.adminCenterApiCredentials }}'
}
catch {
Write-Host $_.Exception.Message
Expand Down Expand Up @@ -310,7 +314,7 @@ jobs:
- name: Run tests
run: |
try {
. (Join-Path "." "e2eTests/Test-AL-Go.ps1") -github -githubOwner '${{ needs.Check.outputs.githubowner }}' -repoName ${{ steps.calculateParams.outputs.repoName }} -token '${{ Secrets.E2EPAT }}' -template ${{ steps.calculateParams.outputs.template }} -adminCenterApiToken ${{ steps.calculateParams.outputs.adminCenterApiCredentials }} -multiProject:('${{ matrix.style }}' -eq 'multiProject') -appSource:('${{ matrix.type }}' -eq 'appSourceApp') -linux:('${{ matrix.os }}' -eq 'linux') -useCompilerFolder:('${{ matrix.Compiler }}' -eq 'CompilerFolder')
. (Join-Path "." "e2eTests/Test-AL-Go.ps1") -github -githubOwner '${{ needs.Check.outputs.githubowner }}' -repoName ${{ steps.calculateParams.outputs.repoName }} -e2epat '${{ Secrets.E2EPAT }}' -token '${{ Secrets.ALGOAUTHAPP }}' -template ${{ steps.calculateParams.outputs.template }} -adminCenterApiToken ${{ steps.calculateParams.outputs.adminCenterApiCredentials }} -multiProject:('${{ matrix.style }}' -eq 'multiProject') -appSource:('${{ matrix.type }}' -eq 'appSourceApp') -linux:('${{ matrix.os }}' -eq 'linux') -useCompilerFolder:('${{ matrix.Compiler }}' -eq 'CompilerFolder')
}
catch {
Write-Host $_.Exception.Message
Expand Down Expand Up @@ -358,7 +362,7 @@ jobs:
- name: Run tests
run: |
try {
. (Join-Path "." "e2eTests/Test-AL-Go.ps1") -private -github -githubOwner '${{ needs.Check.outputs.githubowner }}' -repoName ${{ steps.calculateParams.outputs.repoName }} -token '${{ Secrets.E2EPAT }}' -template ${{ steps.calculateParams.outputs.template }} -adminCenterApiToken ${{ steps.calculateParams.outputs.adminCenterApiCredentials }} -multiProject:('${{ matrix.style }}' -eq 'multiProject') -appSource:('${{ matrix.type }}' -eq 'appSourceApp') -linux:('${{ matrix.os }}' -eq 'linux') -useCompilerFolder:('${{ matrix.Compiler }}' -eq 'CompilerFolder')
. (Join-Path "." "e2eTests/Test-AL-Go.ps1") -private -github -githubOwner '${{ needs.Check.outputs.githubowner }}' -repoName ${{ steps.calculateParams.outputs.repoName }} -e2epat '${{ Secrets.E2EPAT }}' -token '${{ Secrets.ALGOAUTHAPP }}' -template ${{ steps.calculateParams.outputs.template }} -adminCenterApiToken ${{ steps.calculateParams.outputs.adminCenterApiCredentials }} -multiProject:('${{ matrix.style }}' -eq 'multiProject') -appSource:('${{ matrix.type }}' -eq 'appSourceApp') -linux:('${{ matrix.os }}' -eq 'linux') -useCompilerFolder:('${{ matrix.Compiler }}' -eq 'CompilerFolder')
}
catch {
Write-Host $_.Exception.Message
Expand Down Expand Up @@ -405,7 +409,7 @@ jobs:
- name: Run tests
run: |
try {
. (Join-Path "." "e2eTests/Test-AL-Go-Upgrade.ps1") -github -githubOwner '${{ needs.Check.outputs.githubowner }}' -repoName ${{ steps.calculateParams.outputs.repoName }} -token '${{ Secrets.E2EPAT }}' -template ${{ steps.calculateParams.outputs.template }} -appSource:('${{ matrix.type }}' -eq 'appSourceApp') -release '${{ matrix.release }}' -contentPath ${{ steps.calculateParams.outputs.contentPath }}
. (Join-Path "." "e2eTests/Test-AL-Go-Upgrade.ps1") -github -githubOwner '${{ needs.Check.outputs.githubowner }}' -repoName ${{ steps.calculateParams.outputs.repoName }} -e2epat '${{ Secrets.E2EPAT }}' -token '${{ Secrets.ALGOAUTHAPP }}' -template ${{ steps.calculateParams.outputs.template }} -appSource:('${{ matrix.type }}' -eq 'appSourceApp') -release '${{ matrix.release }}' -contentPath ${{ steps.calculateParams.outputs.contentPath }}
}
catch {
Write-Host $_.Exception.Message
Expand All @@ -431,4 +435,4 @@ jobs:
- name: Remove Repositories
run: |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
. (Join-Path "." "e2eTests/RemoveRepositories.ps1") -github -githubOwner '${{ needs.Check.outputs.githubowner }}' -token '${{ Secrets.E2EPAT }}' -actionsRepo '${{ needs.SetupRepositories.outputs.actionsRepo }}' -perTenantExtensionRepo '${{ needs.SetupRepositories.outputs.perTenantExtensionRepo }}' -appSourceAppRepo '${{ needs.SetupRepositories.outputs.appSourceAppRepo }}'
. (Join-Path "." "e2eTests/RemoveRepositories.ps1") -github -githubOwner '${{ needs.Check.outputs.githubowner }}' -e2epat '${{ Secrets.E2EPAT }}' -token '${{ Secrets.ALGOAUTHAPP }}' -actionsRepo '${{ needs.SetupRepositories.outputs.actionsRepo }}' -perTenantExtensionRepo '${{ needs.SetupRepositories.outputs.perTenantExtensionRepo }}' -appSourceAppRepo '${{ needs.SetupRepositories.outputs.appSourceAppRepo }}'
1 change: 1 addition & 0 deletions Scenarios/Contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ In your personal fork, you can now run the end to end tests, if the following pr

- You need the following secrets:
- E2EPAT needs to be a Personal Access Token with these permissions: _admin:org, delete:packages, delete_repo, repo, workflow, write:packages_
- ALGOAUTHAPP ...
- AdminCenterApiCredentials needs to be the adminCenterApiCredentials as described [here](CreateOnlineDevEnv2.md).
- LicenseFileUrl needs to be a direct download URL to a developer .bclicense file
- Beside the secrets, you need to have a GitHub organization setup, which will contain all the temporary repositories created by the end to end testing. This organization needs to have at least two instances of a GitHub runner registered as self-hosted (for running all private repo builds)
Expand Down
12 changes: 7 additions & 5 deletions e2eTests/Test-AL-Go-Upgrade.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Param(
[switch] $github,
[string] $githubOwner = $global:E2EgithubOwner,
[string] $repoName = [System.IO.Path]::GetFileNameWithoutExtension([System.IO.Path]::GetTempFileName()),
[string] $token = ($Global:SecureE2EPAT | Get-PlainText),
[string] $e2epat = ($Global:SecureE2EPAT | Get-PlainText),
[string] $token = ($Global:SecureToken | Get-PlainText),

Check warning

Code scanning / PSScriptAnalyzer

The parameter 'token' has been declared but not used. Warning

The parameter 'token' has been declared but not used.
[string] $contentPath = "pte",
[string] $release = "v2.2",
[string] $template = $global:pteTemplate,
Expand Down Expand Up @@ -57,7 +58,7 @@ else {
$template = "https://github.com/$template"

# Login
SetTokenAndRepository -github:$github -githubOwner $githubOwner -token $token -repository $repository
SetTokenAndRepository -github:$github -githubOwner $githubOwner -token $e2epat -repository $repository

# Create repo
CreateAlGoRepository -github:$github -template "$($orgTemplate)@$($release)" -contentPath (Join-Path $PSScriptRoot $contentPath) -branch $branch -private:$private
Expand All @@ -83,14 +84,16 @@ $runs++

# Run CI/CD and wait
$run = RunCICD -wait -branch $branch
SetTokenAndRepository -github:$github -githubOwner $githubOwner -token $token -repository $repository
Test-ArtifactsFromRun -runid $run.id -expectedArtifacts @{"Apps"=1;"TestApps"=1} -expectedNumberOfTests 1 -folder 'artifacts' -repoVersion '1.0' -appVersion ''

# Expected Run: CI/CD triggered on workflow_dispatch
$runs++

# Update AL-Go System Files
SetRepositorySecret -repository $repository -name 'GHTOKENWORKFLOW' -value (GetRealToken -token $token -repository "$githubOwner/$repository")
# for Upgrade scenarios before version 6.3 we need to set the GHTOKENWORKFLOW secret to a PAT
# for Upgrade scenarios 6.3 or after we can set the GHTOKENWORKFLOW secret to a GH APP
SetRepositorySecret -repository $repository -name 'GHTOKENWORKFLOW' -value $e2epat
#SetRepositorySecret -repository $repository -name 'GHTOKENWORKFLOW' -value $token
RunUpdateAlGoSystemFiles -templateUrl $template -wait -repository $repository -branch $branch | Out-Null

# Expected Run: Update AL-Go System Files triggered on workflow_dispatch
Expand All @@ -116,7 +119,6 @@ $run = RunCICD -wait -branch $branch

# Expected Run: CICD run on workflow_dispatch
$runs++
SetTokenAndRepository -github:$github -githubOwner $githubOwner -token $token -repository $repository
Test-ArtifactsFromRun -runid $run.id -expectedArtifacts @{"Apps"=1;"TestApps"=1} -expectedNumberOfTests 1 -folder 'artifacts2' -repoVersion '1.0' -appVersion ''

TestNumberOfRuns -expectedNumberOfRuns $runs -repository $repository
Expand Down
8 changes: 3 additions & 5 deletions e2eTests/Test-AL-Go.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Param(
[switch] $github,
[string] $githubOwner = $global:E2EgithubOwner,
[string] $repoName = [System.IO.Path]::GetFileNameWithoutExtension([System.IO.Path]::GetTempFileName()),
[string] $token = ($Global:SecureE2EPAT | Get-PlainText),
[string] $e2epat = ($Global:SecureE2EPAT | Get-PlainText),
[string] $token = ($Global:SecureToken | Get-PlainText),
[string] $template = $global:pteTemplate,
[string] $adminCenterApiToken = ($global:SecureAdminCenterApiToken | Get-PlainText),
[switch] $multiProject,
Expand Down Expand Up @@ -99,7 +100,7 @@ else {
$template = "https://github.com/$template"

# Login
SetTokenAndRepository -github:$github -githubOwner $githubOwner -token $token -repository $repository
SetTokenAndRepository -github:$github -githubOwner $githubOwner -token $e2epat -repository $repository

# Create repo
# Set DoNotPublishApps to true until we have test apps and set useCompilerFolder
Expand Down Expand Up @@ -144,7 +145,6 @@ if ($useCompilerFolder) {
else {
$expectedNumberOfTests = 1
}
SetTokenAndRepository -github:$github -githubOwner $githubOwner -token $token -repository $repository
TestNumberOfRuns -expectedNumberOfRuns $runs -repository $repository
Test-ArtifactsFromRun -runid $run.id -expectedArtifacts @{"Apps"=2;"TestApps"=1} -expectedNumberOfTests $expectedNumberOfTests -folder 'artifacts' -repoVersion '1.0' -appVersion ''

Expand Down Expand Up @@ -203,7 +203,6 @@ $runs++
# Merge and run CI/CD + Tests
$run = MergePRandPull -branch $branch -wait
$runs++
SetTokenAndRepository -github:$github -githubOwner $githubOwner -token $token -repository $repository
if ($multiProject) {
Test-ArtifactsFromRun -runid $run.id -expectedArtifacts @{"Apps"=1;"TestApps"=1} -expectedNumberOfTests $expectedNumberOfTests -folder 'artifacts2' -repoVersion '2.1' -appVersion ''
}
Expand Down Expand Up @@ -231,7 +230,6 @@ if (Test-Path "$($project1Folder).AL-Go\*.ps1") { throw "Local PowerShell script
if (Test-Path ".github\workflows\AddExistingAppOrTestApp.yaml") { throw "AddExistingAppOrTestApp.yaml should have been removed" }
$run = RunCICD -wait -branch $branch
$runs++
SetTokenAndRepository -github:$github -githubOwner $githubOwner -token $token -repository $repository
Test-ArtifactsFromRun -runid $run.id -expectedArtifacts @{"Apps"=3;"TestApps"=2} -expectedNumberOfTests $expectedNumberOfTests -folder 'artifacts3' -repoVersion '3.0' -appVersion '3.0'

# Update AL-Go System Files
Expand Down
6 changes: 3 additions & 3 deletions e2eTests/scenarios/BuildModes/runtest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Param(
[switch] $linux,
[string] $githubOwner = $global:E2EgithubOwner,
[string] $repoName = [System.IO.Path]::GetFileNameWithoutExtension([System.IO.Path]::GetTempFileName()),
[string] $token = ($Global:SecureE2EPAT | Get-PlainText),
[string] $e2epat = ($Global:SecureE2EPAT | Get-PlainText),
[string] $token = ($Global:SecureToken | Get-PlainText),
[string] $pteTemplate = $global:pteTemplate,
[string] $appSourceTemplate = $global:appSourceTemplate,
[string] $adminCenterApiToken = ($global:SecureAdminCenterApiToken | Get-PlainText)
Expand Down Expand Up @@ -43,7 +44,7 @@ $branch = "main"
$template = "https://github.com/$pteTemplate"

# Login
SetTokenAndRepository -github:$github -githubOwner $githubOwner -token $token -repository $repository
SetTokenAndRepository -github:$github -githubOwner $githubOwner -token $e2epat -repository $repository

# Create repo
CreateAlGoRepository `
Expand All @@ -64,7 +65,6 @@ Start-Process $repoPath
$run = RunCICD -repository $repository -branch $branch -wait

# Test number of artifacts
SetTokenAndRepository -github:$github -githubOwner $githubOwner -token $token -repository $repository
Test-ArtifactsFromRun -runid $run.id -folder 'artifacts' -expectedArtifacts @{"Apps"=1;"CleanApps"=1;"TranslatedApps"=1;"CustomBuildModeApps"=1} -repoVersion '1.0' -appVersion '1.0'

Set-Location $prevLocation
Expand Down
7 changes: 3 additions & 4 deletions e2eTests/scenarios/FederatedCredentials/runtest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Param(
[switch] $linux,
[string] $githubOwner = $global:E2EgithubOwner,
[string] $repoName = [System.IO.Path]::GetFileNameWithoutExtension([System.IO.Path]::GetTempFileName()),
[string] $token = ($Global:SecureE2EPAT | Get-PlainText),
[string] $e2epat = ($Global:SecureE2EPAT | Get-PlainText),
[string] $token = ($Global:SecureToken | Get-PlainText),
[string] $pteTemplate = $global:pteTemplate,
[string] $appSourceTemplate = $global:appSourceTemplate,
[string] $adminCenterApiToken = ($global:SecureAdminCenterApiToken | Get-PlainText)
Expand Down Expand Up @@ -57,8 +58,7 @@ $branch = "e2e"
$template = "https://github.com/$appSourceTemplate"
$repository = 'microsoft/bcsamples-bingmaps.appsource'

SetTokenAndRepository -github:$github -githubOwner $githubOwner -token $token -repository $repository
$headers = GetHeaders $token -repository "$githubOwner/.github"
$headers = GetHeaders $e2epat -repository "$githubOwner/.github"

$existingBranch = gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /repos/$repository/branches/$branch 2> $null | ConvertFrom-Json
if ($existingBranch.PSObject.Properties.Name -eq 'Name' -and $existingBranch.Name -eq $branch) {
Expand All @@ -76,7 +76,6 @@ RunUpdateAlGoSystemFiles -directCommit -wait -templateUrl $template -repository
$run = RunCICD -repository $repository -branch $branch -wait

# Check that workflow run uses federated credentials and signing was successful
SetTokenAndRepository -github:$github -githubOwner $githubOwner -token $token -repository $repository
Test-LogContainsFromRun -repository $repository -runid $run.id -jobName 'Build Main App (Default) Main App (Default)' -stepName 'Sign' -expectedText 'Connecting to Azure using clientId and federated token'
Test-LogContainsFromRun -repository $repository -runid $run.id -jobName 'Build Main App (Default) Main App (Default)' -stepName 'Sign' -expectedText 'Signing .* succeeded' -isRegEx

Expand Down
Loading

0 comments on commit 632e1ad

Please sign in to comment.