Skip to content

Commit 22155c3

Browse files
authored
Update dependencies script (#3879)
1 parent 426b67a commit 22155c3

10 files changed

Lines changed: 164 additions & 105 deletions

File tree

.github/dependabot.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ updates:
3737
codeql-actions:
3838
patterns:
3939
- 'github/codeql-action/*' # group github/codeql-action/* actions for Dependabot to update these together in one PR
40+
standard-actions:
41+
patterns:
42+
- 'actions/*' # group actions/* actions for Dependabot to update these together in one PR
4043
# Maintain dependencies for Python
4144
- package-ecosystem: pip
4245
directory: '/'

.github/workflows/build.yaml

Lines changed: 96 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
name: Build
99
on:
1010
push:
11-
branches: [ main, 'release/*' ]
11+
branches: [main, 'release/*']
1212
pull_request:
13-
branches: [ main, 'release/*' ]
13+
branches: [main, 'release/*']
1414
schedule:
1515
- cron: '26 21 * * 0' # At 09:26 PM, on Sunday each week
1616
workflow_dispatch: {}
@@ -29,50 +29,52 @@ jobs:
2929
contents: read
3030

3131
steps:
32+
- name: Checkout
33+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
34+
35+
- name: Setup .NET
36+
uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1 # v5.4.0
37+
with:
38+
global-json-file: global.json
39+
40+
- name: Install dependencies
41+
shell: pwsh
42+
timeout-minutes: 3
43+
run: |
44+
./scripts/pipeline-deps.ps1;
45+
Import-Module ./scripts/dependencies.psm1 -Force;
46+
Install-Dependencies -Dev -Repository 'PSGallery' -TrustRepository;
47+
48+
- name: Build module
49+
shell: pwsh
50+
timeout-minutes: 5
51+
run: Invoke-Build -Configuration Release -AssertStyle GitHubActions
52+
53+
- name: Upload module
54+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
55+
with:
56+
name: Module
57+
path: ./out/modules/PSRule.Rules.Azure/*
58+
retention-days: 3
59+
if-no-files-found: error
3260

33-
- name: Checkout
34-
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
35-
36-
- name: Setup .NET
37-
uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1 # v5.4.0
38-
with:
39-
global-json-file: global.json
40-
41-
- name: Install dependencies
42-
shell: pwsh
43-
timeout-minutes: 3
44-
run: ./scripts/pipeline-deps.ps1
45-
46-
- name: Build module
47-
shell: pwsh
48-
timeout-minutes: 5
49-
run: Invoke-Build -Configuration Release -AssertStyle GitHubActions
50-
51-
- name: Upload module
52-
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
53-
with:
54-
name: Module
55-
path: ./out/modules/PSRule.Rules.Azure/*
56-
retention-days: 3
57-
if-no-files-found: error
58-
59-
# - name: Upload Test Results
60-
# uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
61-
# if: always()
62-
# with:
63-
# name: Module.DotNet.TestResults
64-
# path: ./reports/*.trx
65-
# retention-days: 3
66-
# if-no-files-found: error
67-
68-
- name: Upload PSRule Results
69-
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
70-
if: always()
71-
with:
72-
name: Results-PSRule
73-
path: ./reports/ps-rule*.xml
74-
retention-days: 3
75-
if-no-files-found: error
61+
# - name: Upload Test Results
62+
# uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
63+
# if: always()
64+
# with:
65+
# name: Module.DotNet.TestResults
66+
# path: ./reports/*.trx
67+
# retention-days: 3
68+
# if-no-files-found: error
69+
70+
- name: Upload PSRule Results
71+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
72+
if: always()
73+
with:
74+
name: Results-PSRule
75+
path: ./reports/ps-rule*.xml
76+
retention-days: 3
77+
if-no-files-found: error
7678

7779
test_module:
7880
name: 🧪 Test module (${{ matrix.rid }}-${{ matrix.shell }})
@@ -86,9 +88,9 @@ jobs:
8688
fail-fast: false
8789

8890
matrix:
89-
os: [ 'ubuntu-latest' ]
90-
rid: [ 'linux-x64' ]
91-
shell: [ 'pwsh' ]
91+
os: ['ubuntu-latest']
92+
rid: ['linux-x64']
93+
shell: ['pwsh']
9294
include:
9395
- os: windows-latest
9496
rid: win-x64
@@ -107,44 +109,49 @@ jobs:
107109
shell: pwsh
108110

109111
steps:
112+
- name: Checkout
113+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
110114

111-
- name: Checkout
112-
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
113-
114-
- name: Setup .NET
115-
uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1 # v5.4.0
116-
with:
117-
global-json-file: global.json
118-
119-
- if: ${{ matrix.shell == 'pwsh' }}
120-
name: Install dependencies (PowerShell)
121-
shell: pwsh
122-
timeout-minutes: 3
123-
run: ./scripts/pipeline-deps.ps1
124-
125-
- if: ${{ matrix.shell == 'powershell' }}
126-
name: Install dependencies (Windows PowerShell)
127-
shell: powershell
128-
timeout-minutes: 3
129-
run: ./scripts/pipeline-deps.ps1
130-
131-
- name: Download module
132-
uses: actions/download-artifact@v8
133-
with:
134-
name: Module
135-
path: ./out/modules/PSRule.Rules.Azure
136-
137-
- if: ${{ matrix.shell == 'pwsh' }}
138-
name: Test module (PowerShell)
139-
shell: pwsh
140-
timeout-minutes: 15
141-
run: Invoke-Build TestModule -Configuration Release -AssertStyle GitHubActions
142-
143-
- if: ${{ matrix.shell == 'powershell' }}
144-
name: Test module (Windows PowerShell)
145-
shell: powershell
146-
timeout-minutes: 30
147-
run: Invoke-Build TestModule -Configuration Release -AssertStyle GitHubActions
115+
- name: Setup .NET
116+
uses: actions/setup-dotnet@26b0ec14cb23fa6904739307f278c14f94c95bf1 # v5.4.0
117+
with:
118+
global-json-file: global.json
119+
120+
- if: ${{ matrix.shell == 'pwsh' }}
121+
name: Install dependencies (PowerShell)
122+
shell: pwsh
123+
timeout-minutes: 3
124+
run: |
125+
./scripts/pipeline-deps.ps1;
126+
Import-Module ./scripts/dependencies.psm1 -Force;
127+
Install-Dependencies -Dev -Repository 'PSGallery' -TrustRepository;
128+
129+
- if: ${{ matrix.shell == 'powershell' }}
130+
name: Install dependencies (Windows PowerShell)
131+
shell: powershell
132+
timeout-minutes: 5
133+
run: |
134+
./scripts/pipeline-deps.ps1;
135+
Import-Module ./scripts/dependencies.psm1 -Force;
136+
Install-Dependencies -Dev -Repository 'PSGallery' -TrustRepository;
137+
138+
- name: Download module
139+
uses: actions/download-artifact@v8
140+
with:
141+
name: Module
142+
path: ./out/modules/PSRule.Rules.Azure
143+
144+
- if: ${{ matrix.shell == 'pwsh' }}
145+
name: Test module (PowerShell)
146+
shell: pwsh
147+
timeout-minutes: 15
148+
run: Invoke-Build TestModule -Configuration Release -AssertStyle GitHubActions
149+
150+
- if: ${{ matrix.shell == 'powershell' }}
151+
name: Test module (Windows PowerShell)
152+
shell: powershell
153+
timeout-minutes: 30
154+
run: Invoke-Build TestModule -Configuration Release -AssertStyle GitHubActions
148155

149156
build_docs:
150157
name: Build docs
@@ -172,7 +179,10 @@ jobs:
172179
- name: Install dependencies (PowerShell)
173180
shell: pwsh
174181
timeout-minutes: 3
175-
run: ./scripts/pipeline-deps.ps1
182+
run: |
183+
./scripts/pipeline-deps.ps1;
184+
Import-Module ./scripts/dependencies.psm1 -Force;
185+
Install-Dependencies -Dev -Repository 'PSGallery' -TrustRepository;
176186
177187
- name: Build docs
178188
shell: pwsh

.github/workflows/copilot-setup-steps.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ jobs:
4040
dotnet restore;
4141
./scripts/pipeline-deps.ps1;
4242
Import-Module ./scripts/dependencies.psm1 -Force;
43-
Install-Dependencies -Dev;
43+
Install-Dependencies -Dev -Repository 'PSGallery' -TrustRepository;

.github/workflows/docs.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ jobs:
5555
- name: Install dependencies (PowerShell)
5656
shell: pwsh
5757
timeout-minutes: 3
58-
run: ./scripts/pipeline-deps.ps1
58+
run: |
59+
./scripts/pipeline-deps.ps1;
60+
Import-Module ./scripts/dependencies.psm1 -Force;
61+
Install-Dependencies -Dev -Repository 'PSGallery' -TrustRepository;
5962
6063
- name: Build docs
6164
shell: pwsh

pipeline.build.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ if ($Env:BUILD_SOURCEBRANCH -like '*/tags/*' -and $Env:BUILD_SOURCEBRANCHNAME -l
4949
$Build = $Env:BUILD_SOURCEBRANCHNAME.Substring(1);
5050
}
5151

52+
$PSUpstream = 'PSGallery';
53+
if ($Env:PSUPSTREAM -ne $Null -and $Env:PSUPSTREAM -ne '') {
54+
$PSUpstream = $Env:PSUPSTREAM;
55+
}
56+
57+
Write-Host -Object "[Pipeline] -- Using PSUpstream: $PSUpstream" -ForegroundColor Green;
58+
5259
$version = $Build;
5360
$versionSuffix = [String]::Empty;
5461

@@ -560,7 +567,7 @@ task Benchmark {
560567

561568
task Dependencies NuGet, {
562569
Import-Module $PWD/scripts/dependencies.psm1;
563-
Install-Dependencies -Path $PWD/modules.json -Dev;
570+
Install-Dependencies -Path $PWD/modules.json -Dev -Repository $PSUpstream;
564571
}
565572

566573
task ExportData {

requirements-docs.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
mkdocs==1.6.1
22
mkdocs-material==9.7.7
3-
pymdown-extensions==11.0.1
3+
pymdown-extensions==11.0.2
44
mike==2.2.0
5-
mkdocs-git-revision-date-localized-plugin==1.5.3
5+
mkdocs-git-revision-date-localized-plugin==1.5.4
66
mkdocs-git-committers-plugin-2==2.5.0
77
mdx-truly-sane-lists==1.3
88
mkdocs-redirects==1.2.3
99
semver==3.0.4
10-
pygments==2.20.0
10+
pygments==2.21.0
1111
./packages/bicep-syntax

scripts/dependencies.psm1

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,32 @@ function Install-Dependencies {
5252
[String]$Repository = 'PSGallery',
5353

5454
[Parameter(Mandatory = $False)]
55-
[Switch]$Dev
55+
[Switch]$Dev,
56+
57+
[Parameter(Mandatory = $False)]
58+
[Switch]$TrustRepository,
59+
60+
[Parameter(Mandatory = $False)]
61+
[PSCredential]$Credential
5662
)
5763
process {
64+
$installParams = @{
65+
Repository = $Repository
66+
}
67+
68+
if ($Credential) {
69+
$installParams['Credential'] = $Credential;
70+
}
71+
72+
if ($TrustRepository) {
73+
$installParams['TrustRepository'] = $True;
74+
}
75+
5876
$modules = Get-Content -Path $Path -Raw | ConvertFrom-Json;
59-
InstallVersion $modules.dependencies -Repository $Repository;
77+
78+
InstallVersion $modules.dependencies @installParams;
6079
if ($Dev) {
61-
InstallVersion $modules.devDependencies -Repository $Repository -Dev;
80+
InstallVersion $modules.devDependencies @installParams;
6281
}
6382
}
6483
}
@@ -98,9 +117,7 @@ function CheckVersion {
98117
Write-Host -Object "[$group] -- Checking $($module.Name)";
99118
$installParams = @{}
100119
$installParams += $module.Value;
101-
$installParams.MinimumVersion = $installParams.version;
102-
$installParams.Remove('version');
103-
$available = @(Find-Module -Repository $Repository -Name $module.Name @installParams -ErrorAction Ignore);
120+
$available = @(Find-PSResource -Repository $Repository -Name $module.Name @installParams -ErrorAction Ignore);
104121
foreach ($found in $available) {
105122
if (([Version]$found.Version) -gt ([Version]$module.Value.version)) {
106123
Write-Host -Object "[$group] -- Newer version found $($found.Version)";
@@ -127,7 +144,13 @@ function InstallVersion {
127144
[String]$Repository,
128145

129146
[Parameter(Mandatory = $False)]
130-
[Switch]$Dev
147+
[Switch]$Dev,
148+
149+
[Parameter(Mandatory = $False)]
150+
[Switch]$TrustRepository,
151+
152+
[Parameter(Mandatory = $False)]
153+
[PSCredential]$Credential
131154
)
132155
begin {
133156
$group = 'Dependencies';
@@ -137,10 +160,17 @@ function InstallVersion {
137160
}
138161
process {
139162
foreach ($module in $InputObject.PSObject.Properties.GetEnumerator()) {
163+
$installParams = @{ Version = $module.Value.version };
164+
140165
Write-Host -Object "[$group] -- Installing $($module.Name) v$($module.Value.version)";
141-
$installParams = @{ RequiredVersion = $module.Value.version };
142-
if ($Null -eq (Get-InstalledModule -Name $module.Name @installParams -ErrorAction Ignore)) {
143-
Install-Module -Name $module.Name @installParams -Force -Repository $Repository -AllowClobber;
166+
if ($Null -eq (Get-InstalledPSResource -Name $module.Name @installParams -ErrorAction Ignore)) {
167+
if ($Credential) {
168+
$installParams['Credential'] = $Credential;
169+
}
170+
171+
Install-PSResource -Name $module.Name @installParams -Repository $Repository -TrustRepository:$TrustRepository;
172+
} else {
173+
Write-Verbose -Message "[$group] -- $($module.Name) v$($module.Value.version) already installed.";
144174
}
145175
}
146176
}

scripts/pipeline-deps.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ if ($Null -eq (Get-PackageProvider -Name NuGet -ErrorAction Ignore)) {
1313
Install-PackageProvider -Name NuGet -Force -Scope CurrentUser;
1414
}
1515

16-
if ($Null -eq (Get-InstalledModule -Name PowerShellGet -MinimumVersion 2.2.1 -ErrorAction Ignore -WarningAction SilentlyContinue)) {
17-
Install-Module PowerShellGet -MinimumVersion 2.2.1 -Scope CurrentUser -Force -AllowClobber -WarningAction SilentlyContinue;
16+
if ($Null -eq (Get-InstalledModule -Name PowerShellGet -MinimumVersion 2.2.1 -ErrorAction Ignore)) {
17+
Install-Module PowerShellGet -MinimumVersion 2.2.1 -Scope CurrentUser -Force -AllowClobber;
1818
}
1919

2020
if ($Null -eq (Get-InstalledModule -Name InvokeBuild -MinimumVersion 5.4.0 -ErrorAction Ignore)) {
2121
Install-Module InvokeBuild -MinimumVersion 5.4.0 -Scope CurrentUser -Force;
2222
}
23+
24+
if ($Null -eq (Get-InstalledModule -Name Microsoft.PowerShell.PSResourceGet -MinimumVersion 1.1.1 -ErrorAction Ignore)) {
25+
Install-Module Microsoft.PowerShell.PSResourceGet -MinimumVersion 1.1.1 -Scope CurrentUser -Force;
26+
}

tests/PSRule.Rules.Azure.Tests/Azure.APIM.Tests.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ Describe 'Azure.APIM' -Tag 'APIM' {
274274
$filteredResult = $result | Where-Object { $_.RuleName -eq 'Azure.APIM.CertificateExpiry' };
275275

276276
# Fail
277+
# Note: Certificate for apim-p fails every year in August, which is but design.
278+
# Bump the certificate expiry one year in Resources.APIM.json to fix the test.
277279
$ruleResult = @($filteredResult | Where-Object { $_.Outcome -eq 'Fail' });
278280
$ruleResult | Should -Not -BeNullOrEmpty;
279281
$ruleResult.TargetName | Should -Be 'apim-C', 'apim-D', 'apim-E', 'apim-F', 'apim-G', 'apim-H', 'apim-I', 'apim-J', 'apim-K', 'apim-L', 'apim-M', 'apim-N', 'apim-O';

0 commit comments

Comments
 (0)