diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..86dc3fe --- /dev/null +++ b/.gitignore @@ -0,0 +1,46 @@ + + +# packer +**/packer_cache/**/* +**/packer_builds/**/* +**/packer_boxes/**/* +**/packer/build/**/* + +# vagrant +**/.vagrant/**/* +**/.vagrant.d/**/* + +# puppet +**/puppet/ssl/**/* + +# kitchen +**/.kitchen/**/* + +**/.uplift.vagrant.yaml + +uplift-download/repo + +gocd/server/godata +uplift-download/uplift-repository + +node_modules +**/.build/**/* +.build + +**/*.gem +uplift-packer\packer\packer_templates + +uplift-packer/packer-ci-build/**/* +uplift-vagrant/vagrant-uplift/Gemfile.lock + +Gemfile.lock + +# all build folders +build-* + +# all output folders +output + +# all uplift local repositories +uplift-local-repository +uplift-local-resources \ No newline at end of file diff --git a/README.md b/README.md index 3ca972d..8540900 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,12 @@ This repository contains reusable PowerShell modules used in the uplift project. The uplift project offers consistent Packer/Vagrant workflows and Vagrant boxes specifically designed for SharePoint professionals. It heavy lifts low-level details of the creation of domain controllers, SQL servers, SharePoint farms and Visual Studio installs by providing a codified workflow using Packer/Vagrant tooling. +## Build status +| Branch | Status | +| ------------- | ------------- | +| master| [![Build status](https://ci.appveyor.com/api/projects/status/4khhqjvhbscpt3qc/branch/master?svg=true)](https://ci.appveyor.com/project/SubPointSupport/uplift-powershell/branch/master) | +| beta | [![Build status](https://ci.appveyor.com/api/projects/status/4khhqjvhbscpt3qc/branch/beta?svg=true)](https://ci.appveyor.com/project/SubPointSupport/uplift-powershell/branch/beta) | +| dev | [![Build status](https://ci.appveyor.com/api/projects/status/4khhqjvhbscpt3qc/branch/dev?svg=true)](https://ci.appveyor.com/project/SubPointSupport/uplift-powershell/branch/dev) | ## How this works The uplift project is split into several repositories to address particular a piece of functionality: diff --git a/_shared/.build.ps1 b/_shared/.build.ps1 index 8d0132a..8d75614 100644 --- a/_shared/.build.ps1 +++ b/_shared/.build.ps1 @@ -50,7 +50,12 @@ task UnitTest { Write-Build Green " [~] Unit testing..." exec { - pwsh -c 'Invoke-Pester ./tests/unit* -EnableExit' + if($null -ne $script:PS6 ) { + pwsh -c 'Invoke-Pester ./tests/unit* -EnableExit' + } else { + Write-Build Green " [~] Using PowerShell" + powershell -c 'Invoke-Pester ./tests/unit* -EnableExit' + } } } @@ -60,7 +65,13 @@ task IntegrationTest { Write-Build Green " [~] Integration testing..." exec { - pwsh -c 'Invoke-Pester ./tests/integration* -EnableExit' + if($null -ne $script:PS6 ) { + Write-Build Green " [~] Using PS6" + pwsh -c 'Invoke-Pester ./tests/integration* -EnableExit' + } else { + Write-Build Green " [~] Using PowerShell" + powershell -c 'Invoke-Pester ./tests/integration* -EnableExit' + } } } @@ -93,9 +104,25 @@ task VersionModule { # PowerShell does not allow string value in the Version # It seems to map to .NET Version object, so no -alpha/-beta tags # $script:Version = "0.1.0-alpha$stamp" - - $script:Version = "0.1.$stamp" + $script:Version = "0.1.$stamp" + + if($null -ne $env:APPVEYOR_REPO_BRANCH) { + Write-Build Green " [~] Running under APPVEYOR branch: $($env:APPVEYOR_REPO_BRANCH)" + + if($env:APPVEYOR_REPO_BRANCH -ine "beta" -and $env:APPVEYOR_REPO_BRANCH -ine "master") { + Write-Build Green " skipping APPVEYOR versioning for branch: $($env:APPVEYOR_REPO_BRANCH)" + } else { + Write-Build Green " using APPVEYOR versioning for branch: $($env:APPVEYOR_REPO_BRANCH)" + + ## 1902.build-no + $stamp = Get-Date -f "yyMM" + $buildNumber = $env:APPVEYOR_BUILD_NUMBER; + + $script:Version = "0.2.$stamp.$buildNumber" + } + } + if($null -ne $buildVersion ) { Write-Build Yello " [+] Using version from params: $buildVersion" $script:Version = $buildVersion @@ -141,19 +168,19 @@ task BuildModule { # Synopsis: Installes a PowerShell module task InstallModule { - + Write-Build Green "[~] ensuring repository: $devRepositoryName" New-UpliftPSRepository $devRepositoryName ` $moduleRepositoryFolder ` $moduleRepositoryFolder - + Write-Build Green " [+] Fetching repo: $devRepositoryName" Get-PSRepository $devRepositoryName Write-Build Green " [~] Find-Module -Name $moduleName" Find-Module -Name $moduleName -Repository $devRepositoryName - Write-Build Green " [~] Install-Module -Name $moduleName -Force" + Write-Build Green " [~] Install-Module -Name $moduleName -Repository $devRepositoryName -Force" Install-Module -Name $moduleName -Repository $devRepositoryName -Force Write-Build Green " [~] Get-InstalledModule -Name $moduleName" @@ -189,6 +216,27 @@ task ValidateInstalledModule { # Synopsis: Publishes module to the giving repository task PublishModule { + if($null -ne $env:APPVEYOR_REPO_BRANCH) { + Write-Build Green " [~] Running under APPVEYOR branch: $($env:APPVEYOR_REPO_BRANCH)" + + if($env:APPVEYOR_REPO_BRANCH -ine "dev" -and $env:APPVEYOR_REPO_BRANCH -ine "beta" -and $env:APPVEYOR_REPO_BRANCH -ine "master") { + Write-Build Green " skipping publishing for branch: $($env:APPVEYOR_REPO_BRANCH)" + return; + } + + $repoNameEnvName = ("SPS_REPO_NAME_" + $env:APPVEYOR_REPO_BRANCH) + $repoSrcEnvName = ("SPS_REPO_SRC_" + $env:APPVEYOR_REPO_BRANCH) + $repoPushEnvName = ("SPS_REPO_PUSH_" + $env:APPVEYOR_REPO_BRANCH) + $repoKeyEnvName = ("SPS_REPO_KEY_" + $env:APPVEYOR_REPO_BRANCH) + + $publishRepoName = (get-item env:$repoNameEnvName).Value; + + $publishRepoSourceLocation = (get-item env:$repoSrcEnvName).Value; + $publishRepoPublishLocation = (get-item env:$repoPushEnvName).Value; + + $publishRepoNuGetApiKey = (get-item env:$repoKeyEnvName).Value; + } + Confirm-Variable "publishRepoName" $publishRepoName "publishRepoName" Confirm-Variable "publishRepoSourceLocation" $publishRepoSourceLocation "publishRepoSourceLocation" @@ -221,6 +269,11 @@ task PublishModule { Write-Build Green "Completed!" } +# Synopsis: Executes Appveyor specific setup +task AppveyorPrepare { + npm install http-server -g +} + # Synopsis: Runs PSScriptAnalyzer task AnalyzeModule { exec { @@ -251,4 +304,7 @@ task . DefaultBuild task QA AnalyzeModule, DefaultBuild, IntegrationTest # Synopsis: Default module publishing task -task ReleaseModule AnalyzeModule, DefaultBuild, IntegrationTest, PublishModule \ No newline at end of file +task ReleaseModule AnalyzeModule, DefaultBuild, IntegrationTest, PublishModule + +task Appveyor AppveyorPrepare, + ReleaseModule \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..9bfdb7c --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,7 @@ +test: off + +build_script: + - ps: Install-Module -Name InvokeBuild -Force + - ps: pwsh -c Install-Module -Name InvokeBuild -Force + - ps: cd $env:APPVEYOR_BUILD_FOLDER/invoke-uplift; pwsh -c invoke-build Appveyor + - ps: cd $env:APPVEYOR_BUILD_FOLDER/uplift.core; powershell -c invoke-build Appveyor \ No newline at end of file diff --git a/invoke-uplift/.build.ps1 b/invoke-uplift/.build.ps1 index d6ca230..b7b18b4 100644 --- a/invoke-uplift/.build.ps1 +++ b/invoke-uplift/.build.ps1 @@ -20,6 +20,8 @@ $moduleName = "InvokeUplift" . "$dirPath/../_shared/.build-helpers.ps1" . "$dirPath/../_shared/.build.ps1" +$script:PS6 = $true; + task PrepareResourceFiles -After PrepareModule { New-Item "$moduleFolder/$moduleName/resource-files" -ItemType directory -Force | Out-Null diff --git a/invoke-uplift/src/Invoke-Uplift-ActionResourceDownload.ps1 b/invoke-uplift/src/Invoke-Uplift-ActionResourceDownload.ps1 index 1a4ce42..2ea31f8 100644 --- a/invoke-uplift/src/Invoke-Uplift-ActionResourceDownload.ps1 +++ b/invoke-uplift/src/Invoke-Uplift-ActionResourceDownload.ps1 @@ -114,8 +114,8 @@ function Get-ResourceContainer($resource, $dstDir, $force = $false) { StagingDirPath = (Join-Path -Path $resourceDir -ChildPath "download-staging") StagingFilePath = (Join-Path -Path $resourceDir -ChildPath "download-staging" -AdditionalChildPath $resourceFileName) - CacheDirPath = (Join-Path -Path $resourceDir -ChildPath "download-cache") - CacheFilePath = (Join-Path -Path $resourceDir -ChildPath "download-cache" -AdditionalChildPath $resourceFileName) + CacheDirPath = (Join-Path -Path $resourceDir -ChildPath "cache") + CacheFilePath = (Join-Path -Path $resourceDir -ChildPath "cache" -AdditionalChildPath $resourceFileName) ResourceDirPath = $resourceDir DestinationPath = $dstDir @@ -171,7 +171,7 @@ function Invoke-ResourceFolderDownload($resourceContainer, $src, $dst) { Write-DebugMessage " -dst: $dst" # download - $preferredTool = Get-CommandOptionValue @("-t", "-tool") $null "wget" + $preferredTool = Get-CommandOptionValue @("-t", "-tool") $null $null Invoke-DownloadFile ` $src ` $dst ` diff --git a/invoke-uplift/src/Invoke-Uplift-ActionResourceDownloadLocal.ps1 b/invoke-uplift/src/Invoke-Uplift-ActionResourceDownloadLocal.ps1 index d20c886..c820001 100644 --- a/invoke-uplift/src/Invoke-Uplift-ActionResourceDownloadLocal.ps1 +++ b/invoke-uplift/src/Invoke-Uplift-ActionResourceDownloadLocal.ps1 @@ -35,7 +35,7 @@ function Get-LocalResourceContainer($resourceId, $dstDir, $force = $false) { Metadata = $null - CacheDirPath = (Join-Path -Path $resourceDir -ChildPath "download-cache") + CacheDirPath = (Join-Path -Path $resourceDir -ChildPath "cache") LocalRepositoryPath = $dstDir ResourceDirPath = $resourceDir @@ -132,7 +132,7 @@ function Invoke-LocalStagingDownload($resourceContainer) { Write-InfoMessage "[~] checking if /download-staging is OK" $result = Confirm-LocalFileValidity $resourceContainer.StagingFilePath - $preferredTool = Get-CommandOptionValue @("-t", "-tool") $null "wget" + $preferredTool = Get-CommandOptionValue @("-t", "-tool") $null $null if($result -eq $False) { Write-InfoMessage "[~] downloading files..." diff --git a/invoke-uplift/src/Invoke-Uplift-ActionResourceDownloadVS17.ps1 b/invoke-uplift/src/Invoke-Uplift-ActionResourceDownloadVS17.ps1 index 33c7843..b0daf55 100644 --- a/invoke-uplift/src/Invoke-Uplift-ActionResourceDownloadVS17.ps1 +++ b/invoke-uplift/src/Invoke-Uplift-ActionResourceDownloadVS17.ps1 @@ -131,7 +131,16 @@ function Invoke-DownloadResourceVS17Dist ($resourceContainer, $vsClientPath) { Write-InfoMessage "[~] ensuring vs layour folder" $vsClientPath = $resourceContainer.CacheFilePath - $layoutFolderPath = Join-Path -Path $resourceContainer.CacheDirPath -ChildPath "vs17-layout" + $layoutFolderPath = Join-Path -Path $resourceContainer.CacheDirPath -ChildPath "vs17" + + if($layoutFolderPath.Length -gt 80) { + + $help = "error 5007 when trying to install Visual Studio 2017 15.5.7 from offline layout folder - https://developercommunity.visualstudio.com/content/problem/292951/error-5007-when-trying-to-install-visual-studio-20.html" + $err = "Layout folder for VS17 is greater than 80 chars! - $help" + + Write-ErrorMessage $err + throw $err + } New-Folder $layoutFolderPath diff --git a/invoke-uplift/src/Invoke-Uplift-HTTP.ps1 b/invoke-uplift/src/Invoke-Uplift-HTTP.ps1 index ea4fc08..12e9c51 100644 --- a/invoke-uplift/src/Invoke-Uplift-HTTP.ps1 +++ b/invoke-uplift/src/Invoke-Uplift-HTTP.ps1 @@ -181,12 +181,16 @@ function Invoke-DownloadFile($src, $dst, $preferredTool = $null) { if( $tools.wget.IsAvailable -eq $True) { Invoke-DownloadFileAsWget $tools.wget $src $dst return + } else { + Write-DebugMessage "wget is not here, fallback: wget -> curl -> InvokeWebRequest" } # is curl available? if( $tools.curl.IsAvailable -eq $True) { Invoke-DownloadFileAsCurl $tools.curl $src $dst return + } else { + Write-DebugMessage "curl is not here, fallback: wget -> curl -> InvokeWebRequest" } # default is Invoke-WebRequest diff --git a/uplift.core/src/Uplift.Core.ps1 b/uplift.core/src/Uplift.Core.ps1 index 577fedb..3a9c6f3 100644 --- a/uplift.core/src/Uplift.Core.ps1 +++ b/uplift.core/src/Uplift.Core.ps1 @@ -750,11 +750,9 @@ function Repair-UpliftMachineKeys { $fileName = $file.Name if (!$fileName.EndsWith($machGUID)) { - cp "$machineKeyFolder\$fileName" "$machineKeyFolder\$fileName.OLD" + Copy-Item "$machineKeyFolder\$fileName" "$machineKeyFolder\$fileName.OLD" Rename-Item "$machineKeyFolder\$fileName" "$key1$machGUID" break - - } } @@ -767,7 +765,7 @@ function Repair-UpliftMachineKeys { $fileName = $file.Name if (!$fileName.EndsWith($machGUID)) { - cp "$machineKeyFolder\$fileName" "$machineKeyFolder\$fileName.OLD" + Copy-Item "$machineKeyFolder\$fileName" "$machineKeyFolder\$fileName.OLD" Rename-Item "$machineKeyFolder\$fileName" "$key2$machGUID" break diff --git a/uplift.core/tests/integration/Uplift.Core.Tests.ps1 b/uplift.core/tests/integration/Uplift.Core.Tests.ps1 index ccdeb72..1c9bdfc 100644 --- a/uplift.core/tests/integration/Uplift.Core.Tests.ps1 +++ b/uplift.core/tests/integration/Uplift.Core.Tests.ps1 @@ -7,12 +7,13 @@ $srcPath = Resolve-Path "$dirPath/../../src" $skipSourceInclude = $True -Describe 'uplift.core.integration' { - Context "Cdefault" { - It 'can import module' { - Import-Module Uplift.Core - } - } -} +Write-Host "PSHome: $PSHome" +Write-Host "Is64BitProcess: $([Environment]::Is64BitProcess)" + +Write-Host "Listing installed modules:" +Get-InstalledModule + +Write-Host "Importing module: Uplift.Core" +Import-Module Uplift.Core . $srcPath/../tests/unit/Uplift.Core.Tests.ps1 \ No newline at end of file