Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next release #23

Merged
merged 23 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
faaf864
Add learn commands notebook
FH-Inway Mar 4, 2024
de2909e
Add confirm integration notebook
FH-Inway Mar 4, 2024
46fa24f
Add app updates installation notebook
FH-Inway Mar 5, 2024
422d996
:memo: Add notebooks documentation
FH-Inway Mar 5, 2024
62f9cf9
Merge pull request #19 from FH-Inway/more-learning
FH-Inway Mar 5, 2024
7474c56
add reusable workflow for build and release
FH-Inway Mar 9, 2024
bff7e8e
add worklow with manual trigger to test reusable workflow for build a…
FH-Inway Mar 9, 2024
3d76ccb
fix call of reusable workflow
FH-Inway Mar 9, 2024
bb69fa1
fix boolean values for PowerShell switch parameters
FH-Inway Mar 9, 2024
2c548c3
remove unnecessary autoversion input
FH-Inway Mar 9, 2024
8e0bf22
add GitHub release creation
FH-Inway Mar 9, 2024
c878f68
fix working directory
FH-Inway Mar 9, 2024
9182513
fix invalid -Name parameter for Get-Item
FH-Inway Mar 9, 2024
5cbe4ad
remove invalid -ItemType parameter from get-item
FH-Inway Mar 9, 2024
3ea2f23
call build and release template
FH-Inway Mar 9, 2024
0ab1b0f
fix api key secret reference
FH-Inway Mar 9, 2024
c540869
fix api key secret reference in manual build action
FH-Inway Mar 9, 2024
f478ff2
Merge pull request #21 from FH-Inway/add-release-creation-to-build-ac…
Splaxi Mar 11, 2024
381f224
Feature: Implement Export-BapEnvironmentSolution
Splaxi Apr 8, 2024
6f59f5c
Feature: Implement Export-BapEnvironmentSolution
Splaxi Apr 8, 2024
e4ce1d8
Merge branch 'impl-export-solution' of https://github.com/Splaxi/d365…
Splaxi Apr 8, 2024
e91182c
Merge pull request #22 from Splaxi/impl-export-solution
Splaxi Apr 8, 2024
574ac57
Merge branch 'main' into development
Splaxi Apr 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/build-manual.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
on:
workflow_dispatch:
inputs:
skippublish:
description: "Determines if the publishing to the PowerShell Gallery is skipped"
default: $True
required: false
type: choice
options:
- $False
- $True
skipghrelease:
description: "Determines if creation of a GitHub release is skipped"
default: $False
required: false
type: choice
options:
- $False
- $True

jobs:
call-tmpl-build-release:
uses: ./.github/workflows/tmpl-build-release.yml
with:
skippublish: ${{ inputs.skippublish }}
skipghrelease: ${{ inputs.skipghrelease }}
secrets:
apikey: ${{ secrets.ApiKey }}
24 changes: 7 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,10 @@
- main

jobs:
build:

runs-on: windows-latest

steps:
- uses: actions/checkout@v1
- name: Install Prerequisites
run: .\build\vsts-prerequisites.ps1
shell: powershell
- name: Validate
run: .\build\vsts-validate.ps1
shell: powershell
- name: Build
run: .\build\vsts-build.ps1 -ApiKey $env:APIKEY -AutoVersion
shell: powershell
env:
APIKEY: ${{ secrets.ApiKey }}
call-tmpl-build-release:
uses: ./.github/workflows/tmpl-build-release.yml
with:
skippublish: $False
skipghrelease: $False
secrets:
apikey: ${{ secrets.ApiKey }}
63 changes: 63 additions & 0 deletions .github/workflows/tmpl-build-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Template for a reusable workflow to build and release a PowerShell module.
# The template expects the following PowerShell scripts in the build folder of the repository root
# that do the actual validated build and release:
# - vsts-prerequisities.ps1
# - vsts-validate.ps1
# - vsts-build.ps1

on:
workflow_call:
inputs:
autoversion:
description: "Determines if the module's build version number is automatically incremented"
default: $True
required: false
type: string
skippublish:
description: "Determines if the publishing to the PowerShell Gallery is skipped"
default: $False
required: false
type: string
skipghrelease:
description: "Determines if a GitHub release is created"
default: $False
required: false
type: string
secrets:
apikey:
description: "Key for the PowerShell Gallery API"
required: true

jobs:
build-and-release:

runs-on: windows-latest

steps:
- uses: actions/checkout@v1
- name: Install Prerequisites
run: .\build\vsts-prerequisites.ps1
shell: powershell
- name: Validate
run: .\build\vsts-validate.ps1
shell: powershell
- name: Build
run: .\build\vsts-build.ps1 -ApiKey ${{ secrets.apikey }} -AutoVersion:${{ inputs.autoversion }} -SkipPublish:${{ inputs.skippublish }}
shell: powershell

- name: Get version
run: |
$publishDir = Get-Item -Path publish
[version]$version = (Import-PowerShellDataFile -Path "$($publishDir.FullName)\d365bap.tools\d365bap.tools.psd1").ModuleVersion
$githubReleaseVersion = "$($version.Major).$($version.Minor).$($version.Build)"
"VERSION=$githubReleaseVersion" >> $env:GITHUB_ENV
shell: powershell

