Skip to content
This repository was archived by the owner on Jul 6, 2022. It is now read-only.

Commit 045adbf

Browse files
authored
Modernize Build Pipeline (#48)
1 parent b6e791f commit 045adbf

7 files changed

Lines changed: 147 additions & 14 deletions

File tree

.drone.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
kind: pipeline
3+
type: docker
4+
name: Linux_PWSH7_Build
5+
6+
platform:
7+
os: linux
8+
arch: amd64
9+
10+
steps:
11+
- name: Environments
12+
image: mcr.microsoft.com/powershell:latest
13+
commands:
14+
- pwsh -NonInteractive -c "& {Import-Module './tools/DroneIO.psm1' -Verbose; Invoke-ShowEnv -Verbose}"
15+
- pwsh -NonInteractive -c "& {Import-Module './tools/DroneIO.psm1' -Verbose; Invoke-InstallDependencies -Verbose}"
16+
- name: LintTests
17+
image: mcr.microsoft.com/powershell:latest
18+
commands:
19+
- pwsh -NonInteractive -c "& {Import-Module './tools/DroneIO.psm1'; Invoke-InstallDependencies}"
20+
- pwsh -NonInteractive -c "& {Import-Module './tools/DroneIO.psm1'; Invoke-Linter}"
21+
- name: UnitTests
22+
image: mcr.microsoft.com/powershell:latest
23+
commands:
24+
- pwsh -NonInteractive -c "& {Import-Module './tools/DroneIO.psm1'; Invoke-InstallDependencies}"
25+
- pwsh -NonInteractive -c "& {Import-Module './tools/DroneIO.psm1'; Invoke-UnitTests}"
26+
- name: coverage
27+
image: plugins/codecov
28+
settings:
29+
token:
30+
from_secret: CodeCovToken
31+
files:
32+
- coverage.xml

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[![AppVeyor branch](https://img.shields.io/appveyor/ci/OCram85/PSCredentialStore/master.svg?style=plastic "Master Branch Build Status")](https://ci.appveyor.com/project/OCram85/pscredentialstore/branch/master)
22
[![AppVeyor tests branch](https://img.shields.io/appveyor/tests/OCram85/PSCredentialStore/master.svg?style=plastic "Pester Tests Results")](https://ci.appveyor.com/project/OCram85/pscredentialstore/branch/master/tests)
33
[![Coveralls github](https://img.shields.io/coveralls/github/OCram85/PSCredentialStore.svg?style=plastic "Coveralls.io Coverage Report")](https://coveralls.io/github/OCram85/PSCredentialStore?branch=master)
4+
[![codecov](https://codecov.io/gh/OCram85/PSCredentialStore/branch/master/graph/badge.svg)](https://codecov.io/gh/OCram85/PSCredentialStore)
45
[![PowerShell Gallery](https://img.shields.io/powershellgallery/v/PSCredentialStore.svg?style=plastic "PowershellGallery Published Version")](https://www.powershellgallery.com/packages/PSCredentialStore)
56
[![PowerShell Gallery](https://img.shields.io/powershellgallery/vpre/PSCredentialStore.svg?label=latest%20preview&style=plastic "PowershellGallery Latest Preview Version")](https://www.powershellgallery.com/packages/PSCredentialStore)
67
[![PowerShell Gallery](https://img.shields.io/powershellgallery/dt/PSCredentialStore.svg?style=plastic "PowershellGallery Downloads")](https://www.powershellgallery.com/packages/PSCredentialStore)
File renamed without changes.

appveyor.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# pre release version:
22
version: 1.0.{build}
33

4+
#cache:
5+
46
#branches:
57
# only:
68
# - master
@@ -9,9 +11,7 @@ version: 1.0.{build}
911

1012
skip_tags: true
1113

12-
#image: WMF 5
13-
# Test ne build image:
14-
image: Visual Studio 2017
14+
image: Visual Studio 2019
1515

1616
# Install pester module and init the Appveyor support.
1717

@@ -28,6 +28,8 @@ environment:
2828
secure: 835qfZIkC9mE7QhkYfOZVAdR8rZhPvxG8BO4CbeaelRQOhlqmaSr8G1DWRJzZ/bS
2929
CoverallsToken:
3030
secure: eTjWqHL48MBr8wp1rSgLrXHdtpfDV/uClacP3svlWJfCvn/zVokpuaMnWM5RoyIY
31+
CodeCovToken:
32+
secure: LJOvamWIlVORDE7120KcmWVkHxOFYBSN99linyICXXmXLtYm81K/31YeMGiPlgTm
3133

3234
build: false
3335

@@ -59,15 +61,14 @@ deploy:
5961
- provider: GitHub
6062
auth_token:
6163
secure: M+bBX5/nKdJB0eViP7xtrLVTwf3vGDUA9N2MMprZp2i+9ZR3CBVcJnSzJWUmalhB
62-
artifact: PSCredentialStore.zip # upload all NuGet packages to release assets
64+
artifact: PSCredentialStore.zip # upload all NuGet packages to release assets
6365
draft: false
6466
prerelease: false
6567
on:
66-
branch: master # build release on master branch changes
68+
branch: master # build release on master branch changes
6769

6870
after_deploy:
6971
- ps: Invoke-AppVeyorPSGallery -OnBranch 'master'
70-
7172
# Pause build until `lock` on desktop is deleted.
7273
#on_finish:
7374
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

src/PSCredentialStore.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
CompanyName = ''
2020

2121
# Copyright statement for this module
22-
Copyright = '(c) 2019 OCram85. All rights reserved.'
22+
Copyright = '(c) 2020 OCram85. All rights reserved.'
2323

2424
# Description of the functionality provided by this module
2525
Description = 'A simple credential manager to store and reuse multiple credential objects.'

tools/AppVeyor.psm1

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ Function Invoke-InstallDependencies() {
1616

1717
Process {
1818
Try {
19+
Write-Host 'Available PS modules are:' -ForegroundColor Green -BackgroundColor Black
20+
Get-Module -ListAvailable -Name Pester | Format-Table | Out-String
1921
Get-PackageProvider -ListAvailable
2022
Install-PackageProvider -Name NuGet -RequiredVersion '2.8.5.208' -Force -Verbose
2123
Import-PackageProvider -Name NuGet -RequiredVersion '2.8.5.208' -Force
22-
Install-Module -Name 'Pester' -Scope CurrentUser -RequiredVersion '4.4.2' -Force -SkipPublisherCheck -AllowClobber
23-
Install-Module -Name 'posh-git' -Scope CurrentUser -RequiredVersion '1.0.0-beta2' -Force -SkipPublisherCheck -AllowClobber -AllowPrerelease
24-
Install-Module -Name 'PSCoverage' -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber -RequiredVersion '1.0.78'
25-
Import-Module -Name 'Pester', 'posh-git' , 'PSCoverage'
24+
Write-Host 'Installing build deps...' -ForegroundColor Red -BackgroundColor Black
25+
Install-Module -Name 'Pester' -Scope CurrentUser -RequiredVersion '4.10.1' -Force -SkipPublisherCheck -AllowClobber -Verbose
26+
Install-Module -Name 'posh-git' -Scope CurrentUser -RequiredVersion '0.7.3' -Force -SkipPublisherCheck -AllowClobber
27+
Install-Module -Name 'PSCoverage' -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber -RequiredVersion '1.2.108' -Verbose
28+
Import-Module -Name 'posh-git'
29+
Remove-Module -Name 'Pester' -Force -ErrorAction SilentlyContinue
30+
Import-Module -Name 'Pester' -RequiredVersion '4.10.1' -Verbose -Force
31+
Import-Module -Name 'PSCoverage' -RequiredVersion '1.2.108' -Verbose -Force
2632
}
2733
Catch {
2834
$MsgParams = @{
@@ -33,7 +39,8 @@ Function Invoke-InstallDependencies() {
3339
Add-AppveyorMessage @MsgParams
3440
Throw $MsgParams.Message
3541
}
36-
42+
Write-Host 'Loaded PS modules are:' -ForegroundColor Green -BackgroundColor Black
43+
Get-Module -Name Pester | Format-Table | Out-String
3744
}
3845
}
3946
Function Invoke-AppVeyorBumpVersion() {
@@ -42,7 +49,7 @@ Function Invoke-AppVeyorBumpVersion() {
4249

4350
Write-Host "Listing Env Vars for debugging:" -ForegroundColor Black -BackgroundColor Yellow
4451
# Filter Results to prevent exposing secure vars.
45-
Get-ChildItem -Path "Env:*" | Where-Object { $_.name -notmatch "(NuGetToken|CoverallsToken)"} | Sort-Object -Property Name | Format-Table
52+
Get-ChildItem -Path "Env:*" | Where-Object { $_.name -notmatch "(NuGetToken|CoverallsToken|CodeCovToken)" } | Sort-Object -Property Name | Format-Table
4653

4754
Try {
4855
$ModManifest = Get-Content -Path (".\src\{0}.psd1" -f $CALLSIGN)
@@ -112,6 +119,7 @@ Function Invoke-AppVeyorTests() {
112119
Write-Warning -Message ('Could not find file: {0} !' -f $File.FullName)
113120
}
114121
}
122+
Write-Host '===== Preload done. =====' -ForegroundColor Black -BackgroundColor Yellow
115123
}
116124
catch {
117125
$_.Exception.Message | Write-Error
@@ -121,7 +129,7 @@ Function Invoke-AppVeyorTests() {
121129
#$testresults = Invoke-Pester -Path ( Get-ChildItem -Path ".\tests\*.Tests.ps1" -Recurse | Sort-Object -Property Name ) -ExcludeTag 'Disabled' -PassThru
122130
$srcFiles = Get-ChildItem -Path ".\src\*.ps1" -Recurse | Sort-Object -Property 'Name' | Select-Object -ExpandProperty 'FullName'
123131
$testFiles = Get-ChildItem -Path ".\tests\*.Tests.ps1" -Recurse | Sort-Object -Property 'Name' | Select-Object -ExpandProperty 'FullName'
124-
$TestResults = Invoke-Pester -Path $testFiles -CodeCoverage $srcFiles -PassThru
132+
$TestResults = Invoke-Pester -Path $testFiles -CodeCoverage $srcFiles -PassThru -CodeCoverageOutputFile ".\coverage.xml" -CodeCoverageOutputFileEncoding ascii -CodeCoverageOutputFileFormat JaCoCo
125133
ForEach ($Item in $TestResults.TestResult) {
126134
Switch ($Item.Result) {
127135
"Passed" {
@@ -193,6 +201,7 @@ Function Invoke-CoverageReport() {
193201
Publish-CoverageReport -CoverageReport $CoverageReport
194202
}
195203

204+
196205
Function Invoke-AppVeyorPSGallery() {
197206
[CmdletBinding()]
198207
Param(

tools/DroneIO.psm1

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
$Global:ProgressPreference = 'SilentlyContinue'
2+
3+
function Invoke-ShowEnv() {
4+
[CmdletBinding()]
5+
param()
6+
7+
process {
8+
Get-ChildItem -Path 'Env:' | Format-Table | Out-String
9+
}
10+
}
11+
12+
function Invoke-InstallDependencies() {
13+
[CmdletBinding()]
14+
[OutputType()]
15+
param()
16+
17+
process {
18+
try {
19+
Install-Module -Name 'PSScriptAnalyzer' -Scope CurrentUser -RequiredVersion '1.19.1' -Force -SkipPublisherCheck -AllowClobber -Verbose:$VerbosePreference -ErrorAction 'Stop'
20+
Install-Module -Name 'Pester' -Scope CurrentUser -RequiredVersion '4.10.1' -Force -SkipPublisherCheck -AllowClobber -Verbose:$VerbosePreference -ErrorAction 'Stop'
21+
Install-Module -Name 'posh-git' -Scope CurrentUser -RequiredVersion '0.7.3' -Force -SkipPublisherCheck -AllowClobber -Verbose:$VerbosePreference -ErrorAction 'Stop'
22+
Install-Module -Name 'PSCoverage' -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber -RequiredVersion '1.2.108' -Verbose:$VerbosePreference -ErrorAction 'Stop'
23+
}
24+
catch {
25+
$ExceParams = @{
26+
Exception = [System.Exception]::new(
27+
'Could not install required build dependencies!',
28+
$PSItem.Exception
29+
)
30+
ErrorAction = 'Stop'
31+
}
32+
Write-Error @ExceParams
33+
}
34+
35+
}
36+
}
37+
38+
function Invoke-Linter () {
39+
[CmdletBinding()]
40+
param()
41+
42+
process {
43+
$LintRes = Invoke-ScriptAnalyzer -Path './src/' -Recurse
44+
if (-not ($Env:CI_COMMIT_MESSAGE -match 'SkipLint')) {
45+
if ($LintRes ) {
46+
$LintRes | Format-List
47+
Write-Error -Message 'Lint Errors found!' -ErrorAction Stop
48+
}
49+
else {
50+
Write-Host '== No Lint Errors found! =='
51+
}
52+
}
53+
}
54+
}
55+
56+
function Invoke-UnitTests {
57+
[CmdletBinding()]
58+
Param()
59+
60+
process {
61+
62+
try {
63+
Write-Host '===== Preload internal private functions =====' -ForegroundColor Black -BackgroundColor Yellow
64+
65+
$Privates = Get-ChildItem -Path (Join-Path -Path $Env:DRONE_WORKSPACE -ChildPath '/src/Private/*') -Include "*.ps1" -Recurse -ErrorAction Stop
66+
foreach ($File in $Privates) {
67+
if (Test-Path -Path $File.FullName) {
68+
. $File.FullName
69+
Write-Verbose -Message ('Private function dot-sourced: {0}' -f $File.FullName) -Verbose
70+
}
71+
else {
72+
Write-Warning -Message ('Could not find file: {0} !' -f $File.FullName)
73+
}
74+
}
75+
}
76+
catch {
77+
$_.Exception.Message | Write-Error
78+
throw 'Could not load required private functions!'
79+
}
80+
81+
Write-Host '===== Running Pester =====' -ForegroundColor Black -BackgroundColor Yellow
82+
$srcFiles = Get-ChildItem -Path "./src/*.ps1" -Recurse | Sort-Object -Property 'Name' | Select-Object -ExpandProperty 'FullName'
83+
$TestFiles = Get-ChildItem -Path (Join-Path -Path '.' -ChildPath './tests/*.Tests.ps1') -Recurse | Sort-Object -Property Name
84+
$TestResults = Invoke-Pester -Path $testFiles -CodeCoverage $srcFiles -PassThru -CodeCoverageOutputFile "./coverage.xml" -CodeCoverageOutputFileEncoding ascii -CodeCoverageOutputFileFormat JaCoCo
85+
86+
if ($TestResults.FailedCount -gt 0) {
87+
throw ('{0} tests failed!' -f $TestResults.FailedCount)
88+
}
89+
}
90+
}

0 commit comments

Comments
 (0)