-
Notifications
You must be signed in to change notification settings - Fork 10
219 lines (187 loc) · 8.8 KB
/
add-new-template.yml
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
---
name: Add new template and commit PR
on:
workflow_dispatch:
inputs:
solution_name:
description: >
"The solution name with prefix. Not the display name,
but the exact unique name of the solution.
(Examples: mpa_ITBase, mpa_Kudos, etc.)"
required: true
default: 'mpa_'
user_name:
description: "User name for the commit"
required: true
default: 'tshanep'
dev_env_url:
description: >
"The Instance URL of the Dev Environment for this solution.
You can get this from Session details.
Example: https://aicdev4.crm.dynamics.com/"
required: true
solution_type:
description: "Enter 'BASE' or 'APP'."
required: true
dependent_on_solution_name:
description: >
"If solution_type is APP, enter the exact unique name of
the base solution this depends on. (Example: mpa_ITBase).
Leave empty if it is a BASE solution."
required: false
permissions:
contents: write
pull-requests: write
packages: write
jobs:
build-and-create-pr-for-new-template:
runs-on: windows-latest
defaults:
run:
shell: pwsh
steps:
- name: Install Power Platform Tools
uses: microsoft/powerplatform-actions/actions-install@v1
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '14'
# Install Power Platform CLI
- name: Install Power Platform CLI
run: dotnet tool install --global Microsoft.PowerApps.CLI.Tool
# Enable long path support in Git
- name: Enable long paths support in Git
run: git config --system core.longpaths true
# Validate solution_type input
- name: Validate solution_type input
run: |
$validTypes = @("BASE", "APP")
$inputType = "${{ github.event.inputs.solution_type }}"
if (-not $validTypes.Contains($inputType)) {
Write-Error "Invalid solution_type input. Must be either 'BASE' or 'APP'."
exit 1
}
shell: pwsh
# Validate dependent_on_solution_name input when solution_type is APP
- name: Validate dependent_on_solution_name input
run: |
$solutionType = "${{ github.event.inputs.solution_type }}"
$dependentOnSolutionName = "${{ github.event.inputs.dependent_on_solution_name }}"
if ($solutionType -eq "APP" -and [string]::IsNullOrEmpty($dependentOnSolutionName)) {
Write-Error "dependent_on_solution_name must have a value when solution_type is 'APP'. You need to provide the BASE solution uniquename that it is dependent on."
exit 1
}
shell: pwsh
# Enable long path support across all steps
- name: Enable long path support in windows
run: |
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1
shell: pwsh
# Setup Auth with the Correct Environment
- name: Authenticate with Source PowerApps Environment
run: |
pac auth clear
pac auth create --url ${{ github.event.inputs.dev_env_url }} --username ${{ secrets.AUTOMATION_USERNAME }} --password ${{ secrets.AUTOMATION_PASSWORD }} --name DevEnv --cloud Public
# Checkout the main branch
- name: Checkout main branch
uses: actions/checkout@v3
with:
ref: 'main'
# Check if the folder exists
- name: Check to see if solution already exists
id: check_folder
run: |
$folderPath = "solutions/${{ github.event.inputs.solution_name }}"
if (Test-Path $folderPath) {
Write-Host "The solution seems to already exist in the Git Repo - this workflow is only for new solutions being added to Git the first time."
echo "FOLDER_EXISTS=true" | Out-File -FilePath $env:GITHUB_ENV -Append
exit 1
} else {
Write-Host "Solution folder does not exist - will proceed to initialize the solution."
echo "FOLDER_EXISTS=false" | Out-File -FilePath $env:GITHUB_ENV -Append
}
# Navigate to the Solutions folder and initialize the solution
- name: Initialize New Power Platform Template
run: |
pac solution init --publisher-name PowerAccelerator --publisher-prefix mpa --outputDirectory .\Solutions\${{ github.event.inputs.solution_name }}
# Add SolutionPackageType of BOTH to <PropertyGroup> in cdsproj
- name: Add SolutionPackageType node to VS Project file
run: |
# Specify the path to the XML file
$xmlPath = "Solutions/${{ github.event.inputs.solution_name }}/${{ github.event.inputs.solution_name }}.cdsproj"
# Load the XML file
$xml = New-Object System.Xml.XmlDocument
$xml.Load($xmlPath)
# Define and add the namespace manager
$namespaceManager = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
$namespaceManager.AddNamespace("msb", "http://schemas.microsoft.com/developer/msbuild/2003")
# Create the new node
$newNode = $xml.CreateElement("SolutionPackageType", $namespaceManager.LookupNamespace("msb"))
$newNode.InnerText = "Both"
# Find the target PropertyGroup node
$propertyGroup = $xml.SelectSingleNode("//msb:PropertyGroup", $namespaceManager)
# Add the new node to the PropertyGroup
$propertyGroup.AppendChild($newNode)
# Save the updated XML back to the file
$xml.Save($xmlPath)
shell: pwsh
env:
# Define the XML namespace used in your XML file
namespace: http://schemas.microsoft.com/developer/msbuild/2003
# Add SolutionsToBuild node to main solutions.proj
- name: Add SolutionsToBuild node to main solutions.proj
run: |
# Define the path to the XML file
$xmlPath = "Solutions/solutions.proj"
# Load the XML file
$xml = New-Object System.Xml.XmlDocument
$xml.PreserveWhitespace = $true
$xml.Load($xmlPath)
# Define and add the namespace manager
$namespaceManager = New-Object System.Xml.XmlNamespaceManager($xml.NameTable)
$namespaceManager.AddNamespace("msb", "http://schemas.microsoft.com/developer/msbuild/2003")
# Create the new node
$newNode = $xml.CreateElement("SolutionsToBuild", $xml.DocumentElement.NamespaceURI)
$newNode.SetAttribute("Include", "${{ github.event.inputs.solution_name }}/${{ github.event.inputs.solution_name }}.cdsproj")
# Find the target ItemGroup node
$itemGroup = $xml.SelectSingleNode("//msb:ItemGroup", $namespaceManager)
# Add the new node to the ItemGroup
$itemGroup.AppendChild($newNode)
# Save the updated XML back to the file
$xml.Save($xmlPath)
shell: pwsh
env:
# Define the XML namespace used in your XML file
namespace: http://schemas.microsoft.com/developer/msbuild/2003
# Sync and Build Solution
- name: Sync and Build New Template
run: |
cd .\Solutions\${{ github.event.inputs.solution_name }}\
pac solution sync --processCanvasApps
dotnet build /p:configuration=Release ${{ github.event.inputs.solution_name }}.cdsproj
shell: pwsh
# If solution_type is APP, then sync and build the base solution also
- name: Sync and Build Base Template Solution (if any)
if: ${{ github.event.inputs.solution_type == 'APP' }}
run: |
cd .\Solutions\${{ github.event.inputs.solution_name }}\
pac solution sync --processCanvasApps
dotnet build /p:configuration=Release ${{ github.event.inputs.solution_name }}.cdsproj
shell: pwsh
# Checkout to a local user branch, commit, and Pull Request
- name: Checkout to a new branch, commit, and Pull Request
run: |
$branchDateTime = Get-Date -Format "yyyyMMdd-HHmmss"
$branchName = "auto_pipeline/${{ github.event.inputs.solution_name }}-$branchDateTime"
git config --global user.name "tshanep"
git config --global user.email "[email protected]"
git checkout -b $branchName
echo "BRANCH_NAME=$branchName" | Out-File -Append -Encoding utf8 $env:GITHUB_ENV
Write-Host "Working on branch $branchName"
git add .
git commit -m "Added new solution: ${{ github.event.inputs.solution_name }}"
git push origin $branchName
# gh pr create --title "Add new solution ${{ github.event.inputs.solution_name }}" --body "Added new solution: ${{ github.event.inputs.solution_name }}" --base main --head $branchName
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: pwsh