Skip to content

Feature/pipeline-version-package-optimization #434

Feature/pipeline-version-package-optimization

Feature/pipeline-version-package-optimization #434

name: 'build module'
on:
workflow_dispatch:
push:
branches:
- trunk
paths:
- 'src/**'
- 'Tests/**'
- '.docs/**'
- '.github/'
- '!.github/images/'
- '!.github/*.md'
- '!.vscode/**'
- '!.devContainer/**'
- '!tools/**'
- '!.gitignore'
- '!LICENSE'
- '!*.md'
pull_request:
branches:
- trunk
jobs:
build-stage:
name: Build
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest,ubuntu-latest,macos-latest]
fail-fast: true
permissions:
checks: write
steps:
- name: Clone repo
uses: actions/checkout@v3
- name: Install and cache PowerShell modules
id: psmodulecache
uses: potatoqualitee/[email protected]
with:
modules-to-cache: Pester, PSScriptAnalyzer, SHiPS, Trackyon.Utils, Trackyon.Markdown, Metadata, platyPS
- name: .NET Restore
shell: pwsh
run: dotnet restore --no-cache # have to use no cache of the build will fail on Windows
- name: Build module
shell: pwsh
run: |
if ("${{ matrix.os }}" -eq 'ubuntu-latest') {
./Build-Module.ps1 -configuration Release -buildHelp
} else {
./Build-Module.ps1 -configuration Release
}
- name: Run C# unit tests
shell: pwsh
run: dotnet test --logger "trx;LogFileName=test-results.trx" --logger "console;verbosity=detailed"
# - name: Publish C# test results
# if: success() || failure()
# uses: dorny/test-reporter@v1
# with:
# name: C# tests results (${{ matrix.os }})
# path: '**/test-results.trx'
# reporter: dotnet-trx
- name: Run PowerShell unit tests
shell: pwsh
run: |
Import-Module ./dist/*.psd1
# This loads [PesterConfiguration] into scope
Import-Module Pester
$pesterArgs = [PesterConfiguration]::Default
$pesterArgs.Run.Exit = $true
$pesterArgs.Run.Throw = $true
$pesterArgs.Run.PassThru = $false
$pesterArgs.TestResult.Enabled = $true
$pesterArgs.Output.Verbosity = 'None'
$pesterArgs.Run.Path = './Tests/function'
$pesterArgs.TestResult.OutputFormat = 'JUnitXml'
$pesterArgs.TestResult.OutputPath = 'test-results.xml'
$env:VSTEAM_NO_UPDATE_MESSAGE = $true
$env:VSTEAM_NO_MODULE_MESSAGES = $true
Invoke-Pester -Configuration $pesterArgs
# - name: Publish PowerShell test results
# uses: dorny/test-reporter@v1
# with:
# name: PS tests results (${{ matrix.os }})
# path: '**/test-results.xml'
# reporter: jest-junit
- name: Copy files to staging folders
if: ${{ matrix.os == 'ubuntu-latest'}}
shell: pwsh
run: |
Copy-Item -Path "./dist/" -Destination ./staging/VSTeam/dist/ -Recurse -Force
Copy-Item -Path "./.gitignore","./README.md" -Destination ./staging/VSTeam/ -Recurse -Force
Copy-Item -Path "./Tests/SampleFiles/" -Destination ./staging/test/Tests/SampleFiles -Recurse -Force
Copy-Item -Path "./Tests/integration/tests/" -Destination ./staging/test/Tests/integration/tests -Recurse -Force
Copy-Item -Path "./tools/scripts/" -Destination ./staging/tools/scripts -Recurse -Force
Copy-Item -Path "./dist/*.psd1" -Destination ./staging/test/dist -Recurse -Force
- name: Run Static Code Analysis
if: ${{ matrix.os == 'ubuntu-latest'}}
shell: pwsh
run: |
Import-PowerShellDataFile ./dist/*.psd1 | Select-Object -ExpandProperty RequiredModules | Import-Module
$r = Invoke-ScriptAnalyzer -Path ./dist -Recurse | Where-Object severity -ne "Information"
$count = 0
$r | ForEach-Object {
Write-Host "::error file=$($_.ScriptPath),line=$($_.Line),col=$($_.Column)::$($_.Message)"
$count++
}
if ($count -ne 0) { throw "Static Code Analysis with error count = $count" }
- name: Publish Module
if: ${{ matrix.os == 'ubuntu-latest' && github.event_name != 'pull_request' }}
uses: actions/upload-artifact@v3
with:
name: module
path: "./staging/VSTeam"
- name: Publish unit tests
if: ${{ matrix.os == 'ubuntu-latest' && github.event_name != 'pull_request' }}
uses: actions/upload-artifact@v3
with:
name: test
path: "./staging/test"
- name: Publish pipeline scripts
if: ${{ matrix.os == 'ubuntu-latest' && github.event_name != 'pull_request' }}
uses: actions/upload-artifact@v3
with:
name: pipeline-scripts
path: "./staging/tools"
package-stage:
name: Package
uses: ./.github/workflows/reusable.package.yml
needs: build-stage
secrets:
ghToken: ${{ secrets.GITHUB_TOKEN }}
testing-stage:
name: Testing API
uses: ./.github/workflows/reusable.integration-tests.yml
needs: package-stage
with:
pesterVersion: '5.2.0'
secrets:
ghToken: ${{ secrets.GITHUB_TOKEN }}
publish-stage:
name: PowerShell Gallery
needs: testing-stage
environment: 'PowerShell Gallery'
runs-on: ubuntu-latest
env:
module_version: ""
steps:
- name: Download PS module artifact
uses: actions/download-artifact@v3
with:
name: module
path: ./module
- name: Download nuget package artifact
uses: actions/download-artifact@v3
with:
name: VSTeamPackage
path: ./nuget
- name: Download pipeline scripts
uses: actions/download-artifact@v3
with:
name: pipeline-scripts
path: ./tools
- name: Publish module
shell: pwsh
run: |
./Install-ModuleDependencies.ps1 -ModulePath "../../module/dist"
$version = ./Set-VersionNumber.ps1 -ModulePath "../../module"
echo "module_version=$version" | Out-File -FilePath $env:GITHUB_ENV -Append
./Invoke-PublishModule.ps1 -PSGalleryApiKey $env:NUGETAPIKEY -ModulePath "../../module"
env:
NUGETAPIKEY: ${{secrets.NUGETAPIKEY}}
working-directory: './tools/scripts'
- uses: ncipollo/release-action@v1
with:
artifacts: 'nuget/*'
artifactErrorsFailBuild: true
allowUpdates: true
commit: trunk
tag: "v${{ env.module_version }}"
discussionCategory: "Announcements"
generateReleaseNotes: true
token: ${{ secrets.GITHUB_TOKEN }}