diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index 43bb7df4..999225a3 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -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: @@ -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 @@ -46,15 +46,15 @@ jobs: uses: actions/upload-artifact@v2.2.3 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: '' @@ -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 @@ -101,14 +101,14 @@ jobs: - name: Upload Module Artifact uses: actions/upload-artifact@v2.2.3 with: - name: $ModuleArtifactName - path: $BuiltModulePath + name: ${{ env.ModuleArtifactName }} + path: ${{ env.BuiltModulePath }} - name: Upload Pester Version Artifact uses: actions/upload-artifact@v2.2.3 with: - name: $PesterInfoFileName - path: $PesterInfoFilePath + name: ${{ env.PesterInfoFileName }} + path: ${{ env.PesterInfoFilePath }} - name: Generate Nupkg shell: pwsh @@ -119,8 +119,8 @@ jobs: - name: Upload Nupkg Artifact uses: actions/upload-artifact@v2.2.3 with: - name: $NupkgArtifactName - path: $NupkgPath + name: ${{ env.NupkgArtifactName }} + path: ${{ env.NupkgPath }} test: name: "Test Module" @@ -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: '' @@ -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 @@ -184,21 +184,21 @@ jobs: - name: Download Module Nupkg uses: actions/download-artifact@v2.0.9 with: - name: $NupkgArtifactName - path: $PackageDownloadPath + name: ${{ env.NupkgArtifactName }} + path: ${{ env.PackageDownloadPath }} - name: Download Pester Version Information uses: actions/download-artifact@v2.0.9 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 @@ -213,35 +213,36 @@ jobs: run: ./Build/Invoke-ModuleTests.ps1 - name: Publish Test Results - if: ${{ always() }} + if: always() uses: MirageNet/nunit-reporter@v1.0.5 with: access-token: ${{ secrets.GITHUB_TOKEN }} - path: '$GITHUB_WORKSPACE\$TestResults' + path: '${{ github.workspace }}/$TestResults' - name: Generate Code Coverage uses: danielpalme/ReportGenerator-GitHub-Action@4.8.8 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/upload-artifact@v2.2.3 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: '' @@ -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/download-artifact@v2.0.9 with: - path: '$GITHUB_WORKSPACE/artifacts' + path: '${{ github.workspace }}/artifacts' - name: Update Release with Artifacts & Changelog uses: Roang-zero1/github-create-release-action@v2.1.0 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 }}' diff --git a/Build/Build-Module.ps1 b/Build/Build-Module.ps1 index 1ee5a3b8..e267506c 100644 --- a/Build/Build-Module.ps1 +++ b/Build/Build-Module.ps1 @@ -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 } diff --git a/Build/Initialize-Environment.ps1 b/Build/Initialize-Environment.ps1 index 9576a58d..18b205ab 100644 --- a/Build/Initialize-Environment.ps1 +++ b/Build/Initialize-Environment.ps1 @@ -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 diff --git a/Deploy/Publish.ps1 b/Deploy/Publish.ps1 index 62c5a944..ec2adb36 100644 --- a/Deploy/Publish.ps1 +++ b/Deploy/Publish.ps1 @@ -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 } }