Skip to content

Commit e42ccae

Browse files
bolenscursoragent
andauthored
fix(ci): align CodeQL with actions-only analysis (#41)
* fix(ci): align CodeQL with actions-only analysis Drop leftover JS/TS path filters and dual query suites that disagreed with the actions language matrix, and include composite actions paths. Co-authored-by: Cursor <cursoragent@cursor.com> * fix(ci): handle empty Pester shard lists in matrix build Workflow-only changes produced @('') from Resolve-PesterCiShards, which failed Mandatory [string[]] binding in Get-PesterCiShardMatrix. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 3e4d974 commit e42ccae

4 files changed

Lines changed: 53 additions & 82 deletions

File tree

.github/workflows/codeql.yml

Lines changed: 23 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -9,104 +9,50 @@ on:
99
branches: [ main ]
1010
paths:
1111
- '.github/workflows/**'
12-
- '**/*.js'
13-
- '**/*.ts'
14-
- '**/*.mjs'
15-
- '**/*.cjs'
16-
- 'package.json'
17-
- 'pnpm-lock.yaml'
12+
- '.github/actions/**'
1813
- '.github/workflows/codeql.yml'
1914
pull_request:
2015
branches: [ main ]
2116
paths:
2217
- '.github/workflows/**'
23-
- '**/*.js'
24-
- '**/*.ts'
25-
- '**/*.mjs'
26-
- '**/*.cjs'
27-
- 'package.json'
28-
- 'pnpm-lock.yaml'
18+
- '.github/actions/**'
2919
- '.github/workflows/codeql.yml'
3020
schedule:
3121
# Run weekly on Mondays at 2 AM UTC
3222
- cron: '0 2 * * 1'
3323

24+
permissions:
25+
contents: read
26+
3427
jobs:
3528
analyze:
3629
name: Analyze (${{ matrix.language }})
3730
runs-on: ubuntu-latest
3831
permissions:
3932
actions: read
4033
contents: read
41-
issues: write
4234
security-events: write
43-
pull-requests: write
4435

4536
strategy:
4637
fail-fast: false
4738
matrix:
48-
language: [ 'actions' ]
39+
include:
40+
- language: actions
41+
build-mode: none
4942

5043
steps:
51-
- name: Checkout repository
52-
uses: actions/checkout@v7
53-
54-
- name: Initialize CodeQL
55-
uses: github/codeql-action/init@v4
56-
with:
57-
languages: ${{ matrix.language }}
58-
queries: security-extended,security-and-quality
59-
60-
- name: Perform CodeQL Analysis
61-
id: analyze
62-
uses: github/codeql-action/analyze@v4
63-
with:
64-
category: "/language:${{matrix.language}}"
65-
upload: true
66-
67-
- name: Comment PR with CodeQL Results
68-
if: github.event_name == 'pull_request' && steps.analyze.outcome == 'success'
69-
uses: actions/github-script@v9
70-
with:
71-
script: |
72-
const body = `🔍 **CodeQL Analysis Complete** (${{ matrix.language }})
73-
74-
CodeQL analysis has completed successfully. Results are available in the **Security** tab of this PR.
75-
76-
**Language Analyzed:** ${{ matrix.language }}
77-
**Query Suite:** security-extended, security-and-quality
78-
79-
📋 **View Results:**
80-
- Check the Security tab above for detailed findings
81-
- Review any alerts and address them before merging
82-
83-
> **Note:** CodeQL does not natively support PowerShell. This analysis covers GitHub Actions workflows in \`.github/workflows\`.
84-
85-
*Analysis performed automatically by CodeQL*`;
86-
87-
github.rest.issues.createComment({
88-
issue_number: context.issue.number,
89-
owner: context.repo.owner,
90-
repo: context.repo.repo,
91-
body: body
92-
});
93-
94-
- name: Comment PR with CodeQL Errors
95-
if: github.event_name == 'pull_request' && steps.analyze.outcome == 'failure'
96-
uses: actions/github-script@v9
97-
with:
98-
script: |
99-
const body = `❌ **CodeQL Analysis Failed** (${{ matrix.language }})
100-
101-
CodeQL analysis encountered an error. Please check the workflow logs for details.
102-
103-
**Language:** ${{ matrix.language }}
104-
105-
*Check the workflow run for error details.*`;
106-
107-
github.rest.issues.createComment({
108-
issue_number: context.issue.number,
109-
owner: context.repo.owner,
110-
repo: context.repo.repo,
111-
body: body
112-
});
44+
- name: Checkout repository
45+
uses: actions/checkout@v7
46+
47+
- name: Initialize CodeQL
48+
uses: github/codeql-action/init@v4
49+
with:
50+
languages: ${{ matrix.language }}
51+
build-mode: ${{ matrix.build-mode }}
52+
# security-and-quality includes security-extended for Actions workflows
53+
queries: security-and-quality
54+
55+
- name: Perform CodeQL Analysis
56+
uses: github/codeql-action/analyze@v4
57+
with:
58+
category: "/language:${{ matrix.language }}"

.github/workflows/test-pester.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ jobs:
5757
}
5858
}
5959
60-
$include = @(Get-PesterCiShardMatrix -Shards $shards)
60+
# Coerce to [string[]] so empty "no matching shards" stays an empty array
61+
# (bare @() / $null can bind as '' and fail Mandatory [string[]]).
62+
$shardList = [string[]]@($shards | Where-Object { -not [string]::IsNullOrWhiteSpace($_) })
63+
$include = @(Get-PesterCiShardMatrix -Shards $shardList)
6164
$any = $include.Count -gt 0
6265
$matrix = if ($any) {
6366
@{ include = @($include) } | ConvertTo-Json -Compress -Depth 5

scripts/utils/code-quality/modules/PesterCiShardFilter.psm1

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,9 @@ function Resolve-PesterCiShards {
380380
})
381381

