Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/actions/check-uncommitted-changes/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Check for uncommitted changes
description: Checks if there are any uncommitted changes in the repository

inputs:
error-message:
description: 'Error message to display if uncommitted changes are found'
required: true

runs:
using: composite
steps:
- name: Check for uncommitted changes
shell: bash
run: |
ERROR_MSG="${{ inputs.error-message }}"

# Check if there are any changes to tracked files
if ! git diff --quiet; then
echo "::error::$ERROR_MSG"
echo "Changed files:"
git diff --name-only
echo "Diff details:"
git diff
exit 1
fi

# Also check for untracked files that might have been generated
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
echo "::error::$ERROR_MSG"
echo "Untracked files:"
git ls-files --others --exclude-standard
exit 1
fi

echo "No uncommitted changes detected!"
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ on:
- 'package.json'
- 'global.json'
- 'package-lock.json'
- '.github/workflows/codegen-validation.yml'
- '.github/workflows/integrity-checks.yml'
- 'scripts/Invoke-CodeGen.ps1'
- 'scripts/Export-Api.ps1'
- 'api/**'
- 'Directory.Build.targets'
- 'tests/Snippets/**'
- 'README.md'
- 'scripts/Update-Snippets.ps1'
types: [opened, reopened, synchronize]
workflow_dispatch:

Expand Down Expand Up @@ -53,28 +56,9 @@ jobs:
Write-Host "Code generation completed successfully!"

- name: Check for uncommitted changes
run: |
CODEGEN_ERROR_MSG="Code generation produced changes. Please run './scripts/Invoke-CodeGen.ps1' locally and commit the results."

# Check if there are any changes to tracked files after code generation
if ! git diff --quiet; then
echo "::error::$CODEGEN_ERROR_MSG"
echo "Changed files:"
git diff --name-only
echo "Diff details:"
git diff
exit 1
fi

# Also check for untracked files that might have been generated
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
echo "::error::$CODEGEN_ERROR_MSG"
echo "Untracked files:"
git ls-files --others --exclude-standard
exit 1
fi

echo "No uncommitted changes detected - code generation is up to date!"
uses: ./.github/actions/check-uncommitted-changes
with:
error-message: "Code generation produced changes. Please run './scripts/Invoke-CodeGen.ps1' locally and commit the results."

- name: Run codegen visitor tests
run: dotnet test codegen/generator/test/
Expand Down Expand Up @@ -118,25 +102,38 @@ jobs:
Write-Host "API export completed successfully!"

- name: Check for uncommitted changes
uses: ./.github/actions/check-uncommitted-changes
with:
error-message: "API export produced changes. Please run './scripts/Export-Api.ps1' locally and commit the results."

validate-snippets:
name: Validate documentation snippets
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v6

- name: Set up .NET
uses: actions/setup-dotnet@v5
with:
# Use the version specified in global.json
global-json-file: global.json

- name: Run Update-Snippets script
shell: pwsh
run: |
API_ERROR_MSG="API export produced changes. Please run './scripts/Export-Api.ps1' locally and commit the results."

# Check if there are any changes to tracked files after API export
if ! git diff --quiet; then
echo "::error::$API_ERROR_MSG"
echo "Changed files:"
git diff --name-only
echo "Diff details:"
git diff
exit 1
fi

# Also check for untracked files that might have been generated
if [ -n "$(git ls-files --others --exclude-standard)" ]; then
echo "::error::$API_ERROR_MSG"
echo "Untracked files:"
git ls-files --others --exclude-standard
exit 1
fi

echo "No uncommitted changes detected - API export is up to date!"
Write-Host "Running snippet update validation..."
./scripts/Update-Snippets.ps1

if ($LASTEXITCODE -ne 0) {
Write-Error "Snippet update failed with exit code: $LASTEXITCODE"
exit $LASTEXITCODE
}

Write-Host "Snippet update completed successfully!"

- name: Check for uncommitted changes
uses: ./.github/actions/check-uncommitted-changes
with:
error-message: "Documentation snippets are out of date. Please run './scripts/Update-Snippets.ps1' locally and commit the results."