generated from microsoft/AL-Go-PTE
-
Notifications
You must be signed in to change notification settings - Fork 15
201 lines (180 loc) · 8.36 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
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:
contents: read
actions: read
defaults:
run:
shell: powershell
env:
ALGoOrgSettings: ${{ vars.ALGoOrgSettings }}
ALGoRepoSettings: ${{ vars.ALGoRepoSettings }}
jobs:
Initialization:
needs: [ ]
runs-on: [ windows-latest ]
outputs:
telemetryScopeJson: ${{ steps.init.outputs.telemetryScopeJson }}
environmentsMatrixJson: ${{ steps.DetermineDeploymentEnvironments.outputs.EnvironmentsMatrixJson }}
environmentCount: ${{ steps.DetermineDeploymentEnvironments.outputs.EnvironmentCount }}
deploymentEnvironmentsJson: ${{ steps.DetermineDeploymentEnvironments.outputs.DeploymentEnvironmentsJson }}
deviceCode: ${{ steps.Authenticate.outputs.deviceCode }}
steps:
- name: Dump Workflow Information
uses: microsoft/AL-Go/Actions/DumpWorkflowInfo@6a9ef0c91e5b54d0fd3abb3d4495417a1db28f17
with:
shell: powershell
- name: Checkout
uses: actions/checkout@v4
- name: Initialize the workflow
id: init
uses: microsoft/AL-Go/Actions/WorkflowInitialize@6a9ef0c91e5b54d0fd3abb3d4495417a1db28f17
with:
shell: powershell
eventId: "DO0097"
- name: Read settings
id: ReadSettings
uses: microsoft/AL-Go/Actions/ReadSettings@6a9ef0c91e5b54d0fd3abb3d4495417a1db28f17
with:
shell: powershell
- name: Determine Deployment Environments
id: DetermineDeploymentEnvironments
uses: microsoft/AL-Go/Actions/DetermineDeploymentEnvironments@6a9ef0c91e5b54d0fd3abb3d4495417a1db28f17
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/ReadSecrets@6a9ef0c91e5b54d0fd3abb3d4495417a1db28f17
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!"
Set-Content -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/6a9ef0c91e5b54d0fd3abb3d4495417a1db28f17/Actions/AL-Go-Helper.ps1', $ALGoHelperPath)
. $ALGoHelperPath
DownloadAndImportBcContainerHelper
$authContext = New-BcAuthContext -includeDeviceLogin -deviceLoginTimeout ([TimeSpan]::FromSeconds(0))
Set-Content -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@v4
- 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/ReadSettings@6a9ef0c91e5b54d0fd3abb3d4495417a1db28f17
with:
shell: ${{ matrix.shell }}
get: type,powerPlatformSolutionFolder
- name: Read secrets
id: ReadSecrets
uses: microsoft/AL-Go/Actions/ReadSecrets@6a9ef0c91e5b54d0fd3abb3d4495417a1db28f17
with:
shell: ${{ matrix.shell }}
gitHubSecrets: ${{ toJson(secrets) }}
getSecrets: '${{ steps.envName.outputs.envName }}-AuthContext,${{ steps.envName.outputs.envName }}_AuthContext,AuthContext,${{ steps.envName.outputs.envName }}-EnvironmentName,${{ steps.envName.outputs.envName }}_EnvironmentName,EnvironmentName,projects'
- name: Get Artifacts for deployment
uses: microsoft/AL-Go/Actions/GetArtifactsForDeployment@6a9ef0c91e5b54d0fd3abb3d4495417a1db28f17
with:
shell: powershell
artifactsVersion: ${{ github.event.inputs.appVersion }}
artifactsFolder: '.artifacts'
- name: Deploy to Business Central
id: Deploy
uses: microsoft/AL-Go/Actions/Deploy@6a9ef0c91e5b54d0fd3abb3d4495417a1db28f17
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/DeployPowerPlatform@6a9ef0c91e5b54d0fd3abb3d4495417a1db28f17
env:
Secrets: '${{ steps.ReadSecrets.outputs.Secrets }}'
with:
shell: powershell
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@v4
- name: Finalize the workflow
id: PostProcess
uses: microsoft/AL-Go/Actions/WorkflowPostProcess@6a9ef0c91e5b54d0fd3abb3d4495417a1db28f17
with:
shell: powershell
eventId: "DO0097"
telemetryScopeJson: ${{ needs.Initialization.outputs.telemetryScopeJson }}