🧑💻 Improves Test Ergonomics #15
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Validate Changes | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
jobs: | |
lint-with-psscriptanalyzer: | |
name: Lint with PSScriptAnalyzer | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository code | |
uses: actions/checkout@v3 | |
- name: "Cache: Nested PSGallery Modules" | |
id: cacher | |
uses: actions/cache@v3 | |
with: | |
path: ./lib | |
key: lib-PSGallery-${{ hashFiles('./NuGet.PSGallery.config', './packages.PSGallery.config') }} | |
- name: Install NuGet | |
uses: nuget/[email protected] | |
if: steps.cacher.outputs.cache-hit != 'true' | |
with: | |
nuget-version: '6.x' | |
- name: Restore Nested PSGallery Modules | |
if: steps.cacher.outputs.cache-hit != 'true' | |
shell: pwsh | |
run: | | |
Set-PSRepository PSGallery -InstallationPolicy Trusted | |
./build/restore.ps1 | |
- name: Lint with PSScriptAnalyzer | |
shell: pwsh | |
run: ./build/lint.ps1 -CI -NoFail:([bool]"${{ secrets.MANDATE_LINT_SUCCESS != 'true' }}") | |
determine-version: | |
name: Determine Version with GitVersion | |
runs-on: ubuntu-latest | |
steps: | |
- name: Cache dotnet tools | |
id: cacher | |
uses: actions/cache@v3 | |
with: | |
path: | | |
${{ env.HOME }}/.dotnet/tools | |
${{ env.USERPROFILE }}\\.dotnet\\tools | |
key: ${{ runner.os }}-dotnet-tools-${{ hashFiles('**/global.json') }} | |
- name: dotnet tool install -g GitVersion.Tool | |
if: steps.cacher.outputs.cache-hit != 'true' | |
shell: pwsh | |
run: dotnet tool install --global GitVersion.Tool --version 5.12 | |
- name: Check out repository full history | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # GitVersion requires the full history to calculate the version. | |
- name: Show GitVersion configuration | |
shell: pwsh | |
run: dotnet-gitversion /showconfig | |
- name: Capture GitVersion configuration | |
shell: pwsh | |
run: | | |
New-Item -Path ./out -Type Directory -Force | Out-Null | |
dotnet-gitversion /showconfig | Out-File -Path ./out/GitVersion.effective.yml -Encoding UTF8 | |
- name: Determine version | |
shell: pwsh | |
run: | | |
dotnet-gitversion /output json | Out-File -Path ./out/version.json -Encoding UTF8 | |
[int] $gitversionExitCode = $LASTEXITCODE | |
if ($gitversionExitCode -ne 0) { | |
Write-Host "GitVersion failed. Re-running with diagnostic verbosity." | |
dotnet-gitversion /output json /verbosity diagnostic | |
exit $gitversionExitCode | |
} | |
- name: "Create artifact: version.json" | |
uses: actions/upload-artifact@v3 | |
with: | |
name: version.json | |
path: ./out/version.json | |
create-releasenotes: | |
name: Create Release Notes | |
needs: determine-version | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository full history | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # create-release-notes requires the full history to create the release notes. | |
- name: "Get artifact: version.json" | |
uses: actions/download-artifact@v2 | |
with: | |
name: version.json | |
path: ./out/ | |
- name: Populate version variables | |
id: gitversion_vars | |
shell: pwsh | |
run: | | |
[object] $version = Get-Content -Path ./out/version.json | ConvertFrom-Json | |
foreach ($key in $version.PSObject.Properties.Name) { | |
echo "::set-output name=$key::$($version.$key)" | |
} | |
- name: Create release notes | |
id: create_release_notes | |
uses: mikepenz/release-changelog-builder-action@v4 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
fromTag: ${{ steps.gitversion_vars.outputs.VersionSourceSha }} | |
toTag: ${{ steps.gitversion_vars.outputs.Sha }} | |
commitMode: true | |
outputFile: ./out/release-notes.md | |
- name: "Create artifact: release-notes.md" | |
uses: actions/upload-artifact@v2 | |
with: | |
name: release-notes.md | |
path: ./out/release-notes.md | |
build-release-package: | |
name: Build Release Package | |
needs: [create-releasenotes] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository code | |
uses: actions/checkout@v3 | |
- name: "Cache: Nested PSGallery Modules" | |
id: cacher | |
uses: actions/cache@v3 | |
with: | |
path: ./lib | |
key: lib-PSGallery-${{ hashFiles('./NuGet.PSGallery.config', './packages.PSGallery.config') }} | |
- name: Install NuGet | |
uses: nuget/[email protected] | |
if: steps.cacher.outputs.cache-hit != 'true' | |
with: | |
nuget-version: '6.x' | |
- name: Restore Nested PSGallery Modules | |
if: steps.cacher.outputs.cache-hit != 'true' | |
shell: pwsh | |
run: | | |
Set-PSRepository PSGallery -InstallationPolicy Trusted | |
./build/restore.ps1 | |
- name: "Get artifact: version.json" | |
uses: actions/download-artifact@v2 | |
with: | |
name: version.json | |
path: ./out/ | |
- name: Populate GitVersion variables | |
id: gitversion_vars | |
shell: pwsh | |
run: | | |
[object] $version = Get-Content -Raw -Path ./out/version.json -Encoding UTF8 | ConvertFrom-Json | |
foreach ($key in $version.PSObject.Properties.Name) { | |
echo "::set-output name=$key::$($version.$key)" | |
} | |
- name: "Get artifact: release-notes.md" | |
uses: actions/download-artifact@v2 | |
with: | |
name: release-notes.md | |
path: ./out/ | |
- name: Build PSGallery package | |
shell: pwsh | |
run: | | |
[string] $releaseNotes = (Get-Content -Raw -Path ./out/release-notes.md -Encoding UTF8).Trim() | |
[object] $version = Get-Content -Raw -Path ./out/version.json -Encoding UTF8 | ConvertFrom-Json | |
./build/package.ps1 -PackageVersionNuGet $version.NuGetVersionV2 -PackageVersionMajorMinorPatchBuild $version.AssemblySemVer -PackageVersionPrereleaseTag $version.PrereleaseTag -ReleaseNotes $releaseNotes -CommitSha $version.Sha | |
- name: "Create artifact: PSGallery-package" | |
uses: actions/upload-artifact@v3 | |
with: | |
name: PSGallery-package | |
path: ./out/*.nupkg | |
tests: | |
name: Test with Pester on ${{ matrix.os }} | |
continue-on-error: ${{ matrix.experimental == 'true' }} | |
strategy: | |
fail-fast: ${{ github.ref == 'refs/heads/main' }} | |
matrix: | |
# See: https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners | |
os: [ubuntu-latest, windows-latest, macos-latest, ubuntu-20.04, windows-2019] | |
include: | |
- os: windows-latest | |
codecov_os: windows | |
- os: ubuntu-latest | |
codecov_os: linux | |
- os: macos-latest | |
codecov_os: macos | |
experimental: true | |
- os: ubuntu-20.04 | |
codecov_os: linux | |
experimental: true | |
- os: windows-2019 | |
codecov_os: windows | |
experimental: true | |
runs-on: ${{ matrix.os }} | |
needs: build-release-package | |
steps: | |
- name: Check out repository code | |
uses: actions/checkout@v3 | |
- name: "Cache: Nested PSGallery Modules" | |
id: cacher | |
uses: actions/cache@v3 | |
with: | |
path: ./lib | |
key: lib-PSGallery-${{ hashFiles('./NuGet.PSGallery.config', './packages.PSGallery.config') }} | |
- name: Install NuGet | |
uses: nuget/[email protected] | |
if: steps.cacher.outputs.cache-hit != 'true' | |
with: | |
nuget-version: '6.x' | |
- name: Restore Nested PSGallery Modules | |
if: steps.cacher.outputs.cache-hit != 'true' | |
shell: pwsh | |
run: | | |
Set-PSRepository PSGallery -InstallationPolicy Trusted | |
./build/restore.ps1 | |
- name: "Get artifact: PSGallery-package" | |
uses: actions/download-artifact@v2 | |
with: | |
name: PSGallery-package | |
path: ./out/ | |
- name: Test with Pester | |
shell: pwsh | |
run: ./build/test.ps1 -UsePackageExport -CI -OutputFilesPrefix "${{ matrix.os }}-" -NoFail:([bool]"${{ matrix.experimental }}") | |
- name: "Create artifact: tests-${{ matrix.os }}" | |
uses: actions/upload-artifact@v3 | |
if: ${{ always() }} | |
with: | |
name: "tests-${{ matrix.os }}" | |
path: ./out/*.xml | |
- name: Upload coverage report to Codecov | |
uses: codecov/codecov-action@v3 | |
if: ${{ (github.ref == 'refs/heads/main') }} | |
with: | |
fail_ci_if_error: true | |
flags: ${{ matrix.codecov_os }},unittests | |
directory: ./out | |
files: "*coverage.xml" | |
os: ${{ matrix.codecov_os }} | |
env_vars: "OS" |