Skip to content

Commit 6247f11

Browse files
committed
Fix: Making the actions / workflows run from a cache
1 parent b3179b4 commit 6247f11

4 files changed

Lines changed: 201 additions & 40 deletions

File tree

.github/workflows/build.yml

Lines changed: 106 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,120 @@
1-
name: Publish to PowerShell Gallery
1+
name: Publish to PowerShell Gallery
2+
3+
# Build and release the PsLogicAppExtractor PowerShell module on every push to main.
4+
# Validation jobs run in parallel with module caching; build-and-release runs after all pass.
5+
26
on:
37
push:
48
branches:
59
- main
610

711
jobs:
8-
build:
9-
name: Push to Gallery
12+
general-unit-tests:
13+
name: Validate General Unit Tests
1014
runs-on: windows-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 1
19+
20+
- name: Cache Powershell Modules
21+
id: cache-powershell-modules
22+
uses: actions/cache@v5
23+
with:
24+
path: ~\Documents\PowerShell\Modules
25+
key: ps-modules-${{ runner.os }}-v1
26+
27+
- name: Install Prerequisites
28+
if: steps.cache-powershell-modules.outputs.cache-hit != 'true'
29+
shell: pwsh
30+
run: |
31+
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
32+
$modules = @('Pester','PSFramework','PSModuleDevelopment','PSScriptAnalyzer','psake')
33+
foreach ($module in $modules) {
34+
Write-Host "Installing $module..."
35+
Install-Module -Name $module -Scope CurrentUser -Force -SkipPublisherCheck
36+
}
37+
38+
- name: Validate
39+
shell: pwsh
40+
run: build\vsts-validate.ps1 -TestGeneral $true -TestFunctions $false
1141

42+
individual-unit-tests:
43+
name: Validate Individual Unit Tests
44+
runs-on: windows-latest
1245
steps:
13-
- uses: actions/checkout@v3
14-
- name: Setup PowerShell module cache
15-
id: cacher
16-
uses: actions/cache@v3
46+
- uses: actions/checkout@v4
1747
with:
18-
path: "C:\\Users\\runneradmin\\Documents\\PowerShell\\Modules"
19-
key: ${{ runner.os }}-PSFramework-PSScriptAnalyzer
48+
fetch-depth: 1
49+
50+
- name: Cache Powershell Modules
51+
id: cache-powershell-modules
52+
uses: actions/cache@v5
53+
with:
54+
path: ~\Documents\PowerShell\Modules
55+
key: ps-modules-${{ runner.os }}-v1
56+
2057
- name: Install Prerequisites
21-
if: steps.cacher.outputs.cache-hit != 'true'
22-
run: .\build\vsts-prerequisites.ps1
58+
if: steps.cache-powershell-modules.outputs.cache-hit != 'true'
2359
shell: pwsh
24-
# - name: Validate
25-
# run: .\build\vsts-validate.ps1
26-
# shell: pwsh
60+
run: |
61+
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
62+
$modules = @('Pester','PSFramework','PSModuleDevelopment','PSScriptAnalyzer','psake')
63+
foreach ($module in $modules) {
64+
Write-Host "Installing $module..."
65+
Install-Module -Name $module -Scope CurrentUser -Force -SkipPublisherCheck
66+
}
67+
68+
- name: Validate
69+
shell: pwsh
70+
run: build\vsts-validate.ps1 -TestGeneral $false -TestFunctions $true
71+
72+
build-and-release:
73+
name: Build and Release
74+
runs-on: windows-latest
75+
needs: [general-unit-tests, individual-unit-tests]
76+
permissions:
77+
contents: write
78+
steps:
79+
- uses: actions/checkout@v4
80+
with:
81+
fetch-depth: 1
82+
83+
- name: Cache Powershell Modules
84+
id: cache-powershell-modules
85+
uses: actions/cache@v5
86+
with:
87+
path: ~\Documents\PowerShell\Modules
88+
key: ps-modules-${{ runner.os }}-v1
89+
90+
- name: Install Prerequisites
91+
if: steps.cache-powershell-modules.outputs.cache-hit != 'true'
92+
shell: pwsh
93+
run: |
94+
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
95+
$modules = @('Pester','PSFramework','PSModuleDevelopment','PSScriptAnalyzer','psake')
96+
foreach ($module in $modules) {
97+
Write-Host "Installing $module..."
98+
Install-Module -Name $module -Scope CurrentUser -Force -SkipPublisherCheck
99+
}
100+
27101
- name: Build
28-
run: .\build\vsts-build.ps1 -ApiKey $env:APIKEY -AutoVersion
29102
shell: pwsh
30-
env:
31-
APIKEY: ${{ secrets.ApiKey }}
103+
run: .\build\vsts-build.ps1 -ApiKey ${{ secrets.ApiKey }} -AutoVersion:$true -SkipPublish:$false
104+
105+
- name: Get version
106+
shell: pwsh
107+
run: |
108+
$publishDir = Get-Item -Path publish
109+
[version]$version = (Import-PowerShellDataFile -Path "$($publishDir.FullName)\PsLogicAppExtractor\PsLogicAppExtractor.psd1").ModuleVersion
110+
$githubReleaseVersion = "$($version.Major).$($version.Minor).$($version.Build)"
111+
"VERSION=$githubReleaseVersion" >> $env:GITHUB_ENV
112+
113+
- name: Create GitHub release
114+
uses: softprops/action-gh-release@v3
115+
with:
116+
name: ${{ env.VERSION }}
117+
tag_name: ${{ env.VERSION }}
118+
draft: false
119+
prerelease: true
120+
generate_release_notes: true

