Skip to content

Commit 2066eb6

Browse files
authored
Convert powershell/PowerShell-Windows-CI to GitHub Actions (PowerShell#24899)
1 parent 2259f56 commit 2066eb6

File tree

9 files changed

+356
-44
lines changed

9 files changed

+356
-44
lines changed

.github/actions/build/ci/action.yml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: CI Build
2+
description: 'Builds PowerShell'
3+
runs:
4+
using: composite
5+
steps:
6+
- name: Capture Environment
7+
if: success() || failure()
8+
run: 'Get-ChildItem -Path env: | Out-String -width 9999 -Stream | write-Verbose -Verbose'
9+
shell: pwsh
10+
- name: Set Build Name for Non-PR
11+
if: github.event_name != 'PullRequest'
12+
run: Write-Host "##vso[build.updatebuildnumber]$env:BUILD_SOURCEBRANCHNAME-$env:BUILD_SOURCEVERSION-$((get-date).ToString("yyyyMMddhhmmss"))"
13+
shell: pwsh
14+
- name: Bootstrap
15+
if: success()
16+
run: |-
17+
Write-Verbose -Verbose "Running Bootstrap..."
18+
Import-Module .\tools\ci.psm1
19+
Invoke-CIInstall -SkipUser
20+
Write-Verbose -Verbose "Start Sync-PSTags"
21+
Sync-PSTags -AddRemoteIfMissing
22+
Write-Verbose -Verbose "End Sync-PSTags"
23+
shell: pwsh
24+
- name: Build
25+
if: success()
26+
run: |-
27+
Write-Verbose -Verbose "Running Build..."
28+
Import-Module .\tools\ci.psm1
29+
Invoke-CIBuild
30+
shell: pwsh
31+
- name: xUnit Tests
32+
if: success()
33+
continue-on-error: true
34+
run: |-
35+
Write-Verbose -Verbose "Running xUnit tests..."
36+
Import-Module .\tools\ci.psm1
37+
Restore-PSOptions
38+
Invoke-CIxUnit -SkipFailing
39+
shell: pwsh
40+
- name: Upload build artifact
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: build
44+
path: ${{ runner.workspace }}/build
45+
- name: Upload xunit artifact
46+
uses: actions/upload-artifact@v4
47+
with:
48+
name: testResults-xunit
49+
path: ${{ runner.workspace }}/xunit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: verify_xunit
2+
description: 'Verify xUnit Results'
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Download build artifacts
8+
uses: actions/download-artifact@v4
9+
with:
10+
path: "${{ github.workspace }}"
11+
- name: Capture artifacts directory
12+
continue-on-error: true
13+
run: dir "${{ github.workspace }}\testResults-xunit\*" -Recurse
14+
shell: pwsh
15+
- name: Test
16+
if: success()
17+
run: |-
18+
Import-Module .\tools\ci.psm1
19+
$xUnitTestResultsFile = "${{ github.workspace }}\testResults-xunit\xUnitTestResults.xml"
20+
Test-XUnitTestResults -TestResultsFile $xUnitTestResultsFile
21+
shell: pwsh
+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: windows_test
2+
description: 'Test PowerShell on Windows'
3+
4+
inputs:
5+
purpose:
6+
required: false
7+
default: ''
8+
type: string
9+
tagSet:
10+
required: false
11+
default: CI
12+
type: string
13+
ctrfFolder:
14+
required: false
15+
default: ctrf
16+
type: string
17+
18+
runs:
19+
using: composite
20+
steps:
21+
- name: Capture Environment
22+
if: success() || failure()
23+
run: 'Get-ChildItem -Path env: | Out-String -width 9999 -Stream | write-Verbose -Verbose'
24+
shell: pwsh
25+
- name: Download Build Artifacts
26+
uses: actions/download-artifact@v4
27+
with:
28+
path: "${{ github.workspace }}"
29+
- name: Capture Artifacts Directory
30+
continue-on-error: true
31+
run: Get-ChildItem "${{ github.workspace }}\build\*" -Recurse
32+
shell: pwsh
33+
34+
- name: Bootstrap
35+
shell: powershell
36+
run: |-
37+
# Remove "Program Files\dotnet" from the env variable PATH, so old SDKs won't affect us.
38+
Write-Host "Old Path:"
39+
Write-Host $env:Path
40+
$dotnetPath = Join-Path $env:SystemDrive 'Program Files\dotnet'
41+
$paths = $env:Path -split ";" | Where-Object { -not $_.StartsWith($dotnetPath) }
42+
$env:Path = $paths -join ";"
43+
Write-Host "New Path:"
44+
Write-Host $env:Path
45+
# Bootstrap
46+
Import-Module .\tools\ci.psm1
47+
Invoke-CIInstall
48+
49+
- name: Test
50+
if: success()
51+
run: |-
52+
Import-Module .\build.psm1 -force
53+
Start-PSBootstrap
54+
Import-Module .\tools\ci.psm1
55+
Restore-PSOptions -PSOptionsPath '${{ github.workspace }}\build\psoptions.json'
56+
$options = (Get-PSOptions)
57+
$path = split-path -path $options.Output
58+
$rootPath = split-Path -path $path
59+
Expand-Archive -Path '${{ github.workspace }}\build\build.zip' -DestinationPath $rootPath -Force
60+
Invoke-CITest -Purpose '${{ inputs.purpose }}' -TagSet '${{ inputs.tagSet }}' -OutputFormat JUnitXml
61+
shell: pwsh
62+
63+
- name: Convert JUnit to CTRF
64+
run: |-
65+
Get-ChildItem -Path "${{ runner.workspace }}/testResults/*.xml" -Recurse | ForEach-Object {
66+
npx --yes junit-to-ctrf $_.FullName --output .\${{ inputs.ctrfFolder }}\$($_.BaseName).json --tool Pester --env 'Windows ${{ inputs.purpose }} ${{ inputs.tagSet }}'
67+
}
68+
shell: powershell
69+
70+
# this task only takes / as directory separators
71+
- name: Publish Test Report
72+
uses: ctrf-io/github-test-reporter@v1
73+
with:
74+
report-path: './${{ inputs.ctrfFolder }}/*.json'
75+
exit-on-fail: true
76+
summary-report: true
77+
test-report: false
78+
test-list-report: false
79+
failed-report: false
80+
fail-rate-report: false
81+
flaky-report: false
82+
flaky-rate-report: false
83+
failed-folded-report: true
84+
previous-results-report: false
85+
ai-report: true
86+
skipped-report: false
87+
suite-folded-report: false
88+
suite-list-report: false
89+
pull-request-report: false
90+
commit-report: false
91+
custom-report: false
92+
93+
if: always()
94+
95+
- name: Upload testResults artifact
96+
if: always()
97+
uses: actions/upload-artifact@v4
98+
with:
99+
name: junit-pester-${{ inputs.purpose }}-${{ inputs.tagSet }}
100+
path: ${{ runner.workspace }}\testResults
101+
102+
- name: Upload ctrf artifact
103+
if: always()
104+
uses: actions/upload-artifact@v4
105+
with:
106+
name: ctrf-pester-${{ inputs.purpose }}-${{ inputs.tagSet }}
107+
path: ${{ inputs.ctrfFolder }}

.github/workflows/AssignPrs.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Auto Assign PR Maintainer
22
on:
3-
pull_request:
3+
issues:
44
types: [opened, edited]
55
permissions:
66
contents: read
@@ -13,6 +13,7 @@ jobs:
1313
pull-requests: write
1414
steps:
1515
- uses: wow-actions/auto-assign@67fafa03df61d7e5f201734a2fa60d1ab111880d # v3.0.2
16+
if: github.event.issue.pull_request
1617
with:
1718
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1819
# using the `org/team_slug` or `/team_slug` syntax to add git team as reviewers

.github/workflows/rebase.yml

-39
This file was deleted.

.github/workflows/windows-ci.yml

+124
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Windows-CI
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches:
6+
- master
7+
- release*
8+
- feature*
9+
paths:
10+
- "*"
11+
- "!.vsts-ci/misc-analysis.yml"
12+
- "!.github/ISSUE_TEMPLATE/*"
13+
- "!.github/workflows/*"
14+
- "!.dependabot/config.yml"
15+
- "!test/perf/*"
16+
- "!.pipelines/*"
17+
pull_request:
18+
branches:
19+
- master
20+
- release*
21+
- feature*
22+
paths:
23+
- ".vsts-ci/templates/*"
24+
- ".vsts-ci/windows.yml"
25+
- "*.props"
26+
- build.psm1
27+
- src/*
28+
- test/*
29+
- tools/buildCommon/*
30+
- tools/ci.psm1
31+
- tools/WindowsCI.psm1
32+
- "!test/common/markdown/*"
33+
- "!test/perf/*"
34+
permissions:
35+
contents: read
36+
37+
run-name: "${{ github.ref_name }} - ${{ github.run_number }}"
38+
39+
env:
40+
DOTNET_CLI_TELEMETRY_OPTOUT: 1
41+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
42+
GIT_CONFIG_PARAMETERS: "'core.autocrlf=false'"
43+
NugetSecurityAnalysisWarningLevel: none
44+
POWERSHELL_TELEMETRY_OPTOUT: 1
45+
__SuppressAnsiEscapeSequences: 1
46+
nugetMultiFeedWarnLevel: none
47+
jobs:
48+
ci_build:
49+
name: Build PowerShell
50+
runs-on: windows-latest
51+
steps:
52+
- name: checkout
53+
uses: actions/[email protected]
54+
with:
55+
fetch-depth: 1000
56+
- name: Build
57+
uses: "./.github/actions/build/ci"
58+
windows_test:
59+
name: Windows Unelevated CI
60+
needs: ci_build
61+
runs-on: windows-latest
62+
steps:
63+
- name: checkout
64+
uses: actions/[email protected]
65+
with:
66+
fetch-depth: 1000
67+
- name: Windows Unelevated CI
68+
uses: "./.github/actions/test/windows"
69+
with:
70+
purpose: UnelevatedPesterTests
71+
tagSet: CI
72+
windows_test_2:
73+
name: Windows Elevated CI
74+
needs: ci_build
75+
runs-on: windows-latest
76+
steps:
77+
- name: checkout
78+
uses: actions/[email protected]
79+
with:
80+
fetch-depth: 1000
81+
- name: Windows Elevated CI
82+
uses: "./.github/actions/test/windows"
83+
with:
84+
purpose: ElevatedPesterTests
85+
tagSet: CI
86+
windows_test_3:
87+
name: Windows Unelevated Others
88+
needs: ci_build
89+
runs-on: windows-latest
90+
steps:
91+
- name: checkout
92+
uses: actions/[email protected]
93+
with:
94+
fetch-depth: 1000
95+
- name: Windows Unelevated Others
96+
uses: "./.github/actions/test/windows"
97+
with:
98+
purpose: UnelevatedPesterTests
99+
tagSet: Others
100+
windows_test_4:
101+
name: Windows Elevated Others
102+
needs: ci_build
103+
runs-on: windows-latest
104+
steps:
105+
- name: checkout
106+
uses: actions/[email protected]
107+
with:
108+
fetch-depth: 1000
109+
- name: Windows Elevated Others
110+
uses: "./.github/actions/test/windows"
111+
with:
112+
purpose: ElevatedPesterTests
113+
tagSet: Others
114+
verify_xunit:
115+
name: Verify xUnit test results
116+
needs: ci_build
117+
runs-on: windows-latest
118+
steps:
119+
- name: checkout
120+
uses: actions/[email protected]
121+
with:
122+
fetch-depth: 1000
123+
- name: Verify xUnit test results
124+
uses: "./.github/actions/test/verify_xunit"

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,10 @@ msbuild.binlog
111111

112112
# Ignore gzip files in the manpage folder
113113
assets/manpage/*.gz
114+
115+
# Ignore files and folders generated by some gh cli extensions
116+
tmp/*
117+
.env.local
118+
119+
# Ignore CTRF report files
120+
crtf/*

build.psm1

+10
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,16 @@ function Publish-TestResults
17581758

17591759
$resolvedPath = (Resolve-Path -Path $Path).ProviderPath
17601760
Write-Host "##vso[artifact.upload containerfolder=testResults;artifactname=testResults]$resolvedPath"
1761+
} elseif ($env:GITHUB_WORKFLOW -and $env:RUNNER_WORKSPACE) {
1762+
# In GitHub Actions
1763+
$destinationPath = Join-Path -Path $env:RUNNER_WORKSPACE -ChildPath 'testResults'
1764+
1765+
# Create the folder if it does not exist
1766+
if (!(Test-Path -Path $destinationPath)) {
1767+
$null = New-Item -ItemType Directory -Path $destinationPath -Force
1768+
}
1769+
1770+
Copy-Item -Path $Path -Destination $destinationPath -Force -Verbose
17611771
}
17621772
}
17631773

0 commit comments

Comments
 (0)