updating for appveyor build and publishing to gallery

This commit is contained in:
Dan Cuomo 2020-02-01 12:34:57 -08:00
Родитель d76ef1516c
Коммит 7429652410
9 изменённых файлов: 300 добавлений и 6 удалений

10
.gitignore поставляемый
Просмотреть файл

@ -3,11 +3,15 @@
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
DSCResource.Tests/
Results/*.xml
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
launch.json
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
@ -221,7 +225,7 @@ ClientBin/
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
@ -317,7 +321,7 @@ __pycache__/
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
@ -326,5 +330,5 @@ ASALocalRun/
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
# MFractors (Xamarin productivity tool) working folder
.mfractor/

Просмотреть файл

@ -3,7 +3,7 @@
#
# Generated by: Dan Cuomo
#
# Generated on: 7/20/2019
# Generated on: 1/2/2020
#
@{
@ -12,13 +12,13 @@
RootModule = 'Convert-LBFO2SET.psm1'
# Version number of this module.
ModuleVersion = '2019.07.20.0'
ModuleVersion = '2020.2.1.0'
# Supported PSEditions
# CompatiblePSEditions = @()
# ID used to uniquely identify this module
GUID = '958f6819-b97f-4816-b702-181a13d927ef'
GUID = '145ef927-fa91-474a-9078-29f88f095e5c'
# Author of this module
Author = 'Dan Cuomo'

Просмотреть файл

@ -1,3 +1,6 @@
[![Build status](https://ci.appveyor.com/api/projects/status/y6682ir5f5nj28in?svg=true)](https://ci.appveyor.com/project/MSFTCoreNet/convert-lbfo2set)
[![downloads](https://img.shields.io/powershellgallery/dt/Convert-LBFO2SET.svg?label=downloads)](https://www.powershellgallery.com/packages/Convert-LBFO2SET)
# Overview
For more information, including how to use this tool, please see [the Wiki](https://github.com/microsoft/Convert-LBFO2SET/wiki)

67
appveyor.yml Normal file
Просмотреть файл

@ -0,0 +1,67 @@
# YAML Reference Guide : https://www.appveyor.com/docs/appveyor-yml/
# Environmental Variables Guide : https://www.appveyor.com/docs/environment-variables/
# YAML Validator : https://ci.appveyor.com/tools/validate-yaml
# AppVeyor Build Pipeline : https://www.appveyor.com/docs/build-configuration/
# GitHub push with tokens : https://www.appveyor.com/docs/how-to/git-push/
# Repo cloned into this folder on the build worker
clone_folder: c:\projects\Convert-LBFO2SET
# Convert-LBFO2SET uses date-based versioning.
# Version will be of format: yyyy.MM.dd.Build Number e.g. 2019.06.09.buildNumber
init:
- ps: $Env:repoName = $($env:APPVEYOR_REPO_NAME.Split('/')[1])
- ps: $date = Get-Date
- ps: Update-AppveyorBuild -Version "$($date.year).$($date.month).$($date.day).$env:appveyor_build_number"
- ps: $Env:BuildVersion = "$($date.year).$($date.month).$($date.day).$env:appveyor_build_number"
# Install script prior to running tests
install:
- ps: . .\tests\build\setup\install.ps1
# Initiate tests
test_script:
- ps: . .\tests\build\setup\initiate-tests.ps1
# finalize build
deploy_script:
- ps: . .\tests\build\setup\deploy.ps1
version: '{build}'
image:
- Visual Studio 2017
# Environment variables for PowerShell Gallery (NuGetAPIKey) and GitHub (GitHubKey) API key for publishing updates
# - The "secure:" value is the Appveyor encryption of the key
# - GitHub update occurs to ensure that the module version is incremented based on the build number
#CoreNetBuilder
environment:
NuGetApiKey:
secure: Kz5VZnHxQlD/mHk0dlvpxTN1isiwW9A5fWhRdL7a1vcGwbVHFyj/x9wrIkqpAkcf
GitHubKey:
secure: qpQkQoAMAquwRIDJtJT9rD8JZTVlNxAfOFqUgrsbCJy6C8AY0jFHMGap18SxmH+F
APPVEYOR_RDP_PASSWORD:
secure: q9cNMN8o/tkzFDvDf+npkj5MOgFVGOLnJokZq/d4BUY=
# Disable automatic builds; Without this, the following error shows up:
# "Specify a project or solution file. The directory does not contain a project or solution file."
build: "off"
max_jobs: 1
# Ignore testing a commit if specific strings used in commit message: updated readme, update readme, update docs, update version, update appveyor
skip_commits:
message: /updated readme.*|update readme.*s|update docs.*|update version.*|update appveyor.*/
files:
- README.md
# There's no need to alter the build number for a Pull Request (PR) since they don't modify anything
pull_requests:
do_not_increment_build_number: true
#on_finish:
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