.github/workflows/cache-warm.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Warm Module Cache
2+
3+
on:
4+
push:
5+
branches: [main, development]
6+
schedule:
7+
- cron: '0 6 * * 3,6' # Wednesday and Saturday 06:00 UTC
8+
workflow_dispatch:
9+
10+
jobs:
11+
warm-cache:
12+
runs-on: windows-latest
13+
steps:
14+
- name: Cache PowerShell modules
15+
id: cache-powershell-modules
16+
uses: actions/cache@v5
17+
with:
18+
path: ~\Documents\PowerShell\Modules
19+
key: ps-modules-${{ runner.os }}-v1
20+
21+
- name: Install modules
22+
if: steps.cache-powershell-modules.outputs.cache-hit != 'true'
23+
shell: pwsh
24+
run: |
25+
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
26+
$modules = @('Pester','PSFramework','PSModuleDevelopment','PSScriptAnalyzer','psake')
27+
foreach ($module in $modules) {
28+
Write-Host "Installing $module..."
29+
Install-Module -Name $module -Scope CurrentUser -Force -SkipPublisherCheck
30+
}

.github/workflows/validate.yml

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,64 @@
1-
name: Validate Module (Unit Tests)
1+
name: validate
22

3-
on:
4-
workflow_dispatch:
5-
pull_request:
6-
schedule:
7-
- cron: '13 4 * * 1'
3+
on: [pull_request]
84

95
jobs:
10-
validate:
11-
name: Run Pester Unit Tests
6+
general-unit-tests:
7+
name: Validate General Unit Tests
128
runs-on: windows-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
with:
12+
fetch-depth: 1
13+
14+
- name: Cache Powershell Modules
15+
id: cache-powershell-modules
16+
uses: actions/cache@v5
17+
with:
18+
path: ~\Documents\PowerShell\Modules
19+
key: ps-modules-${{ runner.os }}-v1
20+
21+
- name: Install Prerequisites
22+
if: steps.cache-powershell-modules.outputs.cache-hit != 'true'
23+
shell: pwsh
24+
run: |
25+
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
26+
$modules = @('Pester','PSFramework','PSModuleDevelopment','PSScriptAnalyzer','psake')
27+
foreach ($module in $modules) {
28+
Write-Host "Installing $module..."
29+
Install-Module -Name $module -Scope CurrentUser -Force -SkipPublisherCheck
30+
}
31+
32+
- name: Validate
33+
shell: pwsh
34+
run: build\vsts-validate.ps1 -TestGeneral $true -TestFunctions $false
1335

36+
individual-unit-tests:
37+
name: Validate Individual Unit Tests
38+
runs-on: windows-latest
1439
steps:
15-
- uses: actions/checkout@v2
16-
- name: Setup PowerShell module cache
17-
id: cacher
18-
uses: actions/cache@v3
40+
- uses: actions/checkout@v4
41+
with:
42+
fetch-depth: 1
43+
44+
- name: Cache Powershell Modules
45+
id: cache-powershell-modules
46+
uses: actions/cache@v5
1947
with:
20-
path: "C:\\Users\\runneradmin\\Documents\\PowerShell\\Modules"
21-
key: ${{ runner.os }}-PSFramework-PSScriptAnalyzer
22-
restore-keys: |
23-
${{ runner.os }}-PSFramework-
24-
${{ runner.os }}-
25-
${{ runner.os }}
48+
path: ~\Documents\PowerShell\Modules
49+
key: ps-modules-${{ runner.os }}-v1
50+
2651
- name: Install Prerequisites
27-
if: steps.cacher.outputs.cache-hit != 'true'
28-
run: .\build\vsts-prerequisites.ps1
52+
if: steps.cache-powershell-modules.outputs.cache-hit != 'true'
2953
shell: pwsh
54+
run: |
55+
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
56+
$modules = @('Pester','PSFramework','PSModuleDevelopment','PSScriptAnalyzer','psake')
57+
foreach ($module in $modules) {
58+
Write-Host "Installing $module..."
59+
Install-Module -Name $module -Scope CurrentUser -Force -SkipPublisherCheck
60+
}
61+
3062
- name: Validate
31-
run: .\build\vsts-validate.ps1
32-
shell: pwsh
63+
shell: pwsh
64+
run: build\vsts-validate.ps1 -TestGeneral $false -TestFunctions $true

build/vsts-validate.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,15 @@
33

44
# Needs to ensure things are Done Right and only legal commits to master get built
55

6+
param (
7+
$TestGeneral = $true,
8+
9+
$TestFunctions = $true,
10+
11+
$Include = "*",
12+
13+
$Exclude = "*.exclude.ps1"
14+
)
15+
616
# Run internal pester tests
7-
& "$PSScriptRoot\..\PsLogicAppExtractor\tests\pester.ps1"
17+
& "$PSScriptRoot\..\PsLogicAppExtractor\tests\pester.ps1" -TestGeneral $TestGeneral -TestFunctions $TestFunctions -Include $Include -Exclude $Exclude

0 commit comments

Comments
 (0)