Skip to content
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
171 changes: 86 additions & 85 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand All @@ -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 }})
Expand All @@ -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
Expand All @@ -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
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 40 additions & 10 deletions scripts/dependencies.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down Expand Up @@ -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)";
Expand All @@ -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';
Expand All @@ -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.";
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions scripts/pipeline-deps.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Loading