Просмотреть файл

@ -0,0 +1 @@


Просмотреть файл

@ -0,0 +1,98 @@
git config --global credential.helper store
Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:GitHubKey):x-oauth-basic@github.com`n"
git config --global user.email "NetwkBld@Microsoft.com"
git config --global user.name "CoreNet Build Svc"
git config --global core.autocrlf false
git config --global core.safecrlf false
# Line break for readability in AppVeyor console
Write-Host -Object ''
# Make sure we're using the Master branch and that it's not a pull request
# Environmental Variables Guide: https://www.appveyor.com/docs/environment-variables/
If ($env:APPVEYOR_REPO_BRANCH -ne 'master')
{
Write-Warning -Message "Skipping version increment and publish for branch $env:APPVEYOR_REPO_BRANCH"
}
elseif ($env:APPVEYOR_PULL_REQUEST_NUMBER -gt 0)
{
Write-Warning -Message "Skipping version increment and publish for pull request #$env:APPVEYOR_PULL_REQUEST_NUMBER"
}
else
{
# We're going to add 1 to the revision value since a new commit has been merged to Master
# This means that the major / minor / build values will be consistent across GitHub and the Gallery
Try
{
# This is where the module manifest lives
$manifestPath = ".\$($env:RepoName).psd1"
# Start by importing the manifest to determine the version, then add 1 to the revision
$manifest = Test-ModuleManifest -Path $manifestPath -ErrorAction SilentlyContinue
[System.Version]$version = $manifest.Version
Write-Output "Old Version: $version"
[String]$newVersion = $Env:BuildVersion
Write-Output "New Version: $newVersion"
# Update the manifest with the new version value and fix the weird string replace bug
#$functionList = ((Get-ChildItem -Path .\$($env:RepoName)).BaseName)
$splat = @{
'Path' = $manifestPath
'ModuleVersion' = $newVersion
#'FunctionsToExport' = $functionList
'Copyright' = "(c) $( (Get-Date).Year ) Inc. All rights reserved."
}
Update-ModuleManifest @splat -ErrorAction SilentlyContinue
(Get-Content -Path $manifestPath) -replace "PSGet_$($env:RepoName)", "$($env:RepoName)" | Set-Content -Path $manifestPath
(Get-Content -Path $manifestPath) -replace 'NewManifest', "$($env:RepoName)" | Set-Content -Path $manifestPath
#(Get-Content -Path $manifestPath) -replace 'FunctionsToExport = ', 'FunctionsToExport = @(' | Set-Content -Path $manifestPath -Force
#(Get-Content -Path $manifestPath) -replace "$($functionList[-1])'", "$($functionList[-1])')" | Set-Content -Path $manifestPath -Force
}
catch
{
throw $_
}
# Publish the new version to the PowerShell Gallery
Try
{
# Build a splat containing the required details and make sure to Stop for errors which will trigger the catch
$PM = @{
Path = '.'
NuGetApiKey = $env:NuGetApiKey
ErrorAction = 'Stop'
Force = $true
}
Publish-Module @PM
Write-Host "$($env:RepoName) PowerShell Module version $newVersion published to the PowerShell Gallery." -ForegroundColor Cyan
}
Catch
{
Write-Warning "Publishing update $newVersion to the PowerShell Gallery failed."
throw $_
}
# Publish the new version back to Master on GitHub
Try
{
# Set up a path to the git.exe cmd, import posh-git to give us control over git, and then push changes to GitHub
# Note that "update version" is included in the appveyor.yml file's "skip a build" regex to avoid a loop
$env:Path += ";$env:ProgramFiles\Git\cmd"
Import-Module posh-git -ErrorAction Stop
git checkout master -q
git add --all
git status
git commit -s -m "Update version to $newVersion"
git push origin master -q
Write-Host "$($env:RepoName) PowerShell Module version $newVersion published to GitHub." -ForegroundColor Cyan
}
Catch
{
Write-Warning "Publishing update $newVersion to GitHub failed."
throw $_
}
}

Просмотреть файл

@ -0,0 +1,14 @@
# Invoke Pester to run tests, then save the results in NUnitXML to populate the AppVeyor tests section
# Pester : https://github.com/pester/Pester/wiki
# Pester Code Coverage : https://info.sapien.com/index.php/scripting/scripting-modules/testing-pester-code-coverage
New-Item -Path .\tests -Name results -ItemType Directory -Force
$testResultPath = '.\tests\build\results\TestResults.xml'
# This is a manifest so no code coverage is possible. Original line kept below:
#...\results\TestsResults.xml -PassThru -CodeCoverage .\MSFTNetworking.Tools.psd1
$res = Invoke-Pester -Path ".\tests\build\unit" -OutputFormat NUnitXml -OutputFile $testResultPath -PassThru
(New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $testResultPath))
If ($res.FailedCount -gt 0) { throw "$($res.FailedCount) tests failed." }

Просмотреть файл

@ -0,0 +1,60 @@
git.exe clone -q https://github.com/PowerShell/DscResource.Tests
Import-Module -Name "$env:APPVEYOR_BUILD_FOLDER\DscResource.Tests\AppVeyor.psm1"
Invoke-AppveyorInstallTask
[string[]]$PowerShellModules = @("Pester", 'posh-git', 'psake', 'poshspec', 'PSScriptAnalyzer')
$ModuleManifest = Test-ModuleManifest .\$($env:RepoName).psd1 -ErrorAction SilentlyContinue
$repoRequiredModules = $ModuleManifest.RequiredModules.Name
$repoRequiredModules += $ModuleManifest.PrivateData.PSData.ExternalModuleDependencies
If ($repoRequiredModules) { $PowerShellModules += $repoRequiredModules }
# This section is taken care of by Invoke-AppVeyorInstallTask
<#[string[]]$PackageProviders = @('NuGet', 'PowerShellGet')
# Install package providers for PowerShell Modules
ForEach ($Provider in $PackageProviders) {
If (!(Get-PackageProvider $Provider -ErrorAction SilentlyContinue)) {
Install-PackageProvider $Provider -Force -ForceBootstrap -Scope CurrentUser
}
}#>
# Feature Installation
$serverFeatureList = @('Hyper-V')
If ($PowerShellModules -contains 'FailoverClusters') {
$serverFeatureList += 'RSAT-Clustering-Mgmt', 'RSAT-Clustering-PowerShell'
}
$BuildSystem = Get-CimInstance -ClassName 'Win32_OperatingSystem'
ForEach ($Module in $PowerShellModules) {
If ($Module -eq 'FailoverClusters') {
Switch -Wildcard ($BuildSystem.Caption) {
'*Windows 10*' {
Write-Output 'Build System is Windows 10'
Write-Output "Not Implemented"
# Get FailoverCluster Capability Name and Install on W10 Builds
$capabilityName = (Get-WindowsCapability -Online | Where-Object Name -like *RSAT*FailoverCluster.Management*).Name
Add-WindowsCapability -Name $capabilityName -Online
}
Default {
Write-Output "Build System is $($BuildSystem.Caption)"
Install-WindowsFeature -Name $serverFeatureList -IncludeManagementTools | Out-Null
}
}
}
ElseIf ($Module -eq 'Pester') {
Install-Module $Module -Scope AllUsers -Force -Repository PSGallery -AllowClobber -SkipPublisherCheck
}
else {
Install-Module $Module -Scope AllUsers -Force -Repository PSGallery -AllowClobber
}
Import-Module $Module
}

Просмотреть файл

@ -0,0 +1,47 @@
Describe "$($env:repoName)-Manifest" {
$DataFile = Import-PowerShellDataFile .\$($env:repoName).psd1 -ErrorAction SilentlyContinue
$TestModule = Test-ModuleManifest .\$($env:repoName).psd1 -ErrorAction SilentlyContinue
Context Manifest-Validation {
It "[Import-PowerShellDataFile] - $($env:repoName).psd1 is a valid PowerShell Data File" {
$DataFile | Should Not BeNullOrEmpty
}
It "[Test-ModuleManifest] - $($env:repoName).psd1 should pass the basic test" {
$TestModule | Should Not BeNullOrEmpty
}
Import-Module .\$($env:repoName).psd1 -Force -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
$command = Get-Command $($env:repoName) -ErrorAction SilentlyContinue
It "Should have the $($env:repoName) function available" {
$command | Should not BeNullOrEmpty
}
}
Context "Required Modules" {
'Pester' | ForEach-Object {
$module = Find-Module -Name $_ -ErrorAction SilentlyContinue
It "Should contain the $_ Module" {
$_ -in ($TestModule).RequiredModules.Name | Should be $true
}
It "The $_ module should be available in the PowerShell gallery" {
$module | Should not BeNullOrEmpty
}
Remove-Variable -Name Module -ErrorAction SilentlyContinue
}
}
Context ExportedContent {
$testCommand = Get-Command Convert-LBFO2SET
It 'Should default the AllowOutage param to $false' {
Get-Command Convert-LBFO2SET | Should -HaveParameter AllowOutage -DefaultValue $false
}
#TODO: Should test that LBFOTeam and SETTeam params are mandatory
}
}