Skip to content

Commit d13cdad

Browse files
CopilotTravisEz13
andauthored
Fix linux_packaging job being skipped when only packaging files change (#26315)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: TravisEz13 <10873629+TravisEz13@users.noreply.github.com>
1 parent be195a4 commit d13cdad

File tree

4 files changed

+136
-57
lines changed

4 files changed

+136
-57
lines changed

.github/actions/infrastructure/path-filters/action.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,14 @@ runs:
8888
8989
const globalConfigChanged = files.some(file => file.filename.startsWith('.globalconfig')) || files.some(file => file.filename.startsWith('nuget.config')) || files.some(file => file.filename.startsWith('global.json'));
9090
91-
const packagingChanged = files.some(file =>
91+
const packagingChanged = files.some(file =>
9292
file.filename === '.github/workflows/windows-ci.yml' ||
93+
file.filename === '.github/workflows/linux-ci.yml' ||
9394
file.filename.startsWith('assets/wix/') ||
9495
file.filename === 'PowerShell.Common.props' ||
9596
file.filename.match(/^src\/.*\.csproj$/) ||
9697
file.filename.startsWith('test/packaging/windows/') ||
98+
file.filename.startsWith('test/packaging/linux/') ||
9799
file.filename.startsWith('tools/packaging/') ||
98100
file.filename.startsWith('tools/wix/')
99101
) ||
@@ -112,7 +114,7 @@ runs:
112114
core.setOutput('globalConfigChanged', globalConfigChanged);
113115
core.setOutput('packagingChanged', packagingChanged);
114116
core.setOutput('source', source);
115-
117+
116118
117119
- name: Capture outputs
118120
run: |

.github/actions/test/linux-packaging/action.yml

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,68 +13,19 @@ runs:
1313
with:
1414
global-json-file: ./global.json
1515

16-
- name: Download Build Artifacts
17-
uses: actions/download-artifact@v4
18-
with:
19-
name: build
20-
path: "${{ runner.workspace }}/build"
21-
22-
- name: Capture Artifacts Directory
23-
continue-on-error: true
24-
run: Get-ChildItem "${{ runner.workspace }}/build/*" -Recurse
25-
shell: pwsh
26-
2716
- name: Bootstrap
2817
run: |-
2918
Import-Module ./build.psm1
3019
Start-PSBootstrap -Scenario Package
31-
Write-Verbose -Verbose "Start Sync-PSTags"
32-
Sync-PSTags -AddRemoteIfMissing
33-
Write-Verbose -Verbose "End Sync-PSTags"
34-
shell: pwsh
35-
36-
- name: Extract Build ZIP
37-
run: |-
38-
$destinationFolder = "${{ runner.workspace }}/bins"
39-
$archiveFile = "${{ runner.workspace }}/build/build.zip"
40-
41-
Write-Verbose "Extracting $archiveFile to $destinationFolder" -Verbose
42-
New-Item -ItemType Directory -Path $destinationFolder -Force | Out-Null
43-
Expand-Archive -Path $archiveFile -DestinationPath $destinationFolder -Force
44-
shell: pwsh
45-
46-
- name: Fix permissions
47-
continue-on-error: true
48-
run: |-
49-
find "${{ runner.workspace }}/bins" -type d -exec chmod +rwx {} \;
50-
find "${{ runner.workspace }}/bins" -type f -exec chmod +rw {} \;
51-
shell: bash
52-
53-
- name: Capture Extracted Build ZIP
54-
continue-on-error: true
55-
run: Get-ChildItem "${{ runner.workspace }}/bins/*" -Recurse -ErrorAction SilentlyContinue
20+
Import-Module ./tools/ci.psm1
21+
Invoke-CIInstall -SkipUser
5622
shell: pwsh
5723

58-
- name: Create Packages
59-
env:
60-
BUILD_ARTIFACTSTAGINGDIRECTORY: ${{ runner.workspace }}/packages
24+
- name: Build and Package
6125
run: |-
62-
# Create the artifacts staging directory
63-
New-Item -ItemType Directory -Path "$env:BUILD_ARTIFACTSTAGINGDIRECTORY" -Force | Out-Null
64-
65-
# Import packaging module to ensure RPM packaging changes are loaded
66-
Import-Module ./build.psm1 -Force
67-
Import-Module ./tools/packaging/packaging.psm1 -Force
6826
Import-Module ./tools/ci.psm1
69-
Restore-PSOptions -PSOptionsPath '${{ runner.workspace }}/build/psoptions.json'
70-
$options = (Get-PSOptions)
71-
$rootPath = '${{ runner.workspace }}/bins'
72-
$originalRootPath = Split-Path -path $options.Output
73-
$path = Join-Path -path $rootPath -ChildPath (split-path -leaf -path $originalRootPath)
74-
$pwshPath = Join-Path -path $path -ChildPath 'pwsh'
75-
chmod a+x $pwshPath
76-
$options.Output = $pwshPath
77-
Set-PSOptions $options
27+
$releaseTag = Get-ReleaseTag
28+
Start-PSBuild -Configuration 'Release' -ReleaseTag $releaseTag
7829
Invoke-CIFinish
7930
shell: pwsh
8031

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
applyTo:
3+
- ".github/actions/**/*.yml"
4+
- ".github/workflows/**/*.yml"
5+
---
6+
7+
# Build and Packaging Steps Pattern
8+
9+
## Important Rule
10+
11+
**Build and packaging must run in the same step OR you must save and restore PSOptions between steps.**
12+
13+
## Why This Matters
14+
15+
When `Start-PSBuild` runs, it creates PSOptions that contain build configuration details (runtime, configuration, output path, etc.). The packaging functions like `Start-PSPackage` and `Invoke-CIFinish` rely on these PSOptions to know where the build output is located and how it was built.
16+
17+
GitHub Actions steps run in separate PowerShell sessions. This means PSOptions from one step are not available in the next step.
18+
19+
## Pattern 1: Combined Build and Package (Recommended)
20+
21+
Run build and packaging in the same step to keep PSOptions in memory:
22+
23+
```yaml
24+
- name: Build and Package
25+
run: |-
26+
Import-Module ./tools/ci.psm1
27+
$releaseTag = Get-ReleaseTag
28+
Start-PSBuild -Configuration 'Release' -ReleaseTag $releaseTag
29+
Invoke-CIFinish
30+
shell: pwsh
31+
```
32+
33+
**Benefits:**
34+
- Simpler code
35+
- No need for intermediate files
36+
- PSOptions automatically available to packaging
37+
38+
## Pattern 2: Separate Steps with Save/Restore
39+
40+
If you must separate build and packaging into different steps:
41+
42+
```yaml
43+
- name: Build PowerShell
44+
run: |-
45+
Import-Module ./tools/ci.psm1
46+
$releaseTag = Get-ReleaseTag
47+
Start-PSBuild -Configuration 'Release' -ReleaseTag $releaseTag
48+
Save-PSOptions -PSOptionsPath "${{ runner.workspace }}/psoptions.json"
49+
shell: pwsh
50+
51+
- name: Create Packages
52+
run: |-
53+
Import-Module ./tools/ci.psm1
54+
Restore-PSOptions -PSOptionsPath "${{ runner.workspace }}/psoptions.json"
55+
Invoke-CIFinish
56+
shell: pwsh
57+
```
58+
59+
**When to use:**
60+
- When you need to run other steps between build and packaging
61+
- When build and packaging require different permissions or environments
62+
63+
## Common Mistakes
64+
65+
### ❌ Incorrect: Separate steps without save/restore
66+
67+
```yaml
68+
- name: Build PowerShell
69+
run: |-
70+
Start-PSBuild -Configuration 'Release'
71+
shell: pwsh
72+
73+
- name: Create Packages
74+
run: |-
75+
Invoke-CIFinish # ❌ FAILS: PSOptions not available
76+
shell: pwsh
77+
```
78+
79+
### ❌ Incorrect: Using artifacts without PSOptions
80+
81+
```yaml
82+
- name: Download Build Artifacts
83+
uses: actions/download-artifact@v4
84+
with:
85+
name: build
86+
87+
- name: Create Packages
88+
run: |-
89+
Invoke-CIFinish # ❌ FAILS: PSOptions not restored
90+
shell: pwsh
91+
```
92+
93+
## Related Functions
94+
95+
- `Start-PSBuild` - Builds PowerShell and sets PSOptions
96+
- `Save-PSOptions` - Saves PSOptions to a JSON file
97+
- `Restore-PSOptions` - Loads PSOptions from a JSON file
98+
- `Get-PSOptions` - Gets current PSOptions
99+
- `Set-PSOptions` - Sets PSOptions
100+
- `Start-PSPackage` - Creates packages (requires PSOptions)
101+
- `Invoke-CIFinish` - Calls packaging (requires PSOptions on Linux/macOS)
102+
103+
## Examples
104+
105+
### Linux Packaging Action
106+
107+
```yaml
108+
- name: Build and Package
109+
run: |-
110+
Import-Module ./tools/ci.psm1
111+
$releaseTag = Get-ReleaseTag
112+
Start-PSBuild -Configuration 'Release' -ReleaseTag $releaseTag
113+
Invoke-CIFinish
114+
shell: pwsh
115+
```
116+
117+
### Windows Packaging Workflow
118+
119+
```yaml
120+
- name: Build and Package
121+
run: |
122+
Import-Module .\tools\ci.psm1
123+
Invoke-CIFinish -Runtime ${{ matrix.runtimePrefix }}-${{ matrix.architecture }} -channel ${{ matrix.channel }}
124+
shell: pwsh
125+
```
126+
127+
Note: `Invoke-CIFinish` for Windows includes both build and packaging in its logic when `Stage` contains 'Build'.

.github/workflows/linux-ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ jobs:
233233
linux_packaging:
234234
name: Linux Packaging
235235
needs:
236-
- ci_build
237236
- changes
238237
if: ${{ needs.changes.outputs.packagingChanged == 'true' }}
239238
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)