Use GitHub Actions for CI/CD (#31)

* added missing files

* hoping this fixes failures

* typo

* adding debug

* rejiggered

* add file extensions to path

* found the docs

* install modules

* install required modules in each script

* accurately name job

* force install modules

* Resolve linting issue

* Suppress Install-Module logs

* cd

* use xplat-safe path in tests

* test cd

* fix accessor violation with Version

* run sequentially

* integrate api key

* (hopefully) fix secret access

* Fix publish-module path

* cleaner

* better versioning

* bugfix versioning

* version bugfix

* set CD to run on deployment
format-checklist-fix
Chris Kuech 2019-09-12 17:34:31 -07:00 committed by GitHub
parent 393af07eea
commit e9cd39e0a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 102 additions and 11 deletions

18
.github/scripts/Assert-Linting.ps1 vendored Normal file
View File

@ -0,0 +1,18 @@
<#
.SYNOPSIS
Asserts that the repo has valid coding style
.DESCRIPTION
Runs PSScriptAnalyzer on all the PowerShell scripts in the repo, prints out the list of discovered issues, and
writes a message to the output stream associated with the highest-severity of issue found.
#>
Install-Module PSScriptAnalyzer -Force | Out-Null
Import-Module PSScriptAnalyzer
$RepoRoot = "$PSScriptRoot/../.."
$issues = Invoke-ScriptAnalyzer -Path $RepoRoot -Recurse
if ($issues) {
$issues | Format-Table
throw "Encountered $($issues.Count) linting issues"
}

20
.github/scripts/Assert-Tests.ps1 vendored Normal file
View File

@ -0,0 +1,20 @@
<#
.SYNOPSIS
Throws an error if any Pester tests fail
#>
Install-Module Pester -Force | Out-Null
Import-Module Pester
$RepoRoot = "$PSScriptRoot/../.."
Push-Location $RepoRoot
try {
$results = Invoke-Pester -PassThru
if ($results.FailedCount) {
throw "Unit Tests failed"
}
}
finally {
Pop-Location
}

24
.github/scripts/Publish-Module.ps1 vendored Normal file
View File

@ -0,0 +1,24 @@
<#
.SYNOPSIS
Throws an error if any Pester tests fail
#>
$InformationPreference = "Continue"
$Major = 2
$Minor = 2
$RepoRoot = "$PSScriptRoot/../.."
$ModuleManifestPath = "$RepoRoot/Requirements.psd1"
$current = [Version](Find-Module Requirements).Version
$newMinor = [version]"$Major.$Minor.0" # the version to use if we incremented Minor
$newBuild = [version]"$Major.$Minor.$($current.Build + 1)" # the version to use if we increment Build
$new = if ($newMinor -gt $current) { $newMinor } else { $newBuild }
$template = Get-Content $ModuleManifestPath -Raw
$expanded = $template -replace "{{ModuleVersion}}", $new
$expanded | Out-File $ModuleManifestPath -Force
Publish-Module -Path $RepoRoot -NuGetApiKey $env:PSGALLERY_NUGET_API_KEY -WhatIf

28
.github/workflows/cd.yml vendored Normal file
View File

@ -0,0 +1,28 @@
name: CD
on: deployment
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Assert Linting
shell: pwsh
run: ./.github/scripts/Assert-Linting
- name: Assert Tests
shell: pwsh
run: ./.github/scripts/Assert-Tests
publish:
needs: validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Publish Module
env:
PSGALLERY_NUGET_API_KEY: ${{ secrets.PSGALLERY_NUGET_API_KEY }}
shell: pwsh
run: ./.github/scripts/Publish-Module

View File

@ -1,15 +1,16 @@
name: CI
on: [push]
on: push
jobs:
build:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Lint
run: ./.github/Assert-ValidStyle
- name: Test
run: ./.github/Assert-ValidTests
- uses: actions/checkout@v1
- name: Assert Linting
shell: pwsh
run: ./.github/scripts/Assert-Linting
- name: Assert Tests
shell: pwsh
run: ./.github/scripts/Assert-Tests

View File

@ -4,7 +4,7 @@
RootModule = 'src\module.psm1'
# Version number of this module.
ModuleVersion = '2.2.4'
ModuleVersion = '{{ModuleVersion}}'
# Supported PSEditions
# CompatiblePSEditions = @()

View File

@ -20,7 +20,7 @@ Describe "formatters" {
Set = { }
}
$events = invoke $requirement
$tempContainer = if ($env:TEMP) { $env:TEMP } else { $env:TMPDIR }
$tempContainer = $PSScriptRoot
Context "Format-Table" {
$output = $events | Format-Table | Out-String
It "Should print a non-empty string" {