Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues with GHA config #449

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 39 additions & 38 deletions .github/workflows/github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ on:
env:
NupkgArtifactName: 'PSKoans.nupkg'
ModuleArtifactName: 'PSKoans'
PesterInfoFileName: 'PesterVersion.txt'
PesterInfoFilePath: '$GITHUB_WORKSPACE/PesterVersion.txt'
PesterInfoFileName: 'PesterVersion'
PesterInfoFilePath: '${{ github.workspace }}/PesterVersion.txt'

jobs:

Expand All @@ -33,7 +33,7 @@ jobs:
runs-on: ubuntu-latest

env:
FilePath: '$GITHUB_WORKSPACE/Changelog.md'
FilePath: '${{ github.workspace }}/Changelog.md'

steps:
- uses: actions/checkout@v2
Expand All @@ -46,15 +46,15 @@ jobs:
uses: actions/[email protected]
with:
name: Changelog.md
path: $FilePath
path: ${{ env.FilePath }}

build:
name: 'Build Module'
runs-on: ubuntu-latest

env:
FileSystemDeploymentPath: '$GITHUB_WORKSPACE/Deploy/FileSystem'
BuiltModulePath: '$GITHUB_WORKSPACE/Deploy/PSKoans'
FileSystemDeploymentPath: '${{ github.workspace }}/Deploy/FileSystem'
BuiltModulePath: '${{ github.workspace }}/Deploy/PSKoans'
# This needs to be set by the script which creates the nupkg
NupkgPath: ''

Expand All @@ -76,14 +76,14 @@ jobs:

$Params.Name = 'Pester'
$Params.SkipPublisherCheck = $true
$Params.MinimumVersion = $Params.MinimumVersion = (Get-Module -ListAvailable ./PSKoans).RequiredModules.Where{$_.Name -eq 'Pester'}.Version
$Params.RequiredVersion = $Params.MinimumVersion = (Get-Module -ListAvailable ./PSKoans).RequiredModules.Where{$_.Name -eq 'Pester'}.Version
$Params | Out-String | Write-Host
Install-Module @Params

$Params.MinimumVersion | Set-Content -Path "${{ env.PesterInfoFilePath }}"
$Params.RequiredVersion | Set-Content -Path "${{ env.PesterInfoFilePath }}"

$Params.Remove('SkipPublisherCheck')
$Params.Remove('MinimumVersion')
$Params.Remove('RequiredVersion')

$Params.Name = 'EZOut'
$Params.AllowClobber = $true
Expand All @@ -101,14 +101,14 @@ jobs:
- name: Upload Module Artifact
uses: actions/[email protected]
with:
name: $ModuleArtifactName
path: $BuiltModulePath
name: ${{ env.ModuleArtifactName }}
path: ${{ env.BuiltModulePath }}

- name: Upload Pester Version Artifact
uses: actions/[email protected]
with:
name: $PesterInfoFileName
path: $PesterInfoFilePath
name: ${{ env.PesterInfoFileName }}
path: ${{ env.PesterInfoFilePath }}

- name: Generate Nupkg
shell: pwsh
Expand All @@ -119,8 +119,8 @@ jobs:
- name: Upload Nupkg Artifact
uses: actions/[email protected]
with:
name: $NupkgArtifactName
path: $NupkgPath
name: ${{ env.NupkgArtifactName }}
path: ${{ env.NupkgPath }}

test:
name: "Test Module"
Expand All @@ -136,7 +136,7 @@ jobs:
runs-on: ${{ matrix.os }}

env:
PackageDownloadPath: '$GITHUB_WORKSPACE/Module'
PackageDownloadPath: '${{ github.workspace }}/Module'
PSRepositoryName: 'FileSystem'
# The following variables MUST be set in Invoke-ModuleTests.ps1
TestFile: ''
Expand All @@ -161,12 +161,12 @@ jobs:

$Params.Name = 'Pester'
$Params.SkipPublisherCheck = $true
$Params.MinimumVersion = $Params.MinimumVersion = (Get-Module -ListAvailable ./PSKoans).RequiredModules.Where{$_.Name -eq 'Pester'}.Version
$Params.RequiredVersion = $Params.MinimumVersion = (Get-Module -ListAvailable ./PSKoans).RequiredModules.Where{$_.Name -eq 'Pester'}.Version
$Params | Out-String | Write-Host
Install-Module @Params

$Params.Remove('SkipPublisherCheck')
$Params.Remove('MinimumVersion')
$Params.Remove('RequiredVersion')

$Params.Name = 'EZOut'
$Params.AllowClobber = $true
Expand All @@ -184,21 +184,21 @@ jobs:
- name: Download Module Nupkg
uses: actions/[email protected]
with:
name: $NupkgArtifactName
path: $PackageDownloadPath
name: ${{ env.NupkgArtifactName }}
path: ${{ env.PackageDownloadPath }}

- name: Download Pester Version Information
uses: actions/[email protected]
with:
name: $PesterInfoFileName
path: $PesterInfoFilePath
name: ${{ env.PesterInfoFileName }}
path: ${{ github.workspace }}

