Skip to content

test: add ValidateOrThrow characterization tests, fix corrupted test #890

test: add ValidateOrThrow characterization tests, fix corrupted test

test: add ValidateOrThrow characterization tests, fix corrupted test #890

Workflow file for this run

# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL Advanced"
on:
push:
branches: ["master"]
pull_request:
branches: ["master"]
schedule:
- cron: "32 7 * * 3"
jobs:
check_changes:
runs-on: ubuntu-latest
# Skip this check for scheduled runs - always run analysis on schedule
if: github.event_name != 'schedule'
outputs:
should_skip: ${{ steps.check.outputs.should_skip }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0 # Fetch all history to properly check changes
- name: Check if only documentation files changed
id: check
run: |
# Define files to skip CodeQL analysis for (documentation and non-deployed files)
# Add new files to this list as needed (one per line)
DOC_FILES=(
# Documentation files
"README.md"
"AGENTS.md"
"CHANGELOG.md"
"docs/**/*.md"
"tasks/**/*.md"
"spec/**/*"
".github/guides/**/*.md"
".github/prompts/**/*.md"
".github/chatmodes/**/*.md"
".opencode/**/*"
# Test projects (source files are committed but don't affect security analysis)
"tests/**/*"
# Build and development tools (committed but don't need security analysis)
"scripts/**/*"
".editorconfig"
".mcp.json"
".coverletrc"
# IDE and editor configuration
".vscode/**/*"
"*.code-workspace"
"*.sln.DotSettings"
".config/**/*"
".filenesting.json"
".trae/**/*"
# Development configuration
"swa-cli.config.json"
"Start.ps1"
"test.ps1"
"config/**/*"
".changelog-state"
"src/**/Properties/launchSettings.json"
"src/**/appsettings.Development.json"
"src/**/*.local.settings.json*"
# Git configuration
".gitattributes"
".gitignore"
# Add more non-code files here as needed
)
# Build regex pattern from file list
PATTERN=""
for file in "${DOC_FILES[@]}"; do
if [[ -n "$PATTERN" ]]; then
PATTERN="$PATTERN|"
fi
# Escape dots in filenames for regex
ESCAPED_FILE=$(echo "$file" | sed 's/\./\\./g')
PATTERN="${PATTERN}${ESCAPED_FILE}"
done
echo "Using file pattern: $PATTERN"
# For PRs, compare with the base branch
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "Checking PR changes..."
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }})
# For pushes, compare with previous commit
else
echo "Checking push changes..."
# Handle force pushes - if the previous commit doesn't exist, use HEAD~1
if git cat-file -e ${{ github.event.before }} 2>/dev/null; then
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }})
else
echo "Previous commit not found (force push detected) - comparing with HEAD~1"
CHANGED_FILES=$(git diff --name-only HEAD~1 ${{ github.sha }})
fi
fi
# If empty diff (first commit or error), don't skip
if [[ -z "$CHANGED_FILES" ]]; then
echo "Empty diff detected - not skipping analysis"
echo "should_skip=false" >> $GITHUB_OUTPUT
exit 0
fi
# Count all changed files
TOTAL_CHANGED=$(echo "$CHANGED_FILES" | wc -l)
# Count how many of our docs files changed
DOC_FILES_CHANGED=$(echo "$CHANGED_FILES" | grep -E "$PATTERN" | wc -l)
echo "Total files changed: $TOTAL_CHANGED"
echo "Doc files changed: $DOC_FILES_CHANGED"
# If only doc files changed and they exist in the changed files list, skip analysis
if [[ $DOC_FILES_CHANGED -gt 0 && $DOC_FILES_CHANGED -eq $TOTAL_CHANGED ]]; then
echo "Only documentation and non-code files changed, skipping CodeQL analysis"
echo "should_skip=true" >> $GITHUB_OUTPUT
else
echo "Code files changed, proceeding with CodeQL analysis"
echo "should_skip=false" >> $GITHUB_OUTPUT
fi
docs_only_changed_job:
needs: check_changes
if: |
needs.check_changes.outputs.should_skip == 'true' &&
github.event_name != 'schedule'
runs-on: ubuntu-latest
name: Documentation Only Changed
steps:
- name: Skip CodeQL Analysis
run: |
echo "📝 Only documentation and non-code files changed."
echo "⏭️ Skipping CodeQL security analysis as no code changes were detected."
echo ""
echo "💡 WHAT THIS MEANS FOR YOU:"
echo " • Security analysis is skipped to save time and resources"
echo " • Documentation changes don't introduce security vulnerabilities"
echo " • Your codebase security posture remains unchanged"
echo " • Scheduled CodeQL analysis will still run weekly on Wednesdays"
analyze:
needs: [check_changes]
# Run if docs didn't change OR if this is a scheduled run
if: |
github.event_name == 'schedule' ||
needs.check_changes.outputs.should_skip != 'true'
name: Analyze (${{ matrix.language }})
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners (GitHub.com only)
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
permissions:
# required for all workflows
security-events: write
# required to fetch internal or private CodeQL packs
packages: read
# only required for workflows in private repositories
actions: read
contents: read
strategy:
fail-fast: false
matrix:
include:
- language: actions
build-mode: none
- language: csharp
build-mode: none
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
# Use `c-cpp` to analyze code written in C, C++ or both
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning.customizing-your-advanced-setup-for-code-scanning.
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
# 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
steps:
- name: Log analysis decision
run: |
if [[ "${{ github.event_name }}" == "schedule" ]]; then
echo "Running CodeQL analysis on schedule."
else
echo "Running CodeQL analysis as code files were changed."
fi
- name: Checkout repository
uses: actions/checkout@v6
# Add any setup steps before running the `github/codeql-action/init` action.
# This includes steps like installing compilers or runtimes (`actions/setup-node`
# or others). This is typically only required for manual builds.
# - name: Setup runtime (example)
# uses: actions/setup-example@v1
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# 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
# queries: security-extended,security-and-quality
# If the analyze step fails for one of the languages you are analyzing with
# "We were unable to automatically build your code", modify the matrix above
# to set the build mode to "manual" for that language. Then modify this step
# to build your code.
# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
- if: matrix.build-mode == 'manual'
shell: bash
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
exit 1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
with:
category: "/language:${{matrix.language}}"