From 4a13cd30bdf5bacf42b6c1a57562f67adf4ebe5b Mon Sep 17 00:00:00 2001 From: freddydk Date: Tue, 3 May 2022 19:20:59 +0200 Subject: [PATCH 1/3] add environmentname secret --- Scenarios/settings.md | 2 +- .../AppSource App/.github/workflows/CICD.yaml | 45 +++++++++++-------- .../workflows/PublishToEnvironment.yaml | 45 +++++++++++-------- .../.github/workflows/CICD.yaml | 45 +++++++++++-------- .../workflows/PublishToEnvironment.yaml | 45 +++++++++++-------- 5 files changed, 109 insertions(+), 73 deletions(-) diff --git a/Scenarios/settings.md b/Scenarios/settings.md index 68e9833be..ccd996deb 100644 --- a/Scenarios/settings.md +++ b/Scenarios/settings.md @@ -27,7 +27,7 @@ When running a workflow or a local script, the settings are applied by reading o | testFolders | testFolders should be an array of folders (relative to project root), which contains test apps for this project. Apps in these folders are sorted based on dependencies and built, published and tests are run in that order. | [ ] | | appSourceCopMandatoryAffixes | This setting is only used if the type is AppSource App. The value is an array of affixes, which is used for running AppSource Cop. | [ ] | | appDependencyProbingPaths | Array of dependency specifications, from which apps will be downloaded when the CI/CD workflow is starting. Every dependency specification consists of the following properties:
**repo** = repository
**version** = version (default latest)
**release_status** = latestBuild/release/prerelease/draft (default latestBuild)
**projects** = projects (default * = all)
**AuthTokenSecret** = Name of secret containing auth token (default none)
| [ ] | -| environments | Array of environment names. You can specify environments in GitHub environments or in the repo settings file. If you specify environments in the settings file, you can create your AUTHCONTEXT secret using environmentname_AUTHCONTEXT. | [ ] | +| environments | Array of logical environment names. You can specify environments in GitHub environments or in the repo settings file. If you specify environments in the settings file, you can create your AUTHCONTEXT secret using <environmentname>_AUTHCONTEXT. If the actual environment name is different from the logical environmentname, then you can create a secret with the actual name called <environmentname>_EnvironmentName | [ ] | ## Basic Repository settings The repository settings are only read from the repository settings file (.github\AL-Go-Settings.json) diff --git a/Templates/AppSource App/.github/workflows/CICD.yaml b/Templates/AppSource App/.github/workflows/CICD.yaml index f765cddcc..cceada8f7 100644 --- a/Templates/AppSource App/.github/workflows/CICD.yaml +++ b/Templates/AppSource App/.github/workflows/CICD.yaml @@ -214,33 +214,42 @@ jobs: secrets: ${{ toJson(secrets) }} with: settingsJson: ${{ env.Settings }} - secrets: '${{ steps.envName.outputs.envName }}-AuthContext,${{ steps.envName.outputs.envName }}_AuthContext,AuthContext' + secrets: '${{ steps.envName.outputs.envName }}-AuthContext,${{ steps.envName.outputs.envName }}_AuthContext,AuthContext,${{ steps.envName.outputs.envName }}-EnvironmentName,${{ steps.envName.outputs.envName }}_EnvironmentName,EnvironmentName' - name: AuthContext id: authContext run: | - $authContext = [System.Environment]::GetEnvironmentVariable('${{ steps.envName.outputs.envName }}-AuthContext') - if ($authContext) { - Write-Host "Using ${{ steps.envName.outputs.envName }}-AuthContext secret" - } - else { - $authContext = [System.Environment]::GetEnvironmentVariable('${{ steps.envName.outputs.envName }}_AuthContext') - if ($authContext) { - Write-Host "Using ${{ steps.envName.outputs.envName }}_AuthContext secret" - } - else { - $authContext = [System.Environment]::GetEnvironmentVariable('AuthContext') + $envName = '${{ steps.envName.outputs.envName }}' + $authContext = $null + "$($envName)-AuthContext", "$($envName)_AuthContext", "AuthContext" | ForEach-Object { + if (!($authContext)) { + $authContext = [System.Environment]::GetEnvironmentVariable($_) if ($authContext) { - Write-Host "Using AuthContext secret" + Write-Host "Using $_ secret" } - else { - Write-Host "::Error::No AuthContext provided" - exit 1 + } + } + if (!($authContext)) { + Write-Host "::Error::No AuthContext provided" + exit 1 + } + $environmentName = $null + "$($envName)-EnvironmentName", "$($envName)_EnvironmentName", "EnvironmentName" | ForEach-Object { + if (!($EnvironmentName)) { + $EnvironmentName = [System.Environment]::GetEnvironmentVariable($_) + if ($EnvironmentName) { + Write-Host "Using $_ secret" } - } + } + } + if (!($environmentName)) { + $envName = '${{ steps.envName.outputs.envName }}' } + $environmentName = $environmentName + '${{ matrix.environment }}'.SubString($envName.Length) Write-Host "::set-output name=authContext::$authContext" Write-Host "set-output name=authContext::$authContext" + Write-Host "::set-output name=environmentName::$environmentName" + Write-Host "set-output name=environmentName::$environmentName" - name: Deploy uses: microsoft/AL-Go-Actions/Deploy@main @@ -249,7 +258,7 @@ jobs: with: type: 'CD' projects: '${{ secrets.Projects }}' - environmentName: ${{ matrix.environment }} + environmentName: '${{ steps.authContext.outputs.environmentName }}' artifacts: '${{ github.workspace }}\artifacts' PostProcess: diff --git a/Templates/AppSource App/.github/workflows/PublishToEnvironment.yaml b/Templates/AppSource App/.github/workflows/PublishToEnvironment.yaml index bf1c34d94..2d7a22416 100644 --- a/Templates/AppSource App/.github/workflows/PublishToEnvironment.yaml +++ b/Templates/AppSource App/.github/workflows/PublishToEnvironment.yaml @@ -84,33 +84,42 @@ jobs: secrets: ${{ toJson(secrets) }} with: settingsJson: ${{ env.Settings }} - secrets: '${{ steps.envName.outputs.envName }}-AuthContext,${{ steps.envName.outputs.envName }}_AuthContext,AuthContext' + secrets: '${{ steps.envName.outputs.envName }}-AuthContext,${{ steps.envName.outputs.envName }}_AuthContext,AuthContext,${{ steps.envName.outputs.envName }}-EnvironmentName,${{ steps.envName.outputs.envName }}_EnvironmentName,EnvironmentName' - name: AuthContext id: authContext run: | - $authContext = [System.Environment]::GetEnvironmentVariable('${{ steps.envName.outputs.envName }}-AuthContext') - if ($authContext) { - Write-Host "Using ${{ steps.envName.outputs.envName }}-AuthContext secret" - } - else { - $authContext = [System.Environment]::GetEnvironmentVariable('${{ steps.envName.outputs.envName }}_AuthContext') - if ($authContext) { - Write-Host "Using ${{ steps.envName.outputs.envName }}_AuthContext secret" - } - else { - $authContext = [System.Environment]::GetEnvironmentVariable('AuthContext') + $envName = '${{ steps.envName.outputs.envName }}' + $authContext = $null + "$($envName)-AuthContext", "$($envName)_AuthContext", "AuthContext" | ForEach-Object { + if (!($authContext)) { + $authContext = [System.Environment]::GetEnvironmentVariable($_) if ($authContext) { - Write-Host "Using AuthContext secret" + Write-Host "Using $_ secret" } - else { - Write-Host "::Error::No AuthContext provided" - exit 1 + } + } + if (!($authContext)) { + Write-Host "::Error::No AuthContext provided" + exit 1 + } + $environmentName = $null + "$($envName)-EnvironmentName", "$($envName)_EnvironmentName", "EnvironmentName" | ForEach-Object { + if (!($EnvironmentName)) { + $EnvironmentName = [System.Environment]::GetEnvironmentVariable($_) + if ($EnvironmentName) { + Write-Host "Using $_ secret" } - } + } + } + if (!($environmentName)) { + $envName = '${{ steps.envName.outputs.envName }}' } + $environmentName = $environmentName + '${{ matrix.environment }}'.SubString($envName.Length) Write-Host "::set-output name=authContext::$authContext" Write-Host "set-output name=authContext::$authContext" + Write-Host "::set-output name=environmentName::$environmentName" + Write-Host "set-output name=environmentName::$environmentName" - name: Deploy uses: microsoft/AL-Go-Actions/Deploy@main @@ -120,7 +129,7 @@ jobs: parentTelemetryScopeJson: ${{ needs.Initialization.outputs.telemetryScopeJson }} type: 'Publish' projects: '${{ secrets.Projects }}' - environmentName: ${{ matrix.environment }} + environmentName: '${{ steps.authContext.outputs.environmentName }}' artifacts: ${{ github.event.inputs.appVersion }} PostProcess: diff --git a/Templates/Per Tenant Extension/.github/workflows/CICD.yaml b/Templates/Per Tenant Extension/.github/workflows/CICD.yaml index f765cddcc..cceada8f7 100644 --- a/Templates/Per Tenant Extension/.github/workflows/CICD.yaml +++ b/Templates/Per Tenant Extension/.github/workflows/CICD.yaml @@ -214,33 +214,42 @@ jobs: secrets: ${{ toJson(secrets) }} with: settingsJson: ${{ env.Settings }} - secrets: '${{ steps.envName.outputs.envName }}-AuthContext,${{ steps.envName.outputs.envName }}_AuthContext,AuthContext' + secrets: '${{ steps.envName.outputs.envName }}-AuthContext,${{ steps.envName.outputs.envName }}_AuthContext,AuthContext,${{ steps.envName.outputs.envName }}-EnvironmentName,${{ steps.envName.outputs.envName }}_EnvironmentName,EnvironmentName' - name: AuthContext id: authContext run: | - $authContext = [System.Environment]::GetEnvironmentVariable('${{ steps.envName.outputs.envName }}-AuthContext') - if ($authContext) { - Write-Host "Using ${{ steps.envName.outputs.envName }}-AuthContext secret" - } - else { - $authContext = [System.Environment]::GetEnvironmentVariable('${{ steps.envName.outputs.envName }}_AuthContext') - if ($authContext) { - Write-Host "Using ${{ steps.envName.outputs.envName }}_AuthContext secret" - } - else { - $authContext = [System.Environment]::GetEnvironmentVariable('AuthContext') + $envName = '${{ steps.envName.outputs.envName }}' + $authContext = $null + "$($envName)-AuthContext", "$($envName)_AuthContext", "AuthContext" | ForEach-Object { + if (!($authContext)) { + $authContext = [System.Environment]::GetEnvironmentVariable($_) if ($authContext) { - Write-Host "Using AuthContext secret" + Write-Host "Using $_ secret" } - else { - Write-Host "::Error::No AuthContext provided" - exit 1 + } + } + if (!($authContext)) { + Write-Host "::Error::No AuthContext provided" + exit 1 + } + $environmentName = $null + "$($envName)-EnvironmentName", "$($envName)_EnvironmentName", "EnvironmentName" | ForEach-Object { + if (!($EnvironmentName)) { + $EnvironmentName = [System.Environment]::GetEnvironmentVariable($_) + if ($EnvironmentName) { + Write-Host "Using $_ secret" } - } + } + } + if (!($environmentName)) { + $envName = '${{ steps.envName.outputs.envName }}' } + $environmentName = $environmentName + '${{ matrix.environment }}'.SubString($envName.Length) Write-Host "::set-output name=authContext::$authContext" Write-Host "set-output name=authContext::$authContext" + Write-Host "::set-output name=environmentName::$environmentName" + Write-Host "set-output name=environmentName::$environmentName" - name: Deploy uses: microsoft/AL-Go-Actions/Deploy@main @@ -249,7 +258,7 @@ jobs: with: type: 'CD' projects: '${{ secrets.Projects }}' - environmentName: ${{ matrix.environment }} + environmentName: '${{ steps.authContext.outputs.environmentName }}' artifacts: '${{ github.workspace }}\artifacts' PostProcess: diff --git a/Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml b/Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml index bf1c34d94..2d7a22416 100644 --- a/Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml +++ b/Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml @@ -84,33 +84,42 @@ jobs: secrets: ${{ toJson(secrets) }} with: settingsJson: ${{ env.Settings }} - secrets: '${{ steps.envName.outputs.envName }}-AuthContext,${{ steps.envName.outputs.envName }}_AuthContext,AuthContext' + secrets: '${{ steps.envName.outputs.envName }}-AuthContext,${{ steps.envName.outputs.envName }}_AuthContext,AuthContext,${{ steps.envName.outputs.envName }}-EnvironmentName,${{ steps.envName.outputs.envName }}_EnvironmentName,EnvironmentName' - name: AuthContext id: authContext run: | - $authContext = [System.Environment]::GetEnvironmentVariable('${{ steps.envName.outputs.envName }}-AuthContext') - if ($authContext) { - Write-Host "Using ${{ steps.envName.outputs.envName }}-AuthContext secret" - } - else { - $authContext = [System.Environment]::GetEnvironmentVariable('${{ steps.envName.outputs.envName }}_AuthContext') - if ($authContext) { - Write-Host "Using ${{ steps.envName.outputs.envName }}_AuthContext secret" - } - else { - $authContext = [System.Environment]::GetEnvironmentVariable('AuthContext') + $envName = '${{ steps.envName.outputs.envName }}' + $authContext = $null + "$($envName)-AuthContext", "$($envName)_AuthContext", "AuthContext" | ForEach-Object { + if (!($authContext)) { + $authContext = [System.Environment]::GetEnvironmentVariable($_) if ($authContext) { - Write-Host "Using AuthContext secret" + Write-Host "Using $_ secret" } - else { - Write-Host "::Error::No AuthContext provided" - exit 1 + } + } + if (!($authContext)) { + Write-Host "::Error::No AuthContext provided" + exit 1 + } + $environmentName = $null + "$($envName)-EnvironmentName", "$($envName)_EnvironmentName", "EnvironmentName" | ForEach-Object { + if (!($EnvironmentName)) { + $EnvironmentName = [System.Environment]::GetEnvironmentVariable($_) + if ($EnvironmentName) { + Write-Host "Using $_ secret" } - } + } + } + if (!($environmentName)) { + $envName = '${{ steps.envName.outputs.envName }}' } + $environmentName = $environmentName + '${{ matrix.environment }}'.SubString($envName.Length) Write-Host "::set-output name=authContext::$authContext" Write-Host "set-output name=authContext::$authContext" + Write-Host "::set-output name=environmentName::$environmentName" + Write-Host "set-output name=environmentName::$environmentName" - name: Deploy uses: microsoft/AL-Go-Actions/Deploy@main @@ -120,7 +129,7 @@ jobs: parentTelemetryScopeJson: ${{ needs.Initialization.outputs.telemetryScopeJson }} type: 'Publish' projects: '${{ secrets.Projects }}' - environmentName: ${{ matrix.environment }} + environmentName: '${{ steps.authContext.outputs.environmentName }}' artifacts: ${{ github.event.inputs.appVersion }} PostProcess: From 6ecefb6cef62f13ce3c22f05cf819a6848ef6ce8 Mon Sep 17 00:00:00 2001 From: freddydk Date: Tue, 3 May 2022 19:22:17 +0200 Subject: [PATCH 2/3] bold --- Scenarios/settings.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scenarios/settings.md b/Scenarios/settings.md index ccd996deb..9a243115e 100644 --- a/Scenarios/settings.md +++ b/Scenarios/settings.md @@ -27,7 +27,7 @@ When running a workflow or a local script, the settings are applied by reading o | testFolders | testFolders should be an array of folders (relative to project root), which contains test apps for this project. Apps in these folders are sorted based on dependencies and built, published and tests are run in that order. | [ ] | | appSourceCopMandatoryAffixes | This setting is only used if the type is AppSource App. The value is an array of affixes, which is used for running AppSource Cop. | [ ] | | appDependencyProbingPaths | Array of dependency specifications, from which apps will be downloaded when the CI/CD workflow is starting. Every dependency specification consists of the following properties:
**repo** = repository
**version** = version (default latest)
**release_status** = latestBuild/release/prerelease/draft (default latestBuild)
**projects** = projects (default * = all)
**AuthTokenSecret** = Name of secret containing auth token (default none)
| [ ] | -| environments | Array of logical environment names. You can specify environments in GitHub environments or in the repo settings file. If you specify environments in the settings file, you can create your AUTHCONTEXT secret using <environmentname>_AUTHCONTEXT. If the actual environment name is different from the logical environmentname, then you can create a secret with the actual name called <environmentname>_EnvironmentName | [ ] | +| environments | Array of logical environment names. You can specify environments in GitHub environments or in the repo settings file. If you specify environments in the settings file, you can create your AUTHCONTEXT secret using **<environmentname>_AUTHCONTEXT**. If the actual environment name is different from the logical environmentname, then you can create a secret with the actual name called **<environmentname>_ENVIRONMENTNAME** | [ ] | ## Basic Repository settings The repository settings are only read from the repository settings file (.github\AL-Go-Settings.json) From 55f926057d855e35dcaa0752d79f06684cd9915c Mon Sep 17 00:00:00 2001 From: freddydk Date: Tue, 3 May 2022 18:32:04 +0000 Subject: [PATCH 3/3] Collect changes from freddydk/*@main --- Templates/AppSource App/.github/workflows/CICD.yaml | 4 ++-- .../AppSource App/.github/workflows/PublishToEnvironment.yaml | 4 ++-- Templates/Per Tenant Extension/.github/workflows/CICD.yaml | 4 ++-- .../.github/workflows/PublishToEnvironment.yaml | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Templates/AppSource App/.github/workflows/CICD.yaml b/Templates/AppSource App/.github/workflows/CICD.yaml index cceada8f7..ed4f25879 100644 --- a/Templates/AppSource App/.github/workflows/CICD.yaml +++ b/Templates/AppSource App/.github/workflows/CICD.yaml @@ -243,9 +243,9 @@ jobs: } } if (!($environmentName)) { - $envName = '${{ steps.envName.outputs.envName }}' + $environmentName = '${{ steps.envName.outputs.envName }}' } - $environmentName = $environmentName + '${{ matrix.environment }}'.SubString($envName.Length) + $environmentName = ($environmentName + '${{ matrix.environment }}'.SubString($envName.Length)).ToUpperInvariant() Write-Host "::set-output name=authContext::$authContext" Write-Host "set-output name=authContext::$authContext" Write-Host "::set-output name=environmentName::$environmentName" diff --git a/Templates/AppSource App/.github/workflows/PublishToEnvironment.yaml b/Templates/AppSource App/.github/workflows/PublishToEnvironment.yaml index 2d7a22416..82ab97274 100644 --- a/Templates/AppSource App/.github/workflows/PublishToEnvironment.yaml +++ b/Templates/AppSource App/.github/workflows/PublishToEnvironment.yaml @@ -113,9 +113,9 @@ jobs: } } if (!($environmentName)) { - $envName = '${{ steps.envName.outputs.envName }}' + $environmentName = '${{ steps.envName.outputs.envName }}' } - $environmentName = $environmentName + '${{ matrix.environment }}'.SubString($envName.Length) + $environmentName = ($environmentName + '${{ matrix.environment }}'.SubString($envName.Length)).ToUpperInvariant() Write-Host "::set-output name=authContext::$authContext" Write-Host "set-output name=authContext::$authContext" Write-Host "::set-output name=environmentName::$environmentName" diff --git a/Templates/Per Tenant Extension/.github/workflows/CICD.yaml b/Templates/Per Tenant Extension/.github/workflows/CICD.yaml index cceada8f7..ed4f25879 100644 --- a/Templates/Per Tenant Extension/.github/workflows/CICD.yaml +++ b/Templates/Per Tenant Extension/.github/workflows/CICD.yaml @@ -243,9 +243,9 @@ jobs: } } if (!($environmentName)) { - $envName = '${{ steps.envName.outputs.envName }}' + $environmentName = '${{ steps.envName.outputs.envName }}' } - $environmentName = $environmentName + '${{ matrix.environment }}'.SubString($envName.Length) + $environmentName = ($environmentName + '${{ matrix.environment }}'.SubString($envName.Length)).ToUpperInvariant() Write-Host "::set-output name=authContext::$authContext" Write-Host "set-output name=authContext::$authContext" Write-Host "::set-output name=environmentName::$environmentName" diff --git a/Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml b/Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml index 2d7a22416..82ab97274 100644 --- a/Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml +++ b/Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml @@ -113,9 +113,9 @@ jobs: } } if (!($environmentName)) { - $envName = '${{ steps.envName.outputs.envName }}' + $environmentName = '${{ steps.envName.outputs.envName }}' } - $environmentName = $environmentName + '${{ matrix.environment }}'.SubString($envName.Length) + $environmentName = ($environmentName + '${{ matrix.environment }}'.SubString($envName.Length)).ToUpperInvariant() Write-Host "::set-output name=authContext::$authContext" Write-Host "set-output name=authContext::$authContext" Write-Host "::set-output name=environmentName::$environmentName"