Skip to content

Commit

Permalink
Merge pull request #73 from onikolaiev/develop
Browse files Browse the repository at this point in the history
Add Power Platform Unified Package creation functionality
  • Loading branch information
onikolaiev authored Dec 30, 2024
2 parents 553d779 + 524bcd6 commit 20a4dc8
Show file tree
Hide file tree
Showing 26 changed files with 620 additions and 40 deletions.
135 changes: 135 additions & 0 deletions docs/Update-FSCPSNugetsFromLCS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
---
external help file: fscps.tools-help.xml
Module Name: fscps.tools
online version:
schema: 2.0.0
---

# Update-FSCPSNugetsFromLCS

## SYNOPSIS
This uploads the D365FSC nugets from the LCS to the active storage account

## SYNTAX

```
Update-FSCPSNugetsFromLCS [[-LCSUserName] <String>] [[-LCSUserPassword] <SecureString>]
[[-LCSProjectId] <String>] [[-LCSClientId] <String>] [[-FSCMinimumVersion] <String>]
[-ProgressAction <ActionPreference>] [<CommonParameters>]
```

## DESCRIPTION
This uploads the D365FSC nugets from the LCS to the active NuGet storage account

## EXAMPLES

### EXAMPLE 1
```
Update-FSCPSNugetsFromLCS -LCSUserName "[email protected]" -LCSUserPassword "superSecureString" -LCSProjectId "123456" -LCSClientId "123ebf68-a86d-4392-ae38-57b2172ee789" -FSCMinimumVersion "10.0.38"
```

this will uploads the D365FSC nugets from the LCS to the active storage account

## PARAMETERS