382382
if ($files.Count -eq 0) {
383-
# Unary comma preserves empty [string[]] (bare `return @()` unwraps to $null).
384-
return , [string[]]@()
383+
# Emit nothing so call-site `@()` is a true empty array (Count 0).
384+
# Unary-comma / -NoEnumerate empty [string[]] still becomes @('') under `@()`.
385+
return
385386
}
386387

387388
foreach ($ruleName in $rules.Keys) {
@@ -406,7 +407,7 @@ function Resolve-PesterCiShards {
406407

407408
$ordered = [string[]]@($shards | Sort-Object)
408409
if ($ordered.Count -eq 0) {
409-
return , [string[]]@()
410+
return
410411
}
411412
return $ordered
412413
}
@@ -421,14 +422,22 @@ function Get-PesterCiShardMatrix {
421422
param(
422423
[Parameter(Mandatory)]
423424
[AllowEmptyCollection()]
425+
[AllowEmptyString()]
426+
[AllowNull()]
424427
[string[]]$Shards
425428
)
426429

427430
$windowsShards = @(Get-PesterCiWindowsShards)
428431
$archShards = @(Get-PesterCiArchShards)
429432
$include = [System.Collections.Generic.List[object]]::new()
430433

431-
foreach ($shard in ($Shards | Sort-Object -Unique)) {
434+
# Empty `@()` / `$null` / `''` can arrive from GHA when no shards match changed paths.
435+
$shardNames = @(
436+
$Shards |
437+
Where-Object { -not [string]::IsNullOrWhiteSpace($_) } |
438+
Sort-Object -Unique
439+
)
440+
foreach ($shard in $shardNames) {
432441
# Performance shards are Windows-only (historically flaky / slow on Ubuntu).
433442
if ($shard -notlike 'performance*') {
434443
$include.Add([pscustomobject]@{

tests/unit/test-runner/ci/test-runner-pester-ci-shard-filter.tests.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ Describe 'PesterCiShardFilter' {
7777
$matrix | Where-Object { $_.label -eq 'arch-latest' -and $_.shard -eq 'coverage-smoke' } | Should -Not -BeNullOrEmpty
7878
}
7979

80+
It 'Accepts empty or blank shard lists without throwing' {
81+
@(Get-PesterCiShardMatrix -Shards @()) | Should -HaveCount 0
82+
@(Get-PesterCiShardMatrix -Shards @('')) | Should -HaveCount 0
83+
@(Get-PesterCiShardMatrix -Shards $null) | Should -HaveCount 0
84+
}
85+
86+
It 'Returns a true empty array for workflow-only changes with no Pester shards' {
87+
$shards = @(Resolve-PesterCiShards -ChangedFiles @('.github/workflows/codeql.yml'))
88+
$shards.Count | Should -Be 0
89+
@($shards | Where-Object { -not [string]::IsNullOrWhiteSpace($_) }) | Should -HaveCount 0
90+
@(Get-PesterCiShardMatrix -Shards ([string[]]@($shards))) | Should -HaveCount 0
91+
}
92+
8093
It 'Exposes a curated Arch shard set' {
8194
$arch = Get-PesterCiArchShards
8295
$arch | Should -Contain 'unit-library'

0 commit comments

Comments
 (0)