forked from freddydk/spchars
-
Notifications
You must be signed in to change notification settings - Fork 0
163 lines (146 loc) · 6.86 KB
/
CreateOnlineDevelopmentEnvironment.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
name: ' Create Online Dev. Environment'
run-name: "Create Online Dev. Environment for [${{ github.ref_name }} / ${{ github.event.inputs.project }}]"
on:
workflow_dispatch:
inputs:
project:
description: Project name if the repository is setup for multiple projects
required: false
default: '.'
environmentName:
description: Name of the online environment
required: true
reUseExistingEnvironment:
description: Reuse environment if it exists
required: false
default: 'N'
directCommit:
description: Direct COMMIT (Y/N)
required: false
default: 'N'
useGhTokenWorkflow:
description: Use GhTokenWorkflow for Pull Request/COMMIT
type: boolean
permissions:
contents: write
pull-requests: write
defaults:
run:
shell: powershell
env:
ALGoOrgSettings: ${{ vars.ALGoOrgSettings }}
ALGoRepoSettings: ${{ vars.ALGoRepoSettings }}
jobs:
Initialization:
runs-on: [ windows-latest ]
outputs:
deviceCode: ${{ steps.authenticate.outputs.deviceCode }}
telemetryScopeJson: ${{ steps.init.outputs.telemetryScopeJson }}
githubRunner: ${{ steps.ReadSettings.outputs.GitHubRunnerJson }}
githubRunnerShell: ${{ steps.ReadSettings.outputs.GitHubRunnerShell }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Initialize the workflow
id: init
uses: mazhelez/AL-Go/Actions/WorkflowInitialize@output-encoding
with:
shell: powershell
eventId: "DO0093"
- name: Read settings
id: ReadSettings
uses: mazhelez/AL-Go/Actions/ReadSettings@output-encoding
with:
shell: powershell
parentTelemetryScopeJson: ${{ steps.init.outputs.telemetryScopeJson }}
- name: Read secrets
uses: mazhelez/AL-Go/Actions/ReadSecrets@output-encoding
env:
secrets: ${{ toJson(secrets) }}
with:
shell: powershell
parentTelemetryScopeJson: ${{ steps.init.outputs.telemetryScopeJson }}
settingsJson: ${{ env.Settings }}
secrets: 'adminCenterApiCredentials'
- name: Check AdminCenterApiCredentials / Initiate Device Login (open to see code)
id: authenticate
run: |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
$adminCenterApiCredentials = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($env:adminCenterApiCredentials))
if ($adminCenterApiCredentials) {
Write-Host "AdminCenterApiCredentials provided in secret $($ENV:adminCenterApiCredentialsSecretName)!"
Set-Content -Path $ENV:GITHUB_STEP_SUMMARY -value "Admin Center Api Credentials was provided in a secret called $($ENV:adminCenterApiCredentialsSecretName). Using this information for authentication."
}
else {
Write-Host "AdminCenterApiCredentials not provided, initiating Device Code flow"
$ALGoHelperPath = "$([System.IO.Path]::GetTempFileName()).ps1"
$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile('https://raw.githubusercontent.com/mazhelez/AL-Go/output-encoding/Actions/AL-Go-Helper.ps1', $ALGoHelperPath)
. $ALGoHelperPath
$BcContainerHelperPath = DownloadAndImportBcContainerHelper -baseFolder $ENV:GITHUB_WORKSPACE
$authContext = New-BcAuthContext -includeDeviceLogin -deviceLoginTimeout ([TimeSpan]::FromSeconds(0))
CleanupAfterBcContainerHelper -bcContainerHelperPath $bcContainerHelperPath
Set-Content -Path $ENV:GITHUB_STEP_SUMMARY -value "AL-Go needs access to the Business Central Admin Center Api and could not locate a secret called $($ENV:adminCenterApiCredentialsSecretName) (https://aka.ms/ALGoSettings#AdminCenterApiCredentialsSecretName)`n`n$($authContext.message)"
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "deviceCode=$($authContext.deviceCode)"
}
CreateDevelopmentEnvironment:
runs-on: ${{ fromJson(needs.Initialization.outputs.githubRunner) }}
defaults:
run:
shell: ${{ needs.Initialization.outputs.githubRunnerShell }}
name: Create Development Environment
needs: [ Initialization ]
env:
deviceCode: ${{ needs.Initialization.outputs.deviceCode }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Read settings
uses: mazhelez/AL-Go/Actions/ReadSettings@output-encoding
with:
shell: powershell
parentTelemetryScopeJson: ${{ needs.Initialization.outputs.telemetryScopeJson }}
- name: Read secrets
uses: mazhelez/AL-Go/Actions/ReadSecrets@output-encoding
env:
secrets: ${{ toJson(secrets) }}
with:
shell: powershell
parentTelemetryScopeJson: ${{ needs.Initialization.outputs.telemetryScopeJson }}
settingsJson: ${{ env.Settings }}
secrets: 'adminCenterApiCredentials,ghTokenWorkflow=${{ env.GHTOKENWORKFLOWSECRETNAME }}'
- name: CalculateToken
id: CalculateToken
env:
useGhTokenWorkflow: ${{ github.event.inputs.useGhTokenWorkflow }}
run: |
if ($env:useGhTokenWorkflow -eq 'true') {
$ghToken = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($env:GHTOKENWORKFLOW))
} else {
$ghToken = '${{ secrets.GITHUB_TOKEN }}'
}
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "ghToken=$ghToken"
- name: Set AdminCenterApiCredentials
run: |
if ($env:deviceCode) {
$adminCenterApiCredentials = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("{""deviceCode"":""$($env:deviceCode)""}"))
Add-Content -Encoding UTF8 -Path $env:GITHUB_ENV -value "adminCenterApiCredentials=$adminCenterApiCredentials"
}
- name: Create Development Environment
uses: mazhelez/AL-Go/Actions/CreateDevelopmentEnvironment@output-encoding
with:
shell: powershell
token: ${{ steps.CalculateToken.outputs.ghToken }}
parentTelemetryScopeJson: ${{ needs.Initialization.outputs.telemetryScopeJson }}
environmentName: ${{ github.event.inputs.environmentName }}
project: ${{ github.event.inputs.project }}
reUseExistingEnvironment: ${{ github.event.inputs.reUseExistingEnvironment }}
directCommit: ${{ github.event.inputs.directCommit }}
adminCenterApiCredentials: ${{ env.adminCenterApiCredentials }}
- name: Finalize the workflow
if: always()
uses: mazhelez/AL-Go/Actions/WorkflowPostProcess@output-encoding
with:
shell: powershell
eventId: "DO0093"
telemetryScopeJson: ${{ needs.Initialization.outputs.telemetryScopeJson }}