Skip to content

[Fix] Install when version is provided with leading 'v' #5

[Fix] Install when version is provided with leading 'v'

[Fix] Install when version is provided with leading 'v' #5

Workflow file for this run

###########################################################################
# #
# Copyright (c) Microsoft Corporation. All rights reserved. #
# #
# This code is licensed under the MIT License (MIT). #
# #
###########################################################################
name: CI Build
on:
workflow_dispatch:
inputs:
runner:
description: "Windows runner image"
required: false
default: windows-2022
type: choice
options:
- windows-latest
- windows-2022
- windows-2019
pull_request:
branches: ["main", "releases/**"]
paths-ignore:
- "docs/**"
- "*.md"
- en-US/**"
env:
MODULE_DIR: .\Containers-Toolkit
BUILD_SCRIPTS_DIR: .\build\scripts
PESTER_RESULTS_DIR: .\TestResults
MODULE_ARTIFACT: CTK.Module.Scripts
REPO_ARTIFACT: CTK.Scripts
jobs:
lint:
runs-on: ${{ github.event.inputs.RUNNER || 'windows-2022' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
# FIXME: Fix cache not working
- name: Setup PowerShell module cache
id: cacher
uses: actions/cache@v3
with:
path: "C:\\program files\\powershell\\7\\Modules"
key: ${{ runner.os }}-CTK
- name: Install required PowerShell modules
if: steps.cacher.outputs.cache-hit != 'true'
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
$ModuleName = 'PSScriptAnalyzer'
if (-not (Get-Module -ListAvailable -Name $ModuleName)) {
Write-Output "Modules to install: '$ModuleName'"
Install-Module $ModuleName -ErrorAction Stop -AllowClobber -SkipPublisherCheck -Force
}
- name: Run code analysis with PSScriptAnalyzer
id: code_analysis
shell: pwsh
run: |
${{ env.BUILD_SCRIPTS_DIR }}\script-analyzer.ps1 | Out-File -FilePath lintsummary.md -Encoding utf8 -Force
cat lintsummary.md >> $env:GITHUB_STEP_SUMMARY
$fileExists = Test-Path ./psscriptanalysis.xml
echo "LINTSUMMARY_EXISTS=$fileExists" >> $env:GITHUB_OUTPUT
- name: Publish PSScriptAnalyzer results file
if: steps.code_analysis.outputs.LINTSUMMARY_EXISTS == 'true'
uses: actions/upload-artifact@v4
with:
name: PSScriptAnalyzer.Results
path: psscriptanalysis.xml
if-no-files-found: error
overwrite: true
pester:
# TODO: Add Windows ARM64 support
runs-on: ${{ github.event.inputs.RUNNER || 'windows-2022' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
# FIXME: Fix cache not working
- name: Setup PowerShell module cache
id: cacher
uses: actions/cache@v3
with:
path: "C:\\program files\\powershell\\7\\Modules"
key: ${{ runner.os }}-CTK
- name: Install required PowerShell modules
if: steps.cacher.outputs.cache-hit != 'true'
shell: pwsh
run: |
Set-PSRepository PSGallery -InstallationPolicy Trusted
$requiredModules = @('Pester', 'ThreadJob', 'HNS')
$missingModules = $requiredModules | Where-Object { -not (Get-Module -ListAvailable -Name $_) }
if ($missingModules) {
Write-Output "Modules to install: $($missingModules -join ', ')"
Install-Module $missingModules -ErrorAction Stop -AllowClobber -SkipPublisherCheck -Force
}
- name: Run Pester tests
shell: pwsh
run: |
$ErrorActionPreference = 'Continue'
${{ env.BUILD_SCRIPTS_DIR }}\run-tests.ps1
- name: Publish Pester results
uses: actions/upload-artifact@v4
with:
name: CTK.Pester.Results
path: ${{ env.PESTER_RESULTS_DIR }}\Test-Results.xml
if-no-files-found: error
overwrite: true
- name: Publish code coverage results
uses: actions/upload-artifact@v4
with:
name: CTK.Coverage.Summary
path: ${{ env.PESTER_RESULTS_DIR }}\coverage.xml
if-no-files-found: error
overwrite: true
test-coverage:
needs: pester
runs-on: ubuntu-latest
steps:
- name: Download coverage results artifact
uses: actions/download-artifact@v4
with:
name: CTK.Coverage.Summary
- name: Setup .NET Core # Required to execute ReportGenerator
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.x
dotnet-quality: "ga"
- name: ReportGenerator
uses: danielpalme/[email protected]
with:
reports: coverage.xml
targetdir: coveragereport
reporttypes: HtmlInline;MarkdownSummaryGithub;Badges
historydir: coveragehistory
- name: Upload coverage report artifact
uses: actions/upload-artifact@v4
with:
name: coveragereport # Artifact name
path: coveragereport # Directory containing files to upload
- name: Publish coverage summary
uses: marocchino/sticky-pull-request-comment@v2
continue-on-error: true
with:
path: coveragereport/SummaryGithub.md
- name: Post results
run: |
cat coveragereport/SummaryGithub.md >> $GITHUB_STEP_SUMMARY