Skip to content

Commit 9e9450f

Browse files
authored
CodeQl: Support repos with no packages. (#525)
The codeql workflow will attempting to locate Packages by finding folders ending with pkg and then attempting to find a .dsc located within that folder. For repos without any valid pkgs, the codeql workflow will generate an empty matrix. Adding a package_count variable to differentiate this scenario and gate creating and empty matrix. Most repos list the codeql Analyze task as a required check. With an empty matrix, this would fail. Skipping the Analyze task would result in a pending check that will never execute. Modify the codeql to create an empty sarif file when the package_count is zero and upload this. This will allow the Analyze step to run and pass CI when a repo contains no valid packages that can have results uploaded. This is being handled in this manor to allow the same CI checks to exist for repos which still contain a valid release/202502 branch, and a release/202511 branch which deprecates the repo.
1 parent 57fca6d commit 9e9450f

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

.sync/workflows/leaf/codeql.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
contents: read
4949
outputs:
5050
packages: ${{ steps.generate_matrix.outputs.packages }}
51+
package_count: ${{ steps.generate_matrix.outputs.package_count }}
5152

5253
steps:
5354
- name: Checkout repository
@@ -81,12 +82,14 @@ jobs:
8182
8283
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
8384
print(f'packages={json.dumps(packages)}', file=fh)
85+
print(f'package_count={len(packages)}', file=fh)
8486
8587
analyze:
8688
name: Analyze
8789
runs-on: windows-2022
8890
needs:
8991
- gather_packages
92+
if: needs.gather_packages.outputs.package_count != '0'
9093
permissions:
9194
actions: read
9295
contents: read
@@ -502,4 +505,49 @@ jobs:
502505
# Each package is a separate category.
503506
category: ${{ matrix.package }}
504507

508+
analyze_empty:
509+
name: Analyze
510+
runs-on: ubuntu-latest
511+
needs:
512+
- gather_packages
513+
if: needs.gather_packages.outputs.package_count == '0'
514+
permissions:
515+
actions: read
516+
contents: read
517+
security-events: write
518+
519+
steps:
520+
- name: Checkout repository
521+
uses: actions/checkout@v6
522+
523+
- name: Create Empty SARIF
524+
shell: python
525+
run: |
526+
import json
527+
528+
sarif = {
529+
"version": "2.1.0",
530+
"$schema": "https://json.schemastore.org/sarif-2.1.0.json",
531+
"runs": [
532+
{
533+
"tool": {
534+
"driver": {
535+
"name": "CodeQL",
536+
"informationUri": "https://github.com/github/codeql-action"
537+
}
538+
},
539+
"results": []
540+
}
541+
]
542+
}
543+
544+
with open('empty.sarif', 'w', encoding='utf-8') as f:
545+
json.dump(sarif, f)
546+
547+
- name: Upload Empty SARIF To GitHub Code Scanning
548+
uses: github/codeql-action/upload-sarif@v4
549+
with:
550+
sarif_file: empty.sarif
551+
category: no-packages
552+
505553
{% endraw %}

0 commit comments

Comments
 (0)