CI/Publish-script.ps1

Param(
    [Parameter(Mandatory=$true)]
    [string] $typeVersion,
    [Parameter(Mandatory=$true)]
    [string] $moduleDescription,
    [Parameter(Mandatory=$true)]
    [string] $SourcesDirectory,
    [Parameter(Mandatory=$true)]
    [string] $NuGetApiKey
)

Install-Module -Name PowerShellGet -Force 
Install-Module -Name PSScriptAnalyzer -Force
Install-Module -Name Pester -Force
Install-Module -Name BcContainerHelper -Force

Import-Module PSScriptAnalyzer
Invoke-ScriptAnalyzer -Path $SourcesDirectory\AL

$CurrentVersion = Find-Module -Name SMART-BcBuildHelper | Select-Object -ExpandProperty Version
$CurrentVersionBcContainerHelper = Find-Module -Name BcContainerHelper | Select-Object -ExpandProperty Version

$validParameters = @("major", "minor", "patch")
if ($validParameters -contains $typeVersion) {

  [int]$major, [int]$minor, [int]$patch = $currentVersion.Split(".")
  
  switch ($typeVersion) {
    "major" { $major++; $minor = 0; $patch = 0 }
    "minor" { $minor++; $patch = 0 }
    "patch" { $patch++ }
  }

  $newVersion = "$major.$minor.$patch"

  Write-Output "The version was changed from $currentVersion to $newVersion"

} 
New-ModuleManifest -Path $SourcesDirectory\AL\SMART-BcBuildHelper.psd1 -RootModule "SMART-BcBuildHelper.psm1" -ModuleVersion $newVersion -Author "SMART business" -CompanyName "SMART business" -Description $moduleDescription -RequiredModules @(@{ ModuleName = "BcContainerHelper"; ModuleVersion = $CurrentVersionBcContainerHelper}) -ReleaseNotes $newVersion -FunctionsToExport @("Get-BuildVersionFromArtifacts", "Copy-FileToAzureStorage", "Save-AppsToAzureStorage", "Copy-AppFilesToFolder", "Publish-BcAppToDevEndpoint", "Publish-ToAppsource", "Import-BcConfigurationPackage")
Rename-Item -Path "$SourcesDirectory\AL" -NewName "SMART-BcBuildHelper"
Publish-Module -Path $SourcesDirectory\SMART-BcBuildHelper -NuGetApiKey $NuGetApiKey -SkipAutomaticTags