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

✨ Adds Build Support for PSGallery Dependencies #1

Merged
merged 14 commits into from
Aug 26, 2023
Merged
6 changes: 3 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"root = true
root = true

[*]
charset = utf-8
Expand All @@ -12,8 +12,8 @@ indent_size = 2
[*.json]
indent_size = 2

[*.yml]
[*.yml,*.yaml,*.xml]
indent_size = 2

[*.ps1,*.psm1,*.psd1]
indent_size = 4"
indent_size = 4
42 changes: 38 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,23 @@ jobs:
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: Download PSGallery package
uses: actions/download-artifact@v2
with:
Expand All @@ -78,18 +95,35 @@ jobs:
- name: Publish Prerelease to PSGallery (WhatIf)
if: "${{ steps.gitversion_vars.outputs.PreReleaseTag != '' }}"
shell: pwsh
run: ./scripts/publish.ps1 -NUGET_KEY "abc" -Prerelease -WhatIf
run: ./build/publish.ps1 -NUGET_KEY "abc" -Prerelease -WhatIf
- name: Publish Release to PSGallery (WhatIf)
if: "${{ steps.gitversion_vars.outputs.PreReleaseTag == '' }}"
shell: pwsh
run: ./scripts/publish.ps1 -NUGET_KEY "abc" -WhatIf
run: ./build/publish.ps1 -NUGET_KEY "abc" -WhatIf

