From 62d8845d6ccd9e0a548dbdf9291dc54e7e3e9332 Mon Sep 17 00:00:00 2001 From: Elinora White Date: Sat, 1 Aug 2026 06:09:01 +0000 Subject: [PATCH] Update dependencies script --- .github/workflows/build.yaml | 171 ++++++++++++++++++----------------- .github/workflows/docs.yaml | 5 +- scripts/dependencies.psm1 | 50 ++++++++-- scripts/pipeline-deps.ps1 | 8 +- 4 files changed, 136 insertions(+), 98 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 8469700ae53..8196e524fd9 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -8,9 +8,9 @@ name: Build on: push: - branches: [ main, 'release/*' ] + branches: [main, 'release/*'] pull_request: - branches: [ main, 'release/*' ] + branches: [main, 'release/*'] schedule: - cron: '26 21 * * 0' # At 09:26 PM, on Sunday each week workflow_dispatch: {} @@ -29,50 +29,52 @@ jobs: contents: read steps: + - name: Checkout + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + + - name: Setup .NET + uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1 # v5.4.0 + with: + global-json-file: global.json + + - name: Install dependencies + shell: pwsh + timeout-minutes: 3 + run: | + ./scripts/pipeline-deps.ps1; + Import-Module ./scripts/dependencies.psm1 -Force; + Install-Dependencies -Dev -Repository 'PSGallery' -TrustRepository; + + - name: Build module + shell: pwsh + timeout-minutes: 5 + run: Invoke-Build -Configuration Release -AssertStyle GitHubActions + + - name: Upload module + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: Module + path: ./out/modules/PSRule.Rules.Azure/* + retention-days: 3 + if-no-files-found: error - - name: Checkout - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 - - - name: Setup .NET - uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1 # v5.4.0 - with: - global-json-file: global.json - - - name: Install dependencies - shell: pwsh - timeout-minutes: 3 - run: ./scripts/pipeline-deps.ps1 - - - name: Build module - shell: pwsh - timeout-minutes: 5 - run: Invoke-Build -Configuration Release -AssertStyle GitHubActions - - - name: Upload module - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 - with: - name: Module - path: ./out/modules/PSRule.Rules.Azure/* - retention-days: 3 - if-no-files-found: error - - # - name: Upload Test Results - # uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 - # if: always() - # with: - # name: Module.DotNet.TestResults - # path: ./reports/*.trx - # retention-days: 3 - # if-no-files-found: error - - - name: Upload PSRule Results - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 - if: always() - with: - name: Results-PSRule - path: ./reports/ps-rule*.xml - retention-days: 3 - if-no-files-found: error + # - name: Upload Test Results + # uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + # if: always() + # with: + # name: Module.DotNet.TestResults + # path: ./reports/*.trx + # retention-days: 3 + # if-no-files-found: error + + - name: Upload PSRule Results + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + if: always() + with: + name: Results-PSRule + path: ./reports/ps-rule*.xml + retention-days: 3 + if-no-files-found: error test_module: name: 🧪 Test module (${{ matrix.rid }}-${{ matrix.shell }}) @@ -86,9 +88,9 @@ jobs: fail-fast: false matrix: - os: [ 'ubuntu-latest' ] - rid: [ 'linux-x64' ] - shell: [ 'pwsh' ] + os: ['ubuntu-latest'] + rid: ['linux-x64'] + shell: ['pwsh'] include: - os: windows-latest rid: win-x64 @@ -107,44 +109,43 @@ jobs: shell: pwsh steps: + - name: Checkout + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + + - name: Setup .NET + uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1 # v5.4.0 + with: + global-json-file: global.json - - name: Checkout - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 - - - name: Setup .NET - uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1 # v5.4.0 - with: - global-json-file: global.json - - - if: ${{ matrix.shell == 'pwsh' }} - name: Install dependencies (PowerShell) - shell: pwsh - timeout-minutes: 3 - run: ./scripts/pipeline-deps.ps1 - - - if: ${{ matrix.shell == 'powershell' }} - name: Install dependencies (Windows PowerShell) - shell: powershell - timeout-minutes: 3 - run: ./scripts/pipeline-deps.ps1 - - - name: Download module - uses: actions/download-artifact@v8 - with: - name: Module - path: ./out/modules/PSRule.Rules.Azure - - - if: ${{ matrix.shell == 'pwsh' }} - name: Test module (PowerShell) - shell: pwsh - timeout-minutes: 15 - run: Invoke-Build TestModule -Configuration Release -AssertStyle GitHubActions - - - if: ${{ matrix.shell == 'powershell' }} - name: Test module (Windows PowerShell) - shell: powershell - timeout-minutes: 30 - run: Invoke-Build TestModule -Configuration Release -AssertStyle GitHubActions + - if: ${{ matrix.shell == 'pwsh' }} + name: Install dependencies (PowerShell) + shell: pwsh + timeout-minutes: 3 + run: ./scripts/pipeline-deps.ps1 + + - if: ${{ matrix.shell == 'powershell' }} + name: Install dependencies (Windows PowerShell) + shell: powershell + timeout-minutes: 3 + run: ./scripts/pipeline-deps.ps1 + + - name: Download module + uses: actions/download-artifact@v8 + with: + name: Module + path: ./out/modules/PSRule.Rules.Azure + + - if: ${{ matrix.shell == 'pwsh' }} + name: Test module (PowerShell) + shell: pwsh + timeout-minutes: 15 + run: Invoke-Build TestModule -Configuration Release -AssertStyle GitHubActions + + - if: ${{ matrix.shell == 'powershell' }} + name: Test module (Windows PowerShell) + shell: powershell + timeout-minutes: 30 + run: Invoke-Build TestModule -Configuration Release -AssertStyle GitHubActions build_docs: name: Build docs diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index c53d5ac506e..66a6f25e256 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -55,7 +55,10 @@ jobs: - name: Install dependencies (PowerShell) shell: pwsh timeout-minutes: 3 - run: ./scripts/pipeline-deps.ps1 + run: | + ./scripts/pipeline-deps.ps1; + Import-Module ./scripts/dependencies.psm1 -Force; + Install-Dependencies -Dev -Repository 'PSGallery' -TrustRepository; - name: Build docs shell: pwsh diff --git a/scripts/dependencies.psm1 b/scripts/dependencies.psm1 index 150d126e7a0..f503be5cbec 100644 --- a/scripts/dependencies.psm1 +++ b/scripts/dependencies.psm1 @@ -52,13 +52,32 @@ function Install-Dependencies { [String]$Repository = 'PSGallery', [Parameter(Mandatory = $False)] - [Switch]$Dev + [Switch]$Dev, + + [Parameter(Mandatory = $False)] + [Switch]$TrustRepository, + + [Parameter(Mandatory = $False)] + [PSCredential]$Credential ) process { + $installParams = @{ + Repository = $Repository + } + + if ($Credential) { + $installParams['Credential'] = $Credential; + } + + if ($TrustRepository) { + $installParams['TrustRepository'] = $True; + } + $modules = Get-Content -Path $Path -Raw | ConvertFrom-Json; - InstallVersion $modules.dependencies -Repository $Repository; + + InstallVersion $modules.dependencies @installParams; if ($Dev) { - InstallVersion $modules.devDependencies -Repository $Repository -Dev; + InstallVersion $modules.devDependencies @installParams; } } } @@ -98,9 +117,7 @@ function CheckVersion { Write-Host -Object "[$group] -- Checking $($module.Name)"; $installParams = @{} $installParams += $module.Value; - $installParams.MinimumVersion = $installParams.version; - $installParams.Remove('version'); - $available = @(Find-Module -Repository $Repository -Name $module.Name @installParams -ErrorAction Ignore); + $available = @(Find-PSResource -Repository $Repository -Name $module.Name @installParams -ErrorAction Ignore); foreach ($found in $available) { if (([Version]$found.Version) -gt ([Version]$module.Value.version)) { Write-Host -Object "[$group] -- Newer version found $($found.Version)"; @@ -127,7 +144,13 @@ function InstallVersion { [String]$Repository, [Parameter(Mandatory = $False)] - [Switch]$Dev + [Switch]$Dev, + + [Parameter(Mandatory = $False)] + [Switch]$TrustRepository, + + [Parameter(Mandatory = $False)] + [PSCredential]$Credential ) begin { $group = 'Dependencies'; @@ -137,10 +160,17 @@ function InstallVersion { } process { foreach ($module in $InputObject.PSObject.Properties.GetEnumerator()) { + $installParams = @{ Version = $module.Value.version }; + Write-Host -Object "[$group] -- Installing $($module.Name) v$($module.Value.version)"; - $installParams = @{ RequiredVersion = $module.Value.version }; - if ($Null -eq (Get-InstalledModule -Name $module.Name @installParams -ErrorAction Ignore)) { - Install-Module -Name $module.Name @installParams -Force -Repository $Repository -AllowClobber; + if ($Null -eq (Get-InstalledPSResource -Name $module.Name @installParams -ErrorAction Ignore)) { + if ($Credential) { + $installParams['Credential'] = $Credential; + } + + Install-PSResource -Name $module.Name @installParams -Repository $Repository -TrustRepository:$TrustRepository; + } else { + Write-Verbose -Message "[$group] -- $($module.Name) v$($module.Value.version) already installed."; } } } diff --git a/scripts/pipeline-deps.ps1 b/scripts/pipeline-deps.ps1 index 27e57b9b2c9..1d809ad4a7f 100644 --- a/scripts/pipeline-deps.ps1 +++ b/scripts/pipeline-deps.ps1 @@ -13,10 +13,14 @@ if ($Null -eq (Get-PackageProvider -Name NuGet -ErrorAction Ignore)) { Install-PackageProvider -Name NuGet -Force -Scope CurrentUser; } -if ($Null -eq (Get-InstalledModule -Name PowerShellGet -MinimumVersion 2.2.1 -ErrorAction Ignore -WarningAction SilentlyContinue)) { - Install-Module PowerShellGet -MinimumVersion 2.2.1 -Scope CurrentUser -Force -AllowClobber -WarningAction SilentlyContinue; +if ($Null -eq (Get-InstalledModule -Name PowerShellGet -MinimumVersion 2.2.1 -ErrorAction Ignore)) { + Install-Module PowerShellGet -MinimumVersion 2.2.1 -Scope CurrentUser -Force -AllowClobber; } if ($Null -eq (Get-InstalledModule -Name InvokeBuild -MinimumVersion 5.4.0 -ErrorAction Ignore)) { Install-Module InvokeBuild -MinimumVersion 5.4.0 -Scope CurrentUser -Force; } + +if ($Null -eq (Get-InstalledModule -Name Microsoft.PowerShell.PSResourceGet -MinimumVersion 1.1.1 -ErrorAction Ignore)) { + Install-Module Microsoft.PowerShell.PSResourceGet -MinimumVersion 1.1.1 -Scope CurrentUser -Force; +}