From 6247f112cf53d2aaa1a1ba326c145b236e70ae6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=B6tz=20Jensen?= Date: Fri, 10 Jul 2026 16:44:37 +0200 Subject: [PATCH] Fix: Making the actions / workflows run from a cache --- .github/workflows/build.yml | 123 ++++++++++++++++++++++++++----- .github/workflows/cache-warm.yml | 30 ++++++++ .github/workflows/validate.yml | 76 +++++++++++++------ build/vsts-validate.ps1 | 12 ++- 4 files changed, 201 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/cache-warm.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2ad279a..9182c92 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,31 +1,120 @@ -name: Publish to PowerShell Gallery +name: Publish to PowerShell Gallery + +# Build and release the PsLogicAppExtractor PowerShell module on every push to main. +# Validation jobs run in parallel with module caching; build-and-release runs after all pass. + on: push: branches: - main jobs: - build: - name: Push to Gallery + general-unit-tests: + name: Validate General Unit Tests runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Cache Powershell Modules + id: cache-powershell-modules + uses: actions/cache@v5 + with: + path: ~\Documents\PowerShell\Modules + key: ps-modules-${{ runner.os }}-v1 + + - name: Install Prerequisites + if: steps.cache-powershell-modules.outputs.cache-hit != 'true' + shell: pwsh + run: | + Set-PSRepository -Name PSGallery -InstallationPolicy Trusted + $modules = @('Pester','PSFramework','PSModuleDevelopment','PSScriptAnalyzer','psake') + foreach ($module in $modules) { + Write-Host "Installing $module..." + Install-Module -Name $module -Scope CurrentUser -Force -SkipPublisherCheck + } + + - name: Validate + shell: pwsh + run: build\vsts-validate.ps1 -TestGeneral $true -TestFunctions $false + individual-unit-tests: + name: Validate Individual Unit Tests + runs-on: windows-latest steps: - - uses: actions/checkout@v3 - - name: Setup PowerShell module cache - id: cacher - uses: actions/cache@v3 + - uses: actions/checkout@v4 with: - path: "C:\\Users\\runneradmin\\Documents\\PowerShell\\Modules" - key: ${{ runner.os }}-PSFramework-PSScriptAnalyzer + fetch-depth: 1 + + - name: Cache Powershell Modules + id: cache-powershell-modules + uses: actions/cache@v5 + with: + path: ~\Documents\PowerShell\Modules + key: ps-modules-${{ runner.os }}-v1 + - name: Install Prerequisites - if: steps.cacher.outputs.cache-hit != 'true' - run: .\build\vsts-prerequisites.ps1 + if: steps.cache-powershell-modules.outputs.cache-hit != 'true' shell: pwsh - # - name: Validate - # run: .\build\vsts-validate.ps1 - # shell: pwsh + run: | + Set-PSRepository -Name PSGallery -InstallationPolicy Trusted + $modules = @('Pester','PSFramework','PSModuleDevelopment','PSScriptAnalyzer','psake') + foreach ($module in $modules) { + Write-Host "Installing $module..." + Install-Module -Name $module -Scope CurrentUser -Force -SkipPublisherCheck + } + + - name: Validate + shell: pwsh + run: build\vsts-validate.ps1 -TestGeneral $false -TestFunctions $true + + build-and-release: + name: Build and Release + runs-on: windows-latest + needs: [general-unit-tests, individual-unit-tests] + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Cache Powershell Modules + id: cache-powershell-modules + uses: actions/cache@v5 + with: + path: ~\Documents\PowerShell\Modules + key: ps-modules-${{ runner.os }}-v1 + + - name: Install Prerequisites + if: steps.cache-powershell-modules.outputs.cache-hit != 'true' + shell: pwsh + run: | + Set-PSRepository -Name PSGallery -InstallationPolicy Trusted + $modules = @('Pester','PSFramework','PSModuleDevelopment','PSScriptAnalyzer','psake') + foreach ($module in $modules) { + Write-Host "Installing $module..." + Install-Module -Name $module -Scope CurrentUser -Force -SkipPublisherCheck + } + - name: Build - run: .\build\vsts-build.ps1 -ApiKey $env:APIKEY -AutoVersion shell: pwsh - env: - APIKEY: ${{ secrets.ApiKey }} + run: .\build\vsts-build.ps1 -ApiKey ${{ secrets.ApiKey }} -AutoVersion:$true -SkipPublish:$false + + - name: Get version + shell: pwsh + run: | + $publishDir = Get-Item -Path publish + [version]$version = (Import-PowerShellDataFile -Path "$($publishDir.FullName)\PsLogicAppExtractor\PsLogicAppExtractor.psd1").ModuleVersion + $githubReleaseVersion = "$($version.Major).$($version.Minor).$($version.Build)" + "VERSION=$githubReleaseVersion" >> $env:GITHUB_ENV + + - name: Create GitHub release + uses: softprops/action-gh-release@v3 + with: + name: ${{ env.VERSION }} + tag_name: ${{ env.VERSION }} + draft: false + prerelease: true + generate_release_notes: true diff --git a/.github/workflows/cache-warm.yml b/.github/workflows/cache-warm.yml new file mode 100644 index 0000000..0e456ed --- /dev/null +++ b/.github/workflows/cache-warm.yml @@ -0,0 +1,30 @@ +name: Warm Module Cache + +on: + push: + branches: [main, development] + schedule: + - cron: '0 6 * * 3,6' # Wednesday and Saturday 06:00 UTC + workflow_dispatch: + +jobs: + warm-cache: + runs-on: windows-latest + steps: + - name: Cache PowerShell modules + id: cache-powershell-modules + uses: actions/cache@v5 + with: + path: ~\Documents\PowerShell\Modules + key: ps-modules-${{ runner.os }}-v1 + + - name: Install modules + if: steps.cache-powershell-modules.outputs.cache-hit != 'true' + shell: pwsh + run: | + Set-PSRepository -Name PSGallery -InstallationPolicy Trusted + $modules = @('Pester','PSFramework','PSModuleDevelopment','PSScriptAnalyzer','psake') + foreach ($module in $modules) { + Write-Host "Installing $module..." + Install-Module -Name $module -Scope CurrentUser -Force -SkipPublisherCheck + } diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 8a171aa..f6910f9 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -1,32 +1,64 @@ -name: Validate Module (Unit Tests) +name: validate -on: - workflow_dispatch: - pull_request: - schedule: - - cron: '13 4 * * 1' +on: [pull_request] jobs: - validate: - name: Run Pester Unit Tests + general-unit-tests: + name: Validate General Unit Tests runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Cache Powershell Modules + id: cache-powershell-modules + uses: actions/cache@v5 + with: + path: ~\Documents\PowerShell\Modules + key: ps-modules-${{ runner.os }}-v1 + + - name: Install Prerequisites + if: steps.cache-powershell-modules.outputs.cache-hit != 'true' + shell: pwsh + run: | + Set-PSRepository -Name PSGallery -InstallationPolicy Trusted + $modules = @('Pester','PSFramework','PSModuleDevelopment','PSScriptAnalyzer','psake') + foreach ($module in $modules) { + Write-Host "Installing $module..." + Install-Module -Name $module -Scope CurrentUser -Force -SkipPublisherCheck + } + + - name: Validate + shell: pwsh + run: build\vsts-validate.ps1 -TestGeneral $true -TestFunctions $false + individual-unit-tests: + name: Validate Individual Unit Tests + runs-on: windows-latest steps: - - uses: actions/checkout@v2 - - name: Setup PowerShell module cache - id: cacher - uses: actions/cache@v3 + - uses: actions/checkout@v4 + with: + fetch-depth: 1 + + - name: Cache Powershell Modules + id: cache-powershell-modules + uses: actions/cache@v5 with: - path: "C:\\Users\\runneradmin\\Documents\\PowerShell\\Modules" - key: ${{ runner.os }}-PSFramework-PSScriptAnalyzer - restore-keys: | - ${{ runner.os }}-PSFramework- - ${{ runner.os }}- - ${{ runner.os }} + path: ~\Documents\PowerShell\Modules + key: ps-modules-${{ runner.os }}-v1 + - name: Install Prerequisites - if: steps.cacher.outputs.cache-hit != 'true' - run: .\build\vsts-prerequisites.ps1 + if: steps.cache-powershell-modules.outputs.cache-hit != 'true' shell: pwsh + run: | + Set-PSRepository -Name PSGallery -InstallationPolicy Trusted + $modules = @('Pester','PSFramework','PSModuleDevelopment','PSScriptAnalyzer','psake') + foreach ($module in $modules) { + Write-Host "Installing $module..." + Install-Module -Name $module -Scope CurrentUser -Force -SkipPublisherCheck + } + - name: Validate - run: .\build\vsts-validate.ps1 - shell: pwsh \ No newline at end of file + shell: pwsh + run: build\vsts-validate.ps1 -TestGeneral $false -TestFunctions $true diff --git a/build/vsts-validate.ps1 b/build/vsts-validate.ps1 index 191cf90..de36bd1 100644 --- a/build/vsts-validate.ps1 +++ b/build/vsts-validate.ps1 @@ -3,5 +3,15 @@ # Needs to ensure things are Done Right and only legal commits to master get built +param ( + $TestGeneral = $true, + + $TestFunctions = $true, + + $Include = "*", + + $Exclude = "*.exclude.ps1" +) + # Run internal pester tests -& "$PSScriptRoot\..\PsLogicAppExtractor\tests\pester.ps1" \ No newline at end of file +& "$PSScriptRoot\..\PsLogicAppExtractor\tests\pester.ps1" -TestGeneral $TestGeneral -TestFunctions $TestFunctions -Include $Include -Exclude $Exclude \ No newline at end of file