publish-psgallery-package:
runs-on: ubuntu-latest
needs: [test-publish-psgallery-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: Download version.json
uses: actions/download-artifact@v2
with:
Expand All @@ -113,13 +147,13 @@ jobs:
shell: pwsh
env:
NUGET_KEY: ${{ secrets.NUGET_KEY }}
run: ./scripts/publish.ps1 -NUGET_KEY "$env:NUGET_KEY" -Prerelease
run: ./build/publish.ps1 -NUGET_KEY "$env:NUGET_KEY" -Prerelease
- name: Publish Release to PSGallery
if: "${{ steps.gitversion_vars.outputs.PreReleaseTag == '' }}"
shell: pwsh
env:
NUGET_KEY: ${{ secrets.NUGET_KEY }}
run: ./scripts/publish.ps1 -NUGET_KEY "$env:NUGET_KEY"
run: ./build/publish.ps1 -NUGET_KEY "$env:NUGET_KEY"

publish-github-release:
runs-on: ubuntu-latest
Expand Down
87 changes: 62 additions & 25 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,26 @@ jobs:
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Setup PowerShell module cache
- name: "Cache: Nested PSGallery Modules"
id: cacher
uses: actions/cache@v3
with:
path: "~/.local/share/powershell/Modules"
key: ${{ runner.os }}-PSScriptAnalyzer
- name: Install Modules from PSGallery
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
Install-Module PSScriptAnalyzer -ErrorAction Stop
./build/restore.ps1
- name: Lint with PSScriptAnalyzer
shell: pwsh
run: ./scripts/lint.ps1 -NoFail
run: ./build/lint.ps1 -NoFail

determine-version:
name: Determine Version with GitVersion
Expand Down Expand Up @@ -118,6 +123,23 @@ jobs:
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: Download version.json
uses: actions/download-artifact@v2
with:
Expand All @@ -141,7 +163,7 @@ jobs:
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
./scripts/package.ps1 -PackageVersionNuGet $version.NuGetVersionV2 -PackageVersionMajorMinorPatchBuild $version.AssemblySemVer -PackageVersionPrereleaseTag $version.PrereleaseTag -ReleaseNotes $releaseNotes -CommitSha $version.Sha
./build/package.ps1 -PackageVersionNuGet $version.NuGetVersionV2 -PackageVersionMajorMinorPatchBuild $version.AssemblySemVer -PackageVersionPrereleaseTag $version.PrereleaseTag -ReleaseNotes $releaseNotes -CommitSha $version.Sha
- name: Upload PSGallery package
uses: actions/upload-artifact@v3
with:
Expand All @@ -155,26 +177,31 @@ jobs:
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Setup PowerShell module cache
- name: "Cache: Nested PSGallery Modules"
id: cacher
uses: actions/cache@v3
with:
path: "~/.local/share/powershell/Modules" # See: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-powershell#powershell-module-locations
key: ${{ runner.os }}-Pester
- name: Install Modules from PSGallery
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
Install-Module Pester -ErrorAction Stop
./build/restore.ps1
- name: Download PSGallery package
uses: actions/download-artifact@v2
with:
name: PSGallery-package
path: ./out/
- name: Test with Pester
shell: pwsh
run: ./scripts/test.ps1 -UsePackageExport
run: ./build/test.ps1 -UsePackageExport
- name: Upload test results
uses: actions/upload-artifact@v3
with:
Expand All @@ -189,26 +216,31 @@ jobs:
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Setup PowerShell module cache
- name: "Cache: Nested PSGallery Modules"
id: cacher
uses: actions/cache@v3
with:
path: "C:\\Users\\runneradmin\\Documents\\PowerShell\\Modules" # See: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-powershell#powershell-module-locations
key: ${{ runner.os }}-Pester
- name: Install Modules from PSGallery
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
Install-Module Pester -ErrorAction Stop
./build/restore.ps1
- name: Download PSGallery package
uses: actions/download-artifact@v2
with:
name: PSGallery-package
path: ./out/
- name: Test with Pester
shell: pwsh
run: ./scripts/test.ps1 -UsePackageExport
run: ./build/test.ps1 -UsePackageExport
- name: Upload test results
uses: actions/upload-artifact@v3
with:
Expand All @@ -223,26 +255,31 @@ jobs:
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Setup PowerShell module cache
- name: "Cache: Nested PSGallery Modules"
id: cacher
uses: actions/cache@v3
with:
path: "/Users/runner/.local/share/powershell/Modules" # See: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-powershell#powershell-module-locations
key: ${{ runner.os }}-Pester
- name: Install Modules from PSGallery
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
Install-Module Pester -ErrorAction Stop
./build/restore.ps1
- name: Download PSGallery package
uses: actions/download-artifact@v2
with:
name: PSGallery-package
path: ./out/
- name: Test with Pester
shell: pwsh
run: ./scripts/test.ps1 -UsePackageExport -NoFail
run: ./build/test.ps1 -UsePackageExport -NoFail
- name: Upload test results
uses: actions/upload-artifact@v3
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bin/
lib/
obj/
out/
5 changes: 4 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"name": "PowerShell: Run Pester Tests",
"type": "PowerShell",
"request": "launch",
"script": "./scripts/test.ps1",
"script": "./build/test.ps1",
"args": [
"-UsePackageExport",
],
"createTemporaryIntegratedConsole": true,
"attachDotnetDebugger": true
}
Expand Down
5 changes: 4 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
{
"label": "Run Pester Tests",
"type": "shell",
"command": "./scripts/test.ps1"
"command": "./build/test.ps1",
"args": [
"-UsePackageExport",
],
}
]
}
10 changes: 10 additions & 0 deletions NuGet.PSGallery.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="./lib" />
</config>
<packageSources>
<clear />
<add key="PSGallery" value="https://www.powershellgallery.com/api/v2" />
</packageSources>
</configuration>
22 changes: 22 additions & 0 deletions build/clean.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env pwsh
param(
)
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest


[string] $ds = [System.IO.Path]::DirectorySeparatorChar
[string] $projectRoot = Resolve-Path "${PSScriptRoot}${ds}.." -Relative

[string[]] $foldersToDelete = @(
'bin',
'lib',
'obj',
'out'
)

foreach ($folderToDelete in $foldersToDelete) {
if (Test-Path "${projectRoot}${ds}${folderToDelete}" -ErrorAction SilentlyContinue) {
Remove-Item -Path "${projectRoot}${ds}${folderToDelete}" -Recurse -Force -ErrorAction Continue
}
}
Loading
Loading