Add new template and commit PR #17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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 | |
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 |