Skip to content

Commit

Permalink
Pull from Dev Repo
Browse files Browse the repository at this point in the history
  • Loading branch information
epanipinto-jc committed Aug 18, 2020
1 parent b350ad3 commit 41dcbe4
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 89 deletions.
6 changes: 0 additions & 6 deletions PowerShell/Deploy/Build-HelpFiles.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
. ($PSScriptRoot + '/' + 'Get-Config.ps1')
###########################################################################
Write-Host ('[status]Importing current module: ' + $ModuleName)
Import-Module ($FilePath_psd1) -Force
# Install module onto system
If (-not (Get-InstalledModule -Name:('PlatyPS') -ErrorAction SilentlyContinue)) { Install-Module -Force -Name:('PlatyPS') }
# Import module into session
If (-not (Get-Module -Name:('PlatyPS'))) { Import-Module -Force -Name:('PlatyPS') }
Write-Host ('[status]Creating/Updating help files')
$Functions_Public | ForEach-Object {
$FunctionName = $_.BaseName
Expand Down
15 changes: 0 additions & 15 deletions PowerShell/Deploy/Functions/Create-ModuleManifest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,6 @@ Function New-JCModuleManifest
$FunctionParameters.Add($_.Key, $_.Value) | Out-Null
}
}
If ($FunctionParameters.RequiredModules)
{
$FunctionParameters.RequiredModules | ForEach-Object {
If ([System.String]::IsNullOrEmpty((Get-InstalledModule).Where( { $_.Name -eq $_ })))
{
Write-Host ('Installing: ' + $_)
Install-Module -Name:($_) -Force
}
If (!(Get-Module -Name:($_)))
{
Write-Host ('Importing: ' + $_)
Import-Module -Name:($_) -Force
}
}
}
}
Else
{
Expand Down
8 changes: 5 additions & 3 deletions PowerShell/Deploy/Functions/Get-PSGalleryModuleVersion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Function Get-PSGalleryModuleVersion
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1)][ValidateNotNullOrEmpty()][ValidateSet('Major', 'Minor', 'Patch', 'Manual')][string]$RELEASETYPE
)
# Check to see if module already exists to set version number
$PowerShellGalleryModule = Find-Module -Name:($Name) -ErrorAction:('Ignore')
$PowerShellGalleryModule = Find-Module -Repository:('PSGallery') -Name:($Name) -ErrorAction:('Ignore')
If ([string]::IsNullOrEmpty($PowerShellGalleryModule))
{
$ModuleVersion = [PSCustomObject]@{
Expand Down Expand Up @@ -48,10 +48,12 @@ Function Get-PSGalleryModuleVersion
}

}
if ($RELEASETYPE -eq 'Manual'){
if ($RELEASETYPE -eq 'Manual')
{
$NextVersion = ($Psd1).ModuleVersion
}
else {
Else
{
$NextVersion = ($ModuleVersion.Major, $ModuleVersion.Minor, $ModuleVersion.Patch) -join '.'
}
Add-Member -InputObject:($ModuleVersion) -MemberType:('NoteProperty') -Name:('NextVersion') -Value:($NextVersion)
Expand Down
55 changes: 23 additions & 32 deletions PowerShell/Deploy/Get-Config.ps1
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
# Log statuses
Write-Host ('[status]Platform: ' + [environment]::OSVersion.Platform)
Write-Host ('[status]PowerShell Version: ' + ($PSVersionTable.PSVersion -join '.'))
Write-Host ('[status]Host: ' + (Get-Host).Name)
Write-Host ('[status]Loaded config: ' + $MyInvocation.MyCommand.Path)
# Set variables from Azure Pipelines
# Define variables that come from Azure DevOps Pipeline
$ModuleName = $env:MODULENAME
$ModuleFolderName = $env:MODULEFOLDERNAME
$DEPLOYFOLDER = $env:DEPLOYFOLDER
$GitSourceBranch = $env:BUILD_SOURCEBRANCHNAME
$GitSourceRepo = $env:BUILD_REPOSITORY_URI
$StagingDirectory = $env:BUILD_ARTIFACTSTAGINGDIRECTORY
$GitSourceRepoWiki = $GitSourceRepo + '.wiki'
$ScriptRoot = Switch ($env:DEPLOYFOLDER) { $true { $env:DEPLOYFOLDER } Default { $PSScriptRoot } }
$FolderPath_ModuleRootPath = (Get-Item -Path:($ScriptRoot)).Parent.FullName
$GitSourceRepoWiki = "$($GitSourceRepo).wiki"
$RELEASETYPE = $env:RELEASETYPE
$XAPIKEY_PESTER = $env:XAPIKEY_PESTER
$XAPIKEY_MTP = $env:XAPIKEY_MTP
$NUGETAPIKEY = $env:NUGETAPIKEY
$EnvironmentConfig = 'TestEnvironmentVariables.ps1'
$SYSTEM_ACCESSTOKEN = $env:SYSTEM_ACCESSTOKEN
# Log statuses
Write-Host ('[status]Platform: ' + [environment]::OSVersion.Platform)
Write-Host ('[status]PowerShell Version: ' + ($PSVersionTable.PSVersion -join '.'))
Write-Host ('[status]Host: ' + (Get-Host).Name)
Write-Host ('[status]Loaded config: ' + $MyInvocation.MyCommand.Path)
# Set variables from Azure Pipelines
$ScriptRoot = Switch ($DEPLOYFOLDER) { $true { $DEPLOYFOLDER } Default { $PSScriptRoot } }
$FolderPath_ModuleRootPath = (Get-Item -Path:($ScriptRoot)).Parent.FullName
$GitHubWikiUrl = 'https://github.com/TheJumpCloud/support/wiki/'
$FilePath_ModuleBanner = $FolderPath_ModuleRootPath + '/ModuleBanner.md'
$FilePath_ModuleChangelog = $FolderPath_ModuleRootPath + '/ModuleChangelog.md'
# Define required files and folders variables
$RequiredFiles = ('LICENSE', 'psm1', 'psd1', 'PesterConfig')
$RequiredFiles = ('LICENSE', 'psm1', 'psd1')
$RequiredFolders = ('Docs', 'Private', 'Public', 'Tests', 'en-US')
# Define folder path variables
$FolderPath_Module = $FolderPath_ModuleRootPath + '/' + $ModuleFolderName
Expand All @@ -32,32 +34,21 @@ $RequiredFolders | ForEach-Object {
New-Variable -Name:('FolderPath_' + $_.Replace('-', '')) -Value:($FolderPath) -Force
}
$RequiredFiles | ForEach-Object {
$FileName = If ($_ -in ('psm1', 'psd1')) { $ModuleName + '.' + $_ } ElseIf ($_ -eq 'PesterConfig') { $EnvironmentConfig } Else { $_ }
$FilePath = If ($_ -eq 'PesterConfig') { $FolderPath_Module + '/' + $FolderName_Tests + '/' + $FileName } Else { $FolderPath_Module + '/' + $FileName }
$FileName = If ($_ -in ('psm1', 'psd1')) { $ModuleName + '.' + $_ } Else { $_ }
$FilePath = $FolderPath_Module + '/' + $FileName
New-Variable -Name:('FileName_' + $_) -Value:($FileName) -Force;
New-Variable -Name:('FilePath_' + $_) -Value:($FilePath) -Force;
}
# Get module function names
$Functions_Public = If (Test-Path -Path:($FolderPath_Public)) { Get-ChildItem -Path:($FolderPath_Public + '/' + '*.ps1') -Recurse }
$Functions_Private = If (Test-Path -Path:($FolderPath_Private)) { Get-ChildItem -Path:($FolderPath_Private + '/' + '*.ps1') -Recurse }
# Get psd1 contents
# Get .psd1 contents
$Psd1 = Import-PowerShellDataFile -Path:($FilePath_psd1)
$RequiredModules = $Psd1.RequiredModules
# Load deploy functions
$DeployFunctions = @(Get-ChildItem -Path:($PSScriptRoot + '/Functions/*.ps1') -Recurse)
Foreach ($DeployFunction In $DeployFunctions)
# Get module function names
$Functions_Public = If (Test-Path -Path:($FolderPath_Public))
{
Try
{
. $DeployFunction.FullName
}
Catch
{
Write-Error -Message:('Failed to import function: ' + $DeployFunction.FullName)
}
Get-ChildItem -Path:($FolderPath_Public + '/' + '*.ps1') -Recurse
}
# Install NuGet
If (!(Get-PackageProvider -Name:('NuGet') -ListAvailable -ErrorAction:('SilentlyContinue')))
$Functions_Private = If (Test-Path -Path:($FolderPath_Private))
{
Write-Host ('[status]Installing package provider NuGet'); Install-PackageProvider -Name:('NuGet') -Scope:('CurrentUser') -Force
Get-ChildItem -Path:($FolderPath_Private + '/' + '*.ps1') -Recurse
}
# Setup-Dependencies.ps1
.("$ScriptRoot/Setup-Dependencies.ps1")
64 changes: 56 additions & 8 deletions PowerShell/Deploy/SdkSync/jcapiToSupportSync.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,66 @@
. ((Get-Item -Path:($PSScriptRoot)).Parent.FullName + '/' + 'Get-Config.ps1')
###########################################################################
Install-Module -Name:('PSScriptAnalyzer') -Force
$ApprovedFunctions = [Ordered]@{
'JumpCloud.SDK.DirectoryInsights' = @(
[PSCustomObject]@{
Destination = '/Public/DirectoryInsights'
Name = 'Get-JcSdkEvent'
Name = 'Get-JcSdkEvent';
Destination = '/Public/DirectoryInsights';
},
[PSCustomObject]@{
Destination = '/Public/DirectoryInsights'
Name = 'Get-JcSdkEventCount'
Name = 'Get-JcSdkEventCount';
Destination = '/Public/DirectoryInsights';
}
)
);
# 'JumpCloud.SDK.V2' = @(
# [PSCustomObject]@{
# Name = 'Get-JcSdkAppleMdm';
# Destination = '/Public/AppleMdm';
# },
# [PSCustomObject]@{
# Name = 'Remove-JcSdkAppleMdm';
# Destination = '/Public/AppleMdm';
# },
# [PSCustomObject]@{
# Name = 'Set-JcSdkAppleMdm';
# Destination = '/Public/AppleMdm';
# },
# [PSCustomObject]@{
# Name = 'Get-JcSdkAppleMdmCsr';
# Destination = '/Public/AppleMdm';
# },
# [PSCustomObject]@{
# Name = 'Get-JcSdkAppleMdmDepKey';
# Destination = '/Public/AppleMdm';
# },
# [PSCustomObject]@{
# Name = 'Clear-JcSdkAppleMdmDevice';
# Destination = '/Public/AppleMdm';
# },
# [PSCustomObject]@{
# Name = 'Get-JcSdkAppleMdmDevice';
# Destination = '/Public/AppleMdm';
# },
# [PSCustomObject]@{
# Name = 'Lock-JcSdkAppleMdmDevice';
# Destination = '/Public/AppleMdm';
# },
# [PSCustomObject]@{
# Name = 'Restart-JcSdkAppleMdmDevice';
# Destination = '/Public/AppleMdm';
# },
# [PSCustomObject]@{
# Name = 'Stop-JcSdkAppleMdmDevice';
# Destination = '/Public/AppleMdm';
# },
# [PSCustomObject]@{
# Name = 'Sync-JcSdkAppleMdmDevice';
# Destination = '/Public/AppleMdm';
# },
# [PSCustomObject]@{
# Name = 'Get-JcSdkAppleMdmEnrollmentProfile';
# Destination = '/Public/AppleMdm';
# }
# )
}
$SdkPrefix = 'JcSdk'
$JumpCloudModulePrefix = 'JC'
Expand All @@ -21,9 +70,8 @@ $Divider = '|#|#|#|#|#|#|#|#|#|#|#|#|#|#|#|'
$FunctionTemplate = "{0}`nFunction {1}`n{{`n$($IndentChar){2}`n$($IndentChar)Param(`n{3}`n$($IndentChar))`n$($IndentChar)Begin`n$($IndentChar){{`n{4}`n$($IndentChar)}}`n$($IndentChar)Process`n$($IndentChar){{`n{5}`n$($IndentChar)}}`n$($IndentChar)End`n$($IndentChar){{`n{6}`n$($IndentChar)}}`n}}"
$ScriptAnalyzerResults = @()
$JumpCloudModulePath = (Get-Item -Path:($PSScriptRoot)).Parent.Parent.FullName + '/JumpCloud Module'
Import-Module -Name:($RequiredModules)
Get-Module -Refresh -ListAvailable -All | Out-Null
$Modules = Get-Module -Name:($RequiredModules | Where-Object { $_ -in $ApprovedFunctions.Keys })
$Modules = Get-Module -Name:($Psd1.RequiredModules | Where-Object { $_ -in $ApprovedFunctions.Keys })
If (-not [System.String]::IsNullOrEmpty($Modules))
{
ForEach ($Module In $Modules)
Expand Down
64 changes: 57 additions & 7 deletions PowerShell/Deploy/Setup-Dependencies.ps1
Original file line number Diff line number Diff line change
@@ -1,18 +1,68 @@
. ($PSScriptRoot + '/' + 'Get-Config.ps1')
###########################################################################
ForEach ($RequiredModule In $RequiredModules)
# Install NuGet
If (!(Get-PackageProvider -Name:('NuGet') -ListAvailable -ErrorAction:('SilentlyContinue')))
{
Write-Host("Setting up dependency '$RequiredModule'")
Write-Host ('[status]Installing package provider NuGet');
Install-PackageProvider -Name:('NuGet') -Scope:('CurrentUser') -Force
}
# Install dependent modules
$DependentModules = @('PSScriptAnalyzer', 'PlatyPS')
ForEach ($DependentModule In $DependentModules)
{
Write-Host("[status]Setting up dependency '$DependentModule'")
# Check to see if the module is installed
If ([System.String]::IsNullOrEmpty((Get-InstalledModule).Where( { $_.Name -eq $DependentModule })))
{
Write-Host("[status]Installing '$DependentModule' from 'PSGallery'")
Install-Module -Repository:('PSGallery') -Force -Name:($DependentModule) -Scope:('CurrentUser')
}
# Get-Module -Refresh -ListAvailable
If ([System.String]::IsNullOrEmpty((Get-Module).Where( { $_.Name -eq $DependentModule })))
{
Write-Host("[status]Importing '$DependentModule'")
Import-Module -Name:($DependentModule) -Force
}
}
# Register PSRepository
$Password = $SYSTEM_ACCESSTOKEN | ConvertTo-SecureString -AsPlainText -Force
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $SYSTEM_ACCESSTOKEN, $Password
If (-not (Get-PackageSource -Name:('JumpCloudPowershell-Dev') -ErrorAction SilentlyContinue))
{
Write-Host("[status]Register-PackageSource 'JumpCloudPowershell-Dev'")
Register-PackageSource -Trusted -ProviderName:("PowerShellGet") -Name:('JumpCloudPowershell-Dev') -Location:("https://pkgs.dev.azure.com/JumpCloudPowershell/_packaging/Dev/nuget/v2/") -Credential:($Credentials)
}
# Install required modules
ForEach ($RequiredModule In $Psd1.RequiredModules)
{
Write-Host("[status]Setting up dependency '$RequiredModule'")
# Check to see if the module is installed
If ([System.String]::IsNullOrEmpty((Get-InstalledModule).Where( { $_.Name -eq $RequiredModule })))
{
Write-Host("Installing '$RequiredModule'")
Install-Module -Name:($RequiredModule) -Force
Write-Host("[status]Installing '$RequiredModule' from 'JumpCloudPowershell-Dev'")
Install-Module -Repository:('JumpCloudPowershell-Dev') -AllowPrerelease -Force -Name:($RequiredModule) -Credential:($Credentials) -Scope:('CurrentUser')
}
# Get-Module -Refresh -ListAvailable
If ([System.String]::IsNullOrEmpty((Get-Module).Where( { $_.Name -eq $RequiredModule })))
{
Write-Host("Importing '$RequiredModule'")
Write-Host("[status]Importing '$RequiredModule'")
Import-Module -Name:($RequiredModule) -Force
}
}
# Load current module
If ([System.String]::IsNullOrEmpty((Get-Module).Where( { $_.Name -eq $ModuleName })))
{
Write-Host("[status]Importing '$ModuleName'")
Import-Module ($FilePath_psd1) -Force
}
# Load "Deploy" functions
$DeployFunctions = @(Get-ChildItem -Path:($PSScriptRoot + '/Functions/*.ps1') -Recurse)
Foreach ($DeployFunction In $DeployFunctions)
{
Try
{
. $DeployFunction.FullName
}
Catch
{
Write-Error -Message:('Failed to import function: ' + $DeployFunction.FullName)
}
}
2 changes: 0 additions & 2 deletions PowerShell/Deploy/Tests/PSScriptAnalyzer.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
# # }
# # Context 'PSScriptAnalyzer Tests' {
# # It 'Passes Invoke-PSScriptAnalyzer' {
Write-Host ('[status]Installing module: PSScriptAnalyzer')
Install-Module -Name:('PSScriptAnalyzer') -Force -Scope:('CurrentUser')
Write-Host ('[status]Running PSScriptAnalyzer on: ' + $FolderPath_Module)
$ScriptAnalyzerResults = Invoke-ScriptAnalyzer -Path:($FolderPath_Module) -Recurse
# # $ScriptAnalyzerResults | Should BeNullOrEmpty
Expand Down
2 changes: 1 addition & 1 deletion PowerShell/JumpCloud Module/ModuleUpdate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $GitHubWikiUrl = 'https://github.com/TheJumpCloud/support/wiki/'
Write-Host ('[status]Importing current module: ' + $ModuleName)
Import-Module ($FilePath_Psd1) -Force
Write-Host ('[status]Installing module: PlatyPS')
Install-Module -Name:('PlatyPS') -Force
Install-Module -Repository:('PSGallery') -Name:('PlatyPS') -Force
# Clear out existing docs
If (-not [System.String]::IsNullOrEmpty($IncludeList))
{
Expand Down
36 changes: 26 additions & 10 deletions PowerShell/JumpCloud Module/Tests/InvokePester.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ Param(
, [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1)][ValidateNotNullOrEmpty()][System.String]$JumpCloudApiKeyMsp
, [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, Position = 2)][System.String[]]$ExcludeTagList
, [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, Position = 3)][System.String[]]$IncludeTagList
, [Parameter(Mandatory = $false, ValueFromPipelineByPropertyName = $true, Position = 4)][System.String[]]$RequiredModulesRepo = 'PSGallery'
)
# Install Pester
Install-Module -Name:('Pester') -Force
# Install NuGet
If (!(Get-PackageProvider -Name:('NuGet') -ErrorAction:('SilentlyContinue')))
{
Install-PackageProvider NuGet -ForceBootstrap -Force | Out-Null
}
Install-Module -Repository:('PSGallery') -Name:('Pester') -Force
# Get list of tags and validate that tags have been applied
$PesterTests = Get-ChildItem -Path:($PSScriptRoot + '/*.Tests.ps1') -Recurse
$Tags = ForEach ($PesterTest In $PesterTests)
Expand Down Expand Up @@ -48,16 +44,36 @@ $RequiredModules = (Import-LocalizedData -BaseDirectory:($PesterParams_ModuleMan
If ($RequiredModules)
{
$RequiredModules | ForEach-Object {
If ([System.String]::IsNullOrEmpty((Get-InstalledModule).Where( { $_.Name -eq $_ })))
If ($RequiredModulesRepo -eq 'PSGallery')
{
If ([System.String]::IsNullOrEmpty((Get-InstalledModule).Where( { $_.Name -eq $_ })))
{
Write-Host ('[status]Installing: ' + $_)
Install-Module -Repository:($RequiredModulesRepo) -Name:($_) -Force
}
}
Else
{
Write-Host ('Installing: ' + $_)
Install-Module -Name:($_) -Force
If ([System.String]::IsNullOrEmpty((Get-InstalledModule).Where( { $_.Name -eq $_ })))
{
# Register PSRepository
$Password = $env:SYSTEM_ACCESSTOKEN | ConvertTo-SecureString -AsPlainText -Force
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $env:SYSTEM_ACCESSTOKEN, $Password
If (-not (Get-PackageSource -Name:('JumpCloudPowershell-Dev') -ErrorAction SilentlyContinue))
{
Write-Host("[status]Register-PackageSource 'JumpCloudPowershell-Dev'")
Register-PackageSource -Trusted -ProviderName:("PowerShellGet") -Name:('JumpCloudPowershell-Dev') -Location:("https://pkgs.dev.azure.com/JumpCloudPowershell/_packaging/Dev/nuget/v2/") -Credential:($Credentials)
}
Write-Host ('[status]Installing: ' + $_)
Install-Module -Repository:($RequiredModulesRepo) -Name:($_) -Force -Credential:($Credentials) -AllowPrerelease
}
}
If (!(Get-Module -Name:($_)))
{
Write-Host ('Importing: ' + $_)
Write-Host ('[status]Importing: ' + $_)
Import-Module -Name:($_) -Force
}

}
}
# Import the module
Expand Down
Loading

0 comments on commit 41dcbe4

Please sign in to comment.