- name: Install Module from Nupkg
shell: pwsh
run: |
$pesterParams = @{
Name = 'Pester'
MinimumVersion = Get-Content -Path "${{ env.PesterInfoFilePath }}"
RequiredVersion = Get-Content -Path "${{ env.PesterInfoFilePath }}"
ProviderName = 'NuGet'
Path = '${{ env.PackageDownloadPath }}'
Force = $true
Expand All @@ -213,35 +213,36 @@ jobs:
run: ./Build/Invoke-ModuleTests.ps1

- name: Publish Test Results
if: ${{ always() }}
if: always()
uses: MirageNet/[email protected]
with:
access-token: ${{ secrets.GITHUB_TOKEN }}
path: '$GITHUB_WORKSPACE\$TestResults'
path: '${{ github.workspace }}/$TestResults'

- name: Generate Code Coverage
uses: danielpalme/[email protected]
with:
reports: '$GITHUB_WORKSPACE\$CodeCoverageFile'
targetdir: '$GITHUB_WORKSPACE\coveragereports'
sourcedirs: $SourceFolders
reports: '${{ github.workspace }}/$CodeCoverageFile'
targetdir: '${{ github.workspace }}/coveragereports'
sourcedirs: ${{ env.ModuleFolders }}
title: PSKoans Code Coverage

- name: Publish Code Coverage artifacts
uses: actions/[email protected]
with:
name: 'Code Coverage Reports'
path: '$GITHUB_WORKSPACE\coveragereports'
path: '${{ github.workspace }}/coveragereports'

publish:
name: Publish Module to PSGallery
needs: test
if: ${{ success() && startsWith( 'refs/tags/', env.GITHUB_REF ) }}
if: success() && startsWith( github.ref, 'refs/tags/' )

runs-on: ubuntu-latest

env:
BuiltModulePath: '$GITHUB_WORKSPACE/Deploy/PSKoans'
GalleryDeploymentPath: '$GITHUB_WORKSPACE/Deploy/PSGallery'
BuiltModulePath: '${{ github.workspace }}/Deploy/PSKoans'
GalleryDeploymentPath: '${{ github.workspace }}/Deploy/PSGallery'
# This variable must be set by the script
TagName: ''

Expand All @@ -261,17 +262,17 @@ jobs:
- name: Set Release Tag Name
shell: pwsh
run: |
$tagName = ("${{ env.GITHUB_REF }}" -replace '^refs/tags/').Trim()
"TagName=$tagname" | Add-Content -Path '${{ env.GITHUB_ENV }}'
$tagName = ("${{ github.ref }}" -replace '^refs/tags/').Trim()
"TagName=$tagname" | Add-Content -Path '${{ github.env }}'

- name: Download Artifacts
uses: actions/[email protected]
with:
path: '$GITHUB_WORKSPACE/artifacts'
path: '${{ github.workspace }}/artifacts'

- name: Update Release with Artifacts & Changelog
uses: Roang-zero1/[email protected]
with:
created_tag: $TagName
changelog_file: '$GITHUB_WORKSPACE/artifacts/Changelog.md'
release_title: 'PSKoans Release $TagName'
created_tag: ${{ env.TagName }}
changelog_file: '${{ github.workspace }}/artifacts/Changelog.md'
release_title: 'PSKoans Release ${{ env.TagName }}'
4 changes: 3 additions & 1 deletion Build/Build-Module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ catch {
# Build external help files from Platyps MD files
New-ExternalHelp -Path "$env:PROJECTROOT/docs/" -OutputPath "$env:PROJECTROOT/PSKoans/en"

Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $env:BUILTMODULEPATH -Recurse -PassThru |
$buildModulePath = @($env:BuiltModulePath, $env:BUILTMODULEPATH).Where({ $_ }, 'First')[0]

Copy-Item -Path "$env:PROJECTROOT/PSKoans" -Destination $buildModulePath -Recurse -PassThru |
Where-Object { -not $_.PSIsContainer }
22 changes: 20 additions & 2 deletions Build/Initialize-Environment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,30 @@ Get-PackageProvider -Name NuGet -ForceBootstrap > $null
Set-BuildEnvironment

$ProjectRoot = Resolve-Path -Path "$PSScriptRoot/.."
Write-Host "##vso[task.setvariable variable=ProjectRoot]$ProjectRoot"

$Lines = '-' * 70

Write-Host $Lines
Write-Host "Repository Branch: $env:BUILD_SOURCEBRANCHNAME ($env:BUILD_SOURCEBRANCH)"

$AzurePipelines = $env:BUILD_SOURCESDIRECTORY -and $env:BUILD_BUILDNUMBER
$GithubActions = [bool]$env:GITHUB_WORKSPACE

if ($AzurePipelines) {
Write-Host "Repository Branch: [$env:BUILD_SOURCEBRANCHNAME] ($env:BUILD_SOURCEBRANCH)"
Write-Host "##vso[task.setvariable variable=ProjectRoot]$ProjectRoot"
}
elseif ($GithubActions) {
Write-Host "Repository Branch: $env:GITHUB_REF"
if ($env:GITHUB_HEAD_REF -and $env:GITHUB_BASE_REF) {
Write-Host "Pull Request Build: [$env:GITHUB_HEAD_REF] (HEAD) -> [$env:GITHUB_BASE_REF] (BASE)"
}

"PROJECTROOT=$ProjectRoot" | Add-Content -Path $env:GITHUB_ENV
}
else {
$env:PROJECTROOT = $ProjectRoot
}

Write-Host "Build System Details:"
Get-Item 'Env:BH*' | Out-String | Write-Host
Write-Host $Lines
6 changes: 3 additions & 3 deletions Deploy/Publish.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ if ($OutputDirectory) {
Import-Module "$PSScriptRoot/PSKoans"
$Module = Get-Module -Name PSKoans
$Dependencies = @(
$Module.RequiredModules.Name
$Module.NestedModules.Name
$Module.RequiredModules | Select-Object -Property Name, Version
$Module.NestedModules | Select-Object -Property Name, Version
).Where{ $_ }

foreach ($Module in $Dependencies) {
Publish-Module -Name $Module -Repository FileSystem -NugetApiKey "Test-Publish"
Publish-Module -Name $Module.Name -Repository FileSystem -NugetApiKey "Test-Publish" -RequiredVersion $Module.Version
}
}

Expand Down