- name: Create GitHub release
uses: softprops/action-gh-release@v2
with:
name: ${{ env.VERSION }}
tag_name: ${{ env.VERSION }}
draft: false
prerelease: true
generate_release_notes: true
4 changes: 4 additions & 0 deletions d365bap.tools/d365bap.tools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@

, 'Confirm-BapEnvironmentIntegration'

, 'Export-BapEnvironmentSolution'

, 'Get-BapEnvironment'
, 'Get-BapEnvironmentApplicationUser'

, 'Get-BapEnvironmentD365App'

, 'Get-BapEnvironmentSolution'

, 'Get-BapEnvironmentUser'

, 'Get-BapEnvironmentVirtualEntity'
Expand Down
113 changes: 113 additions & 0 deletions d365bap.tools/functions/Export-BapEnvironmentSolution.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

<#
.SYNOPSIS
Export PowerPlatform / Dataverse Solution from the environment

.DESCRIPTION
Enables the user to export solutions, on a given environment

The cmdlet downloads the solution, extracts it and removes unnecessary files

.PARAMETER EnvironmentId
The id of the environment that you want to work against

This can be obtained from the Get-BapEnvironment cmdlet

.PARAMETER SolutionId
The id of the solution that you want to work against

This can be obtained from the Get-BapEnvironmentSolution cmdlet

.PARAMETER Path
Path to the location that you want the files to be exported to

.EXAMPLE
PS C:\> Export-BapEnvironmentSolution -EnvironmentId eec2c11a-a4c7-4e1d-b8ed-f62acc9c74c6 -SolutionId 3ac10775-0808-42e0-bd23-83b6c714972f -Path "C:\Temp\"

This will export the solution from the environment.
It will extract the files into the "C:\Temp\" location.

.NOTES
Author: Mötz Jensen (@Splaxi)
#>
function Export-BapEnvironmentSolution {
[CmdletBinding()]
param (
[parameter (mandatory = $true)]
[string] $EnvironmentId,

[parameter (mandatory = $true)]
[string] $SolutionId,

[parameter (mandatory = $true)]
[string] $Path
)

begin {
# Make sure all *BapEnvironment* cmdlets will validate that the environment exists prior running anything.
$envObj = Get-BapEnvironment -EnvironmentId $EnvironmentId | Select-Object -First 1

if ($null -eq $envObj) {
$messageString = "The supplied EnvironmentId: <c='em'>$EnvironmentId</c> didn't return any matching environment details. Please verify that the EnvironmentId is correct - try running the <c='em'>Get-BapEnvironment</c> cmdlet."
Write-PSFMessage -Level Host -Message $messageString
Stop-PSFFunction -Message "Stopping because environment was NOT found based on the id." -Exception $([System.Exception]::new($($messageString -replace '<[^>]+>', '')))
}

if (Test-PSFFunctionInterrupt) { return }

$solObj = Get-BapEnvironmentSolution -EnvironmentId $EnvironmentId -SolutionId $SolutionId | Select-Object -First 1

if ($null -eq $solObj) {
$messageString = "The supplied SolutionId: <c='em'>$SolutionId</c> didn't return any matching solution from the environment. Please verify that the SolutionId is correct - try running the <c='em'>Get-BapEnvironmentSolution</c> cmdlet."
Write-PSFMessage -Level Host -Message $messageString
Stop-PSFFunction -Message "Stopping because solution was NOT found based on the id." -Exception $([System.Exception]::new($($messageString -replace '<[^>]+>', '')))
}
}

process {
if (Test-PSFFunctionInterrupt) { return }

$tmp = pac org list --filter $EnvironmentId

Write-PSFMessage -Level Host -Message "<c='em'>$($tmp[0])</c>"

$found = $false
foreach ($line in $tmp) {
$found = $line -like "*$EnvironmentId*"

if ($found) {
break
}
}

if (-not $found) {
$messageString = "It seems that the current pac cli session isn't connected to the correct tenant. Please run the <c='em'>pac auth create --name 'ChangeThis'</c> and make sure to use credentials that have enough privileges."
Write-PSFMessage -Level Host -Message $messageString
Stop-PSFFunction -Message "Stopping because pac cli session is NOT connected to the correct tenant." -Exception $([System.Exception]::new($($messageString -replace '<[^>]+>', '')))
}

if (Test-PSFFunctionInterrupt) { return }

# pac cli is connected to the correct tenant
$pathDownload = [System.IO.Path]::ChangeExtension([System.IO.Path]::GetTempFileName(), 'zip')

$tmp = pac solution export --name $solObj.SystemName --environment $EnvironmentId --path $pathDownload --overwrite

if (-not (($tmp | Select-Object -Last 1) -eq "Solution export succeeded.")) {
$messageString = "It seems that export of the solution encountered some kind of error. Please run the cmdlet <c='em'>again in a few minutes</c>."
Write-PSFMessage -Level Host -Message $messageString
Stop-PSFFunction -Message "Stopping because export failed." -Exception $([System.Exception]::new($($messageString -replace '<[^>]+>', '')))
}

Expand-Archive -Path $pathDownload -DestinationPath $Path -Force

# Give the file system time to persis the extracted files.
Start-Sleep -Seconds 2

Remove-Item -LiteralPath $(Join-Path -Path $Path -ChildPath "[Content_Types].xml") -ErrorAction SilentlyContinue -Force
}

end {

}
}
Loading