-
Notifications
You must be signed in to change notification settings - Fork 123
/
CreateOnlineDevelopmentEnvironment.yaml
158 lines (141 loc) · 6.28 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
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?
type: boolean
default: false
directCommit:
description: Direct Commit?
type: boolean
default: false
useGhTokenWorkflow:
description: Use GhTokenWorkflow for PR/Commit?
type: boolean
default: false
permissions:
actions: read
contents: write
id-token: write
pull-requests: write
defaults:
run:
shell: powershell
env:
ALGoOrgSettings: ${{ vars.ALGoOrgSettings }}
ALGoRepoSettings: ${{ vars.ALGoRepoSettings }}
jobs:
Initialization:
needs: [ ]
runs-on: [ windows-latest ]
outputs:
deviceCode: ${{ steps.authenticate.outputs.deviceCode }}
githubRunner: ${{ steps.ReadSettings.outputs.GitHubRunnerJson }}
githubRunnerShell: ${{ steps.ReadSettings.outputs.GitHubRunnerShell }}
telemetryScopeJson: ${{ steps.init.outputs.telemetryScopeJson }}
steps:
- name: Dump Workflow Information
uses: microsoft/AL-Go-Actions/DumpWorkflowInfo@main
with:
shell: powershell
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Initialize the workflow
id: init
uses: microsoft/AL-Go-Actions/WorkflowInitialize@main
with:
shell: powershell
- name: Read settings
id: ReadSettings
uses: microsoft/AL-Go-Actions/ReadSettings@main
with:
shell: powershell
- name: Read secrets
id: ReadSecrets
uses: microsoft/AL-Go-Actions/ReadSecrets@main
with:
shell: powershell
gitHubSecrets: ${{ toJson(secrets) }}
getSecrets: 'adminCenterApiCredentials'
- name: Check AdminCenterApiCredentials / Initiate Device Login (open to see code)
id: authenticate
run: |
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0
$settings = $env:Settings | ConvertFrom-Json
if ('${{ fromJson(steps.ReadSecrets.outputs.Secrets).adminCenterApiCredentials }}') {
Write-Host "AdminCenterApiCredentials provided in secret $($settings.adminCenterApiCredentialsSecretName)!"
Add-Content -Encoding UTF8 -path $ENV:GITHUB_STEP_SUMMARY -value "Admin Center Api Credentials was provided in a secret called $($settings.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/microsoft/AL-Go-Actions/main/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 Admin Center Api and could not locate a secret called $($settings.adminCenterApiCredentialsSecretName) (https://aka.ms/ALGoSettings#AdminCenterApiCredentialsSecretName)`n`n$($authContext.message)"
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "deviceCode=$($authContext.deviceCode)"
}
CreateDevelopmentEnvironment:
needs: [ Initialization ]
runs-on: ${{ fromJson(needs.Initialization.outputs.githubRunner) }}
defaults:
run:
shell: ${{ needs.Initialization.outputs.githubRunnerShell }}
name: Create Development Environment
env:
deviceCode: ${{ needs.Initialization.outputs.deviceCode }}
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Read settings
uses: microsoft/AL-Go-Actions/ReadSettings@main
with:
shell: powershell
- name: Read secrets
id: ReadSecrets
uses: microsoft/AL-Go-Actions/ReadSecrets@main
with:
shell: powershell
gitHubSecrets: ${{ toJson(secrets) }}
getSecrets: 'adminCenterApiCredentials,TokenForPush'
useGhTokenWorkflowForPush: '${{ github.event.inputs.useGhTokenWorkflow }}'
- name: Set AdminCenterApiCredentials
id: SetAdminCenterApiCredentials
run: |
if ($env:deviceCode) {
$adminCenterApiCredentials = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("{""deviceCode"":""$($env:deviceCode)""}"))
}
else {
$adminCenterApiCredentials = '${{ fromJson(steps.ReadSecrets.outputs.Secrets).adminCenterApiCredentials }}'
}
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -value "adminCenterApiCredentials=$adminCenterApiCredentials"
- name: Create Development Environment
uses: microsoft/AL-Go-Actions/CreateDevelopmentEnvironment@main
with:
shell: powershell
token: ${{ steps.ReadSecrets.outputs.TokenForPush }}
environmentName: ${{ github.event.inputs.environmentName }}
project: ${{ github.event.inputs.project }}
reUseExistingEnvironment: ${{ github.event.inputs.reUseExistingEnvironment }}
directCommit: ${{ github.event.inputs.directCommit }}
adminCenterApiCredentials: ${{ steps.SetAdminCenterApiCredentials.outputs.adminCenterApiCredentials }}
- name: Finalize the workflow
if: always()
uses: microsoft/AL-Go-Actions/WorkflowPostProcess@main
env:
GITHUB_TOKEN: ${{ github.token }}
with:
shell: powershell
telemetryScopeJson: ${{ needs.Initialization.outputs.telemetryScopeJson }}
currentJobContext: ${{ toJson(job) }}