generated from microsoft/AL-Go-PTE
-
Notifications
You must be signed in to change notification settings - Fork 5
203 lines (182 loc) · 8.07 KB
/
PublishToEnvironment.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
name: ' Publish To Environment'
on:
workflow_dispatch:
inputs:
appVersion:
description: App version to deploy to environment(s) (current, prerelease, draft, latest or version number)
required: false
default: 'current'
environmentName:
description: Environment mask to receive the new version (* for all, PROD* for all environments starting with PROD)
required: true
permissions:
actions: read
contents: read
id-token: write
defaults:
run:
shell: powershell
env:
ALGoOrgSettings: ${{ vars.ALGoOrgSettings }}
ALGoRepoSettings: ${{ vars.ALGoRepoSettings }}
jobs:
Initialization:
needs: [ ]
runs-on: [ windows-latest ]
outputs:
environmentsMatrixJson: ${{ steps.DetermineDeploymentEnvironments.outputs.EnvironmentsMatrixJson }}
environmentCount: ${{ steps.DetermineDeploymentEnvironments.outputs.EnvironmentCount }}
deploymentEnvironmentsJson: ${{ steps.DetermineDeploymentEnvironments.outputs.DeploymentEnvironmentsJson }}
deviceCode: ${{ steps.Authenticate.outputs.deviceCode }}
telemetryScopeJson: ${{ steps.init.outputs.telemetryScopeJson }}
steps:
- name: Dump Workflow Information
uses: microsoft/AL-Go-Actions/[email protected]
with:
shell: powershell
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Initialize the workflow
id: init
uses: microsoft/AL-Go-Actions/[email protected]
with:
shell: powershell
- name: Read settings
id: ReadSettings
uses: microsoft/AL-Go-Actions/[email protected]
with:
shell: powershell
- name: Determine Deployment Environments
id: DetermineDeploymentEnvironments
uses: microsoft/AL-Go-Actions/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}
with:
shell: powershell
getEnvironments: ${{ github.event.inputs.environmentName }}
type: 'Publish'
- name: EnvName
id: envName
if: steps.DetermineDeploymentEnvironments.outputs.UnknownEnvironment == 1
run: |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
$envName = '${{ fromJson(steps.DetermineDeploymentEnvironments.outputs.environmentsMatrixJson).matrix.include[0].environment }}'.split(' ')[0]
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "envName=$envName"
- name: Read secrets
id: ReadSecrets
uses: microsoft/AL-Go-Actions/[email protected]
if: steps.DetermineDeploymentEnvironments.outputs.UnknownEnvironment == 1
with:
shell: powershell
gitHubSecrets: ${{ toJson(secrets) }}
getSecrets: '${{ steps.envName.outputs.envName }}-AuthContext,${{ steps.envName.outputs.envName }}_AuthContext,AuthContext'
- name: Authenticate
id: Authenticate
if: steps.DetermineDeploymentEnvironments.outputs.UnknownEnvironment == 1
run: |
$envName = '${{ steps.envName.outputs.envName }}'
$secretName = ''
$secrets = '${{ steps.ReadSecrets.outputs.Secrets }}' | ConvertFrom-Json
$authContext = $null
"$($envName)-AuthContext", "$($envName)_AuthContext", "AuthContext" | ForEach-Object {
if (!($authContext)) {
if ($secrets."$_") {
Write-Host "Using $_ secret as AuthContext"
$authContext = $secrets."$_"
$secretName = $_
}
}
}
if ($authContext) {
Write-Host "AuthContext provided in secret $secretName!"
Add-Content -Encoding UTF8 -path $ENV:GITHUB_STEP_SUMMARY -value "AuthContext was provided in a secret called $secretName. Using this information for authentication."
}
else {
Write-Host "No AuthContext provided for $envName, initiating Device Code flow"
$ALGoHelperPath = "$([System.IO.Path]::GetTempFileName()).ps1"
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile('https://raw.githubusercontent.com/microsoft/AL-Go-Actions/v5.3/AL-Go-Helper.ps1', $ALGoHelperPath)
. $ALGoHelperPath
DownloadAndImportBcContainerHelper
$authContext = New-BcAuthContext -includeDeviceLogin -deviceLoginTimeout ([TimeSpan]::FromSeconds(0))
Add-Content -Encoding UTF8 -path $ENV:GITHUB_STEP_SUMMARY -value "AL-Go needs access to the Business Central Environment $('${{ steps.envName.outputs.envName }}'.Split(' ')[0]) and could not locate a secret called ${{ steps.envName.outputs.envName }}_AuthContext`n`n$($authContext.message)"
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "deviceCode=$($authContext.deviceCode)"
}
Deploy:
needs: [ Initialization ]
if: needs.Initialization.outputs.environmentCount > 0
strategy: ${{ fromJson(needs.Initialization.outputs.environmentsMatrixJson) }}
runs-on: ${{ fromJson(matrix.os) }}
name: Deploy to ${{ matrix.environment }}
defaults:
run:
shell: ${{ matrix.shell }}
environment:
name: ${{ matrix.environment }}
url: ${{ steps.Deploy.outputs.environmentUrl }}
env:
deviceCode: ${{ needs.Initialization.outputs.deviceCode }}
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: EnvName
id: envName
run: |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
$envName = '${{ matrix.environment }}'.split(' ')[0]
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "envName=$envName"
- name: Read settings
uses: microsoft/AL-Go-Actions/[email protected]
with:
shell: ${{ matrix.shell }}
get: type,powerPlatformSolutionFolder
- name: Read secrets
id: ReadSecrets
uses: microsoft/AL-Go-Actions/[email protected]
with:
shell: ${{ matrix.shell }}
gitHubSecrets: ${{ toJson(secrets) }}
getSecrets: '${{ steps.envName.outputs.envName }}-AuthContext,${{ steps.envName.outputs.envName }}_AuthContext,AuthContext'
- name: Get Artifacts for deployment
uses: microsoft/AL-Go-Actions/[email protected]
with:
shell: ${{ matrix.shell }}
artifactsVersion: ${{ github.event.inputs.appVersion }}
artifactsFolder: '.artifacts'
- name: Deploy to Business Central
id: Deploy
uses: microsoft/AL-Go-Actions/[email protected]
env:
Secrets: '${{ steps.ReadSecrets.outputs.Secrets }}'
with:
shell: ${{ matrix.shell }}
environmentName: ${{ matrix.environment }}
artifactsFolder: '.artifacts'
type: 'Publish'
deploymentEnvironmentsJson: ${{ needs.Initialization.outputs.deploymentEnvironmentsJson }}
- name: Deploy to Power Platform
if: env.type == 'PTE' && env.powerPlatformSolutionFolder != ''
uses: microsoft/AL-Go-Actions/[email protected]
env:
Secrets: '${{ steps.ReadSecrets.outputs.Secrets }}'
with:
shell: ${{ matrix.shell }}
environmentName: ${{ matrix.environment }}
artifactsFolder: '.artifacts'
deploymentEnvironmentsJson: ${{ needs.Initialization.outputs.deploymentEnvironmentsJson }}
PostProcess:
needs: [ Initialization, Deploy ]
if: always()
runs-on: [ windows-latest ]
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Finalize the workflow
id: PostProcess
uses: microsoft/AL-Go-Actions/[email protected]
env:
GITHUB_TOKEN: ${{ github.token }}
with:
shell: ${{ matrix.shell }}
telemetryScopeJson: ${{ needs.Initialization.outputs.telemetryScopeJson }}
currentJobContext: ${{ toJson(job) }}