|
| 1 | +# Code Scanning Setup Guide |
| 2 | + |
| 3 | +This document explains how to resolve code scanning configuration issues in this repository and maintain compliance with organizational policies. |
| 4 | + |
| 5 | +## Current Configuration |
| 6 | + |
| 7 | +This repository has two CodeQL code scanning configurations: |
| 8 | + |
| 9 | +1. **Default Setup** (managed by GitHub) — Configured in **Settings > Code security > Code scanning**. This is GitHub's built-in scanning that runs automatically without a workflow file. |
| 10 | + |
| 11 | +2. **Custom Workflow** (`.github/workflows/codeql.yml`) — A workflow file in the repository that provides more control over the scanning process, including the `security-and-quality` query suite. |
| 12 | + |
| 13 | +## Known Issue: Stale Configuration Error |
| 14 | + |
| 15 | +The custom CodeQL workflow (`codeql.yml`) was previously **manually disabled**, which causes the code scanning status page to show an error or stale configuration at: |
| 16 | + |
| 17 | +> **Security** > **Code scanning** > **Tool status** > **CodeQL** > **Configurations** |
| 18 | +
|
| 19 | +This happens because GitHub detects the workflow configuration but finds no recent scan results from it. |
| 20 | + |
| 21 | +## How to Resolve |
| 22 | + |
| 23 | +You have two options — choose **one**: |
| 24 | + |
| 25 | +### Option A: Use the Custom Workflow (Recommended) |
| 26 | + |
| 27 | +The custom workflow provides more thorough analysis with the `security-and-quality` query suite. |
| 28 | + |
| 29 | +1. Go to **Actions** > **CodeQL** (the workflow, not the default setup) |
| 30 | +2. Click **Enable workflow** to re-enable the disabled `codeql.yml` |
| 31 | +3. Optionally, trigger a manual run via **Run workflow** to verify it works |
| 32 | +4. Go to **Settings** > **Code security** > **Code scanning** and disable the **Default setup** to avoid duplicate scanning |
| 33 | +5. Verify the workflow completes successfully and results appear under **Security** > **Code scanning** |
| 34 | + |
| 35 | +### Option B: Use the Default Setup Only |
| 36 | + |
| 37 | +If you prefer the simpler GitHub-managed scanning: |
| 38 | + |
| 39 | +1. Verify the Default Setup is enabled in **Settings** > **Code security** > **Code scanning** |
| 40 | +2. **Delete** the file `.github/workflows/codeql.yml` from the repository to remove the stale configuration |
| 41 | +3. Commit and push the deletion |
| 42 | +4. The stale configuration error will clear after the next scheduled scan |
| 43 | + |
| 44 | +## Why Was the Workflow Failing? |
| 45 | + |
| 46 | +The original `codeql.yml` used CodeQL's **Autobuild** step, which could not build this .NET MAUI project because: |
| 47 | + |
| 48 | +- The .NET SDK was not set up in the workflow |
| 49 | +- MAUI workloads (required for building MAUI projects) were not installed |
| 50 | +- Autobuild does not automatically install platform-specific workloads |
| 51 | + |
| 52 | +The updated workflow in this repository fixes these issues by: |
| 53 | + |
| 54 | +- Adding a `setup-dotnet` step for .NET 9 |
| 55 | +- Installing the `maui-android` workload (compatible with Ubuntu runners) |
| 56 | +- Replacing the Autobuild step with an explicit `dotnet build` targeting `net9.0-android` |
| 57 | + |
| 58 | +## Verifying Code Scanning Compliance |
| 59 | + |
| 60 | +To verify your code scanning setup is working correctly: |
| 61 | + |
| 62 | +1. Go to **Security** > **Code scanning** > **Tool status** |
| 63 | +2. Confirm CodeQL shows a **green status** with recent scan results |
| 64 | +3. Ensure there is only **one active configuration** (either default setup or custom workflow, not both) |
| 65 | +4. Check that scheduled scans are running (the custom workflow runs monthly on the 1st) |
| 66 | + |
| 67 | +## Dependencies for the Custom Workflow |
| 68 | + |
| 69 | +The custom CodeQL workflow requires: |
| 70 | + |
| 71 | +| Dependency | Purpose | |
| 72 | +|---|---| |
| 73 | +| `actions/checkout@v5` | Check out the repository code | |
| 74 | +| `actions/setup-dotnet@v4` | Install .NET 9 SDK | |
| 75 | +| `github/codeql-action/init@v4` | Initialize CodeQL analysis | |
| 76 | +| `github/codeql-action/analyze@v4` | Run CodeQL analysis and upload results | |
| 77 | + |
| 78 | +These are kept up to date by Dependabot (configured in `.github/dependabot.yml`). |
0 commit comments