Skip to content

Commit 123ba46

Browse files
claudeHeyItsGilbert
authored andcommitted
Fix GitHub Actions documentation inaccuracies
- Remove non-existent PowerShell/setup-powershell action reference - Clarify that PowerShell 7.4+ (pwsh) is pre-installed on all runners - Document that Windows PowerShell 5.1 (powershell) is Windows-only - Simplify cross-platform matrix builds (no PowerShell setup needed) - Add separate example for testing with Windows PowerShell 5.1 - Fix invalid cache path conditional syntax - Update execution policy troubleshooting with platform clarity
1 parent 2f21975 commit 123ba46

File tree

1 file changed

+41
-15
lines changed

1 file changed

+41
-15
lines changed

docs/ci-examples/github-actions.md

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ jobs:
3535
Invoke-psake -buildFile .\psakefile.ps1 -taskList Build
3636
```
3737
38+
## PowerShell on GitHub-Hosted Runners
39+
40+
GitHub-hosted runners come with PowerShell pre-installed on all platforms:
41+
42+
- **PowerShell 7.4+ (`pwsh`)**: Available on Windows, Linux, and macOS runners
43+
- **Windows PowerShell 5.1 (`powershell`)**: Only available on Windows runners
44+
45+
**Important:** Always use `shell: pwsh` in your workflows for cross-platform compatibility. Only use `shell: powershell` if you specifically need Windows PowerShell 5.1 features.
46+
3847
## Installing psake in GitHub Actions
3948

4049
There are several approaches to installing psake in your workflow:
@@ -202,23 +211,13 @@ jobs:
202211
fail-fast: false
203212
matrix:
204213
os: [windows-latest, ubuntu-latest, macos-latest]
205-
powershell-version: ['7.2', '7.4']
206-
include:
207-
- os: windows-latest
208-
powershell-version: '5.1'
209214

210215
runs-on: ${{ matrix.os }}
211216

212217
steps:
213218
- name: Checkout code
214219
uses: actions/checkout@v4
215220

216-
- name: Setup PowerShell ${{ matrix.powershell-version }}
217-
if: matrix.powershell-version != '5.1'
218-
uses: PowerShell/setup-powershell@v1
219-
with:
220-
powershell-version: ${{ matrix.powershell-version }}
221-
222221
- name: Install psake
223222
shell: pwsh
224223
run: Install-Module -Name psake -Scope CurrentUser -Force
@@ -238,10 +237,34 @@ jobs:
238237
- name: Upload artifacts
239238
uses: actions/upload-artifact@v4
240239
with:
241-
name: build-${{ matrix.os }}-ps${{ matrix.powershell-version }}
240+
name: build-${{ matrix.os }}
242241
path: ./build/
243242
```
244243
244+
**Testing with Windows PowerShell 5.1:**
245+
246+
If you need to test specifically with Windows PowerShell 5.1, add a separate job:
247+
248+
```yaml
249+
jobs:
250+
build-cross-platform:
251+
# ... pwsh matrix build from above ...
252+
253+
build-windows-powershell:
254+
runs-on: windows-latest
255+
steps:
256+
- name: Checkout code
257+
uses: actions/checkout@v4
258+
259+
- name: Install psake
260+
shell: powershell # Windows PowerShell 5.1
261+
run: Install-Module -Name psake -Scope CurrentUser -Force
262+
263+
- name: Run psake build
264+
shell: powershell
265+
run: Invoke-psake -buildFile .\psakefile.ps1 -taskList Build, Test
266+
```
267+
245268
## Secret Management
246269
247270
GitHub Actions provides a secure way to store and use secrets in your workflows.
@@ -470,13 +493,15 @@ Task Publish -depends Pack {
470493
471494
**Problem:** Scripts fail due to execution policy on Windows runners
472495
473-
**Solution:** Use `pwsh` shell (PowerShell Core) instead of `powershell` (Windows PowerShell):
496+
**Solution:** Use `shell: pwsh` (PowerShell 7) instead of `shell: powershell` (Windows PowerShell 5.1):
474497
```yaml
475498
- name: Run psake
476-
shell: pwsh # Not 'powershell'
499+
shell: pwsh # PowerShell 7 - available on all platforms
477500
run: Invoke-psake
478501
```
479502

503+
**Note:** The `pwsh` shell is available on Windows, Linux, and macOS runners. The `powershell` shell is only available on Windows and may have stricter execution policies.
504+
480505
### Build Failures Not Failing the Workflow
481506

482507
**Problem:** psake build fails but workflow shows success
@@ -527,14 +552,15 @@ Properties {
527552

528553
**Problem:** Cache doesn't restore modules correctly
529554

530-
**Solution:** Use platform-specific cache paths:
555+
**Solution:** List both Windows and Unix paths—GitHub Actions will cache what exists:
531556

532557
```yaml
533558
- name: Cache PowerShell modules
534559
uses: actions/cache@v4
535560
with:
536561
path: |
537-
${{ runner.os == 'Windows' && '~\Documents\PowerShell\Modules' || '~/.local/share/powershell/Modules' }}
562+
~/.local/share/powershell/Modules
563+
~/Documents/PowerShell/Modules
538564
key: ${{ runner.os }}-psake-${{ hashFiles('**/requirements.psd1') }}
539565
```
540566

0 commit comments

Comments
 (0)