### -LCSUserName
The LCS username

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -LCSUserPassword
The LCS password
```yaml
Type: SecureString
Parameter Sets: (All)
Aliases:

Required: False
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -LCSProjectId
The LCS project ID
```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 3
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -LCSClientId
The ClientId what has access to the LCS
```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 4
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -FSCMinimumVersion
The minimum version of the FSC to update the NuGet\`s
```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 5
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -ProgressAction
{{ Fill ProgressAction Description }}
```yaml
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
## OUTPUTS
## NOTES
Author: Oleksandr Nikolaiev (@onikolaiev)
## RELATED LINKS
8 changes: 4 additions & 4 deletions fscps.tools/fscps.tools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Oleksandr Nikolaiev
#
# Generated on: 7/15/2024
# Generated on: 12/30/2024
#

@{
Expand All @@ -12,7 +12,7 @@
RootModule = 'fscps.tools.psm1'

# Version number of this module.
ModuleVersion = '1.0.263'
ModuleVersion = '1.0.274'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand All @@ -27,7 +27,7 @@ Author = 'Oleksandr Nikolaiev'
CompanyName = 'Ciellos Inc.'

# Copyright statement for this module
Copyright = 'Copyright (c) 2024 Oleksandr Nikolaiev. All rights reserved.'
Copyright = 'Copyright (c) 2025 Oleksandr Nikolaiev. All rights reserved.'

# Description of the functionality provided by this module
Description = 'fscps.tools'
Expand Down Expand Up @@ -84,7 +84,7 @@ FunctionsToExport = 'Get-FSCPSSettings', 'Set-FSCPSSettings', 'Invoke-FSCPSChoco
'Set-FSCPSActiveAzureStorageConfig',
'Invoke-FSCPSAzureStorageDownload',
'Invoke-FSCPSAzureStorageUpload', 'Invoke-FSCPSAzureStorageDelete',
'Update-FSCPSISVSource'
'Update-FSCPSISVSource', 'Update-FSCPSNugetsFromLCS'

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()
Expand Down
178 changes: 178 additions & 0 deletions fscps.tools/functions/update-fscpsnugetsfromlcs.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@

<#
.SYNOPSIS
This uploads the D365FSC nugets from the LCS to the active storage account
.DESCRIPTION
This uploads the D365FSC nugets from the LCS to the active NuGet storage account
.PARAMETER LCSUserName
The LCS username
.PARAMETER LCSUserPassword
The LCS password
.PARAMETER LCSProjectId
The LCS project ID
.PARAMETER LCSClientId
The ClientId what has access to the LCS
.PARAMETER FSCMinimumVersion
The minimum version of the FSC to update the NuGet`s
.EXAMPLE
PS C:\> Update-FSCPSNugetsFromLCS -LCSUserName "[email protected]" -LCSUserPassword "superSecureString" -LCSProjectId "123456" -LCSClientId "123ebf68-a86d-4392-ae38-57b2172ee789" -FSCMinimumVersion "10.0.38"
this will uploads the D365FSC nugets from the LCS to the active storage account
.NOTES
Author: Oleksandr Nikolaiev (@onikolaiev)
#>
function Update-FSCPSNugetsFromLCS {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
[CmdletBinding()]
param(
[Parameter()]
[string]$LCSUserName,
[Parameter()]
[SecureString]$LCSUserPassword,
[Parameter()]
[string]$LCSProjectId,
[Parameter()]
[string]$LCSClientId,
[Parameter()]
[string]$FSCMinimumVersion
)

begin{
Invoke-TimeSignal -Start
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($LCSUserPassword)
$UnsecureLCSUserPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)

Get-D365LcsApiToken -ClientId $LCSClientId -Username $LCSUserName -Password $UnsecureLCSUserPassword -LcsApiUri "https://lcsapi.lcs.dynamics.com" | Set-D365LcsApiConfig -ProjectId $LCSProjectId -ClientId $LCSClientId

}
process{

try
{

Get-D365LcsApiConfig
$assetList = Get-D365LcsSharedAssetFile -FileType NuGetPackage

$assetList | Sort-Object{$_.ModifiedDate} | ForEach-Object {
#$fileName = $_.FileName

$fscVersion = Get-FSCVersionFromPackageName $_.Name
if($fscVersion -gt $FSCMinimumVersion -and $fscVersion.Length -gt 6)
{
Write-PSFMessage -Level Host -Message "#################### $fscVersion #####################"
try
{
#ProcessingNuGet -FSCVersion $fscVersion -AssetId $_.Id -AssetName $fileName -ProjectId $lcsProjectId -LCSToken $lcstoken -StorageSAStoken $StorageSAStoken -LCSAssetName $_.Name
}
catch
{
$_.Exception.Message
}
}
}

<#
$assetList = Get-D365LcsSharedAssetFile -FileType NuGetPackage
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$destinationNugetFilePath = Join-Path $PackageDestination $AssetName
#get download link asset
$uri = "https://lcsapi.lcs.dynamics.com/box/fileasset/GetFileAsset/$($ProjectId)?assetId=$($AssetId)"
$assetJson = (Invoke-RestMethod -Method Get -Uri $uri -Headers $header)
if(Test-Path $destinationNugetFilePath)
{
$regex = [regex] "\b(([0-9]*[0-9])\.){3}(?:[0-9]*[0-9]?)\b"
$filenameVersion = $regex.Match($AssetName).Value
$version = Get-NuGetVersion $destinationNugetFilePath
if($filenameVersion -ne "")
{
$newdestinationNugetFilePath = ($destinationNugetFilePath).Replace(".$filenameVersion.nupkg", ".nupkg")
}
else { $newdestinationNugetFilePath = $destinationNugetFilePath }
$newdestinationNugetFilePath = ($newdestinationNugetFilePath).Replace(".nupkg",".$version.nupkg")
if(-not(Test-Path $newdestinationNugetFilePath))
{
Rename-Item -Path $destinationNugetFilePath -NewName ([System.IO.DirectoryInfo]$newdestinationNugetFilePath).FullName -Force -PassThru
}
$destinationNugetFilePath = $newdestinationNugetFilePath
}
$download = (-not(Test-Path $destinationNugetFilePath))
$blob = Get-AzStorageBlob -Context $ctx -Container $storageContainer -Blob $AssetName -ConcurrentTaskCount 10 -ErrorAction SilentlyContinue
if(!$blob)
{
if($download)
{
Invoke-D365AzCopyTransfer -SourceUri $assetJson.FileLocation -DestinationUri "$destinationNugetFilePath"
if(Test-Path $destinationNugetFilePath)
{
$regex = [regex] "\b(([0-9]*[0-9])\.){3}(?:[0-9]*[0-9]?)\b"
$filenameVersion = $regex.Match($AssetName).Value
$version = Get-NuGetVersion $destinationNugetFilePath
if($filenameVersion -ne "")
{
$newdestinationNugetFilePath = ($destinationNugetFilePath).Replace(".$filenameVersion.nupkg", ".nupkg")
}
else { $newdestinationNugetFilePath = $destinationNugetFilePath }
$newdestinationNugetFilePath = ($newdestinationNugetFilePath).Replace(".nupkg",".$version.nupkg")
if(-not(Test-Path $newdestinationNugetFilePath))
{
Rename-Item -Path $destinationNugetFilePath -NewName ([System.IO.DirectoryInfo]$newdestinationNugetFilePath).FullName -Force -PassThru
}
$destinationNugetFilePath = $newdestinationNugetFilePath
}
#Invoke-D365AzCopyTransfer $assetJson.FileLocation "$destinationNugetFilePath"
}
}
else
{
if($download)
{
$blob = Get-AzStorageBlobContent -Context $ctx -Container $storageContainer -Blob $AssetName -Destination $destinationNugetFilePath -ConcurrentTaskCount 10 -Force
$blob.Name
}
Write-PSFMessage -Level Host "Blob was found!"
}
$regex = [regex] "\b(([0-9]*[0-9])\.){3}(?:[0-9]*[0-9]?)\b"
$filenameVersion = $regex.Match($AssetName).Value
$version = Get-NuGetVersion $destinationNugetFilePath
$AssetName = ($AssetName).Replace(".$filenameVersion.nupkg", ".nupkg")
$AssetName = ($AssetName).Replace(".nupkg",".$version.nupkg")
Write-PSFMessage -Level Host "FSCVersion: $FSCVersion"
Write-PSFMessage -Level Host "AssetName: $AssetName"
Set-AzStorageBlobContent -Context $ctx -Container $storageContainer -Blob "$AssetName" -File "$destinationNugetFilePath" -StandardBlobTier Hot -ConcurrentTaskCount 10 -Force
#>


}
catch {
Write-PSFMessage -Level Host -Message "Something went wrong while updating D365FSC package versiob" -Exception $PSItem.Exception
Stop-PSFFunction -Message "Stopping because of errors" -EnableException $true
return
}
finally{

}

}
end{
Invoke-TimeSignal -End
}
}
4 changes: 3 additions & 1 deletion fscps.tools/internal/configurations/configuration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ Set-PSFConfig -FullName 'fscps.tools.settings.github.azVmrg' -Value '' -Initiali

Set-PSFConfig -FullName 'fscps.tools.settings.all.artifactsPath' -Value '' -Initialize -Description 'The destination artifacts path'
Set-PSFConfig -FullName 'fscps.tools.settings.all.artifactsFolderName' -Value 'artifacts' -Initialize -Description 'The name of the folder contains the result artifacts'
Set-PSFConfig -FullName 'fscps.tools.settings.all.generatePackages' -Value $true -Initialize -Description 'Option to generate a package after build.'
Set-PSFConfig -FullName 'fscps.tools.settings.all.generatePackages' -Value $true -Initialize -Description 'Option to enable a packages generation functionality. Default / TRUE'
Set-PSFConfig -FullName 'fscps.tools.settings.all.createRegularPackage' -Value $true -Initialize -Description 'Option to generate an LCS Deployable Package after build. The "generatePackages" option should be enabled. Default / TRUE'
Set-PSFConfig -FullName 'fscps.tools.settings.all.createCloudPackage' -Value $false -Initialize -Description 'Option to generate a Power Platform Unified Package after build. The "generatePackages" option should be enabled. Default / FALSE'
Set-PSFConfig -FullName 'fscps.tools.settings.all.namingStrategy' -Value 'Default' -Initialize -Description 'The package naming strategy. Custom value means the result package will have the name specified in the packageName variable. Default / Custom'
Set-PSFConfig -FullName 'fscps.tools.settings.all.packageNamePattern' -Value 'BRANCHNAME-PACKAGENAME-FNSCMVERSION_DATE.RUNNUMBER' -Initialize -Description ''
Set-PSFConfig -FullName 'fscps.tools.settings.all.packageName' -Value '' -Initialize -Description 'Name of the package'
Expand Down
Loading

0 comments on commit 20a4dc8

Please sign in to comment.