Skip to content

Commit 1d4e584

Browse files
committed
ci: stabilize CI and remove red-X noise (formatting gate, STJ pin via CPM, solution-scoped restore/list, unique artifact name, Dependabot skip, permissions + CodeQL setup)
1 parent f0570d8 commit 1d4e584

28 files changed

+269
-269
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
name: CI
22

3+
permissions:
4+
contents: read
5+
security-events: write
6+
actions: read
7+
38
on:
49
push:
5-
branches:
6-
- main
7-
- master
10+
branches: [ main, master ]
811
pull_request:
9-
branches:
10-
- "*"
12+
branches: [ "*" ]
1113

1214
jobs:
1315
build:
16+
if: github.actor != 'dependabot[bot]'
1417
runs-on: ${{ matrix.os }}
1518
strategy:
1619
matrix:
@@ -22,7 +25,7 @@ jobs:
2225
with:
2326
dotnet-version: '8.0.x'
2427
- name: Restore dependencies
25-
run: dotnet restore
28+
run: dotnet restore KeelMatrix.QueryWatch.sln
2629
- name: Build
2730
run: dotnet build --configuration Release --no-restore
2831
- name: Test
@@ -42,10 +45,12 @@ jobs:
4245
with:
4346
name: nuget-packages
4447
path: ./artifacts/packages
48+
if-no-files-found: error
49+
overwrite: true
4550
- name: Verify formatting
4651
run: dotnet format --verify-no-changes
4752
- name: Check for vulnerable dependencies
48-
run: dotnet list package --vulnerable
53+
run: dotnet list KeelMatrix.QueryWatch.sln package --vulnerable
4954
- name: Initialize CodeQL
5055
uses: github/codeql-action/init@v3
5156
with:

.github/workflows/codeql.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL Advanced"
13+
14+
on:
15+
push:
16+
branches: [ "main" ]
17+
pull_request:
18+
branches: [ "main" ]
19+
schedule:
20+
- cron: '24 15 * * 6'
21+
22+
jobs:
23+
analyze:
24+
name: Analyze (${{ matrix.language }})
25+
# Runner size impacts CodeQL analysis time. To learn more, please see:
26+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
27+
# - https://gh.io/supported-runners-and-hardware-resources
28+
# - https://gh.io/using-larger-runners (GitHub.com only)
29+
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
30+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
31+
32+
# Ensure the SARIF upload can succeed.
33+
permissions:
34+
# required for all workflows
35+
security-events: write
36+
37+
# required to fetch internal or private CodeQL packs
38+
packages: read
39+
40+
# typical for public repos (safe to keep)
41+
actions: read
42+
contents: read
43+
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
include:
48+
# Scan GitHub Actions workflows (YAML) for common issues.
49+
- language: actions
50+
build-mode: none
51+
52+
# Primary language of this repo (KeelMatrix.QueryWatch)
53+
- language: csharp
54+
# Let CodeQL discover and build your solution automatically.
55+
build-mode: autobuild
56+
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', 'swift'
57+
# Use `c-cpp` to analyze code written in C, C++ or both
58+
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
59+
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
60+
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
61+
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
62+
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
63+
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
64+
65+
steps:
66+
- name: Checkout repository
67+
uses: actions/checkout@v4
68+
69+
# Add any setup steps before running the `github/codeql-action/init` action.
70+
# This includes steps like installing compilers or runtimes (`actions/setup-node`
71+
# or others). This is typically only required for manual builds.
72+
# - name: Setup runtime (example)
73+
# uses: actions/setup-example@v1
74+
75+
# Ensure .NET 8 SDK is present for autobuild of the C# solution.
76+
- name: Set up .NET 8
77+
if: matrix.language == 'csharp'
78+
uses: actions/setup-dotnet@v4
79+
with:
80+
dotnet-version: '8.0.x'
81+
82+
# Initializes the CodeQL tools for scanning.
83+
- name: Initialize CodeQL
84+
uses: github/codeql-action/init@v3
85+
with:
86+
languages: ${{ matrix.language }}
87+
build-mode: ${{ matrix.build-mode }}
88+
# If you wish to specify custom queries, you can do so here or in a config file.
89+
# By default, queries listed here will override any specified in a config file.
90+
# Prefix the list here with "+" to use these queries and those in the config file.
91+
#
92+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
93+
queries: +security-extended,security-and-quality
94+
95+
# If the analyze step fails for one of the languages you are analyzing with
96+
# "We were unable to automatically build your code", modify the matrix above
97+
# to set the build mode to "manual" for that language. Then modify this step
98+
# to build your code.
99+
# ℹ️ Command-line programs to run using the OS shell.
100+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
101+
- if: matrix.build-mode == 'manual'
102+
shell: bash
103+
run: |
104+
echo 'If you are using a "manual" build mode for one or more of the' \
105+
'languages you are analyzing, replace this with the commands to build' \
106+
'your code, for example:'
107+
echo ' dotnet restore KeelMatrix.QueryWatch.sln'
108+
echo ' dotnet build KeelMatrix.QueryWatch.sln -c Release --no-restore'
109+
exit 1
110+
111+
- name: Perform CodeQL Analysis
112+
uses: github/codeql-action/analyze@v3
113+
with:
114+
category: "/language:${{ matrix.language }}"

Directory.Build.props

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@
1414
<!-- Generate XML documentation for all projects by default -->
1515
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1616
</PropertyGroup>
17+
18+
<!-- Optional: suppress CS1591 for Release builds of packable projects -->
19+
<PropertyGroup Condition="'$(IsPackable)'=='true' and '$(Configuration)'=='Release'">
20+
<NoWarn>$(NoWarn);CS1591</NoWarn>
21+
</PropertyGroup>
1722
</Project>

Directory.Packages.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@
1616
<!-- JSON serializer used by QueryWatch.Reporting -->
1717
<!-- Pin a patched System.Text.Json so NuGet never resolves 8.0.0 -->
1818
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
19+
20+
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
21+
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.8" />
1922
</ItemGroup>
2023
</Project>

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2025 Your Name
3+
Copyright (c) 2025 KeelMatrix
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
> The project is currently under development. Keep an eye out for its release!
2+
13
# KeelMatrix.QueryWatch
24

35
> Catch N+1 queries and slow SQL in tests. Fail builds when query budgets are exceeded.

src/KeelMatrix.QueryWatch/Ado/QueryWatchCommand.cs

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,40 @@
44
using System.Diagnostics;
55
using System.Diagnostics.CodeAnalysis;
66

7-
namespace KeelMatrix.QueryWatch.Ado
8-
{
7+
namespace KeelMatrix.QueryWatch.Ado {
98
/// <summary>
109
/// Delegating <see cref="DbCommand"/> that measures execution and records into a session.
1110
/// </summary>
12-
public sealed class QueryWatchCommand : DbCommand
13-
{
11+
public sealed class QueryWatchCommand : DbCommand {
1412
private readonly DbCommand _inner;
1513
private readonly QueryWatchSession _session;
1614
private readonly DbConnection? _connection; // wrapper connection
1715

18-
public QueryWatchCommand(DbCommand inner, QueryWatchSession session, DbConnection? wrapperConnection = null)
19-
{
16+
public QueryWatchCommand(DbCommand inner, QueryWatchSession session, DbConnection? wrapperConnection = null) {
2017
_inner = inner ?? throw new ArgumentNullException(nameof(inner));
2118
_session = session ?? throw new ArgumentNullException(nameof(session));
2219
_connection = wrapperConnection;
2320
}
2421

2522
[AllowNull]
26-
public override string CommandText
27-
{
23+
public override string CommandText {
2824
get => _inner.CommandText;
2925
set => _inner.CommandText = value;
3026
}
3127

32-
public override int CommandTimeout
33-
{
28+
public override int CommandTimeout {
3429
get => _inner.CommandTimeout;
3530
set => _inner.CommandTimeout = value;
3631
}
3732

38-
public override CommandType CommandType
39-
{
33+
public override CommandType CommandType {
4034
get => _inner.CommandType;
4135
set => _inner.CommandType = value;
4236
}
4337

44-
protected override DbConnection? DbConnection
45-
{
38+
protected override DbConnection? DbConnection {
4639
get => _connection ?? _inner.Connection;
47-
set
48-
{
40+
set {
4941
if (value is null) {
5042
_inner.Connection = null;
5143
}
@@ -60,20 +52,17 @@ protected override DbConnection? DbConnection
6052

6153
protected override DbParameterCollection DbParameterCollection => _inner.Parameters;
6254

63-
protected override DbTransaction? DbTransaction
64-
{
55+
protected override DbTransaction? DbTransaction {
6556
get => _inner.Transaction;
6657
set => _inner.Transaction = value;
6758
}
6859

69-
public override bool DesignTimeVisible
70-
{
60+
public override bool DesignTimeVisible {
7161
get => _inner.DesignTimeVisible;
7262
set => _inner.DesignTimeVisible = value;
7363
}
7464

75-
public override UpdateRowSource UpdatedRowSource
76-
{
65+
public override UpdateRowSource UpdatedRowSource {
7766
get => _inner.UpdatedRowSource;
7867
set => _inner.UpdatedRowSource = value;
7968
}
@@ -85,50 +74,43 @@ public override UpdateRowSource UpdatedRowSource
8574

8675
private void Record(TimeSpan elapsed) => _session.Record(_inner.CommandText ?? string.Empty, elapsed);
8776

88-
public override int ExecuteNonQuery()
89-
{
77+
public override int ExecuteNonQuery() {
9078
var sw = Stopwatch.StartNew();
9179
try { return _inner.ExecuteNonQuery(); }
9280
finally { sw.Stop(); Record(sw.Elapsed); }
9381
}
9482

95-
public override object? ExecuteScalar()
96-
{
83+
public override object? ExecuteScalar() {
9784
var sw = Stopwatch.StartNew();
9885
try { return _inner.ExecuteScalar(); }
9986
finally { sw.Stop(); Record(sw.Elapsed); }
10087
}
10188

102-
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
103-
{
89+
protected override DbDataReader ExecuteDbDataReader(CommandBehavior behavior) {
10490
var sw = Stopwatch.StartNew();
10591
try { return _inner.ExecuteReader(behavior); }
10692
finally { sw.Stop(); Record(sw.Elapsed); }
10793
}
10894

109-
public override async Task<int> ExecuteNonQueryAsync(CancellationToken cancellationToken)
110-
{
95+
public override async Task<int> ExecuteNonQueryAsync(CancellationToken cancellationToken) {
11196
var sw = Stopwatch.StartNew();
11297
try { return await _inner.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false); }
11398
finally { sw.Stop(); Record(sw.Elapsed); }
11499
}
115100

116-
public override async Task<object?> ExecuteScalarAsync(CancellationToken cancellationToken)
117-
{
101+
public override async Task<object?> ExecuteScalarAsync(CancellationToken cancellationToken) {
118102
var sw = Stopwatch.StartNew();
119103
try { return await _inner.ExecuteScalarAsync(cancellationToken).ConfigureAwait(false); }
120104
finally { sw.Stop(); Record(sw.Elapsed); }
121105
}
122106

123-
protected override async Task<DbDataReader> ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
124-
{
107+
protected override async Task<DbDataReader> ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken) {
125108
var sw = Stopwatch.StartNew();
126109
try { return await _inner.ExecuteReaderAsync(behavior, cancellationToken).ConfigureAwait(false); }
127110
finally { sw.Stop(); Record(sw.Elapsed); }
128111
}
129112

130-
protected override void Dispose(bool disposing)
131-
{
113+
protected override void Dispose(bool disposing) {
132114
if (disposing) _inner.Dispose();
133115
base.Dispose(disposing);
134116
}

0 commit comments

Comments
 (0)