diff --git a/.github/workflows/codegen-validation.yml b/.github/workflows/codegen-validation.yml new file mode 100644 index 000000000..e499818e7 --- /dev/null +++ b/.github/workflows/codegen-validation.yml @@ -0,0 +1,67 @@ +# This workflow validates changes made to the codegen folder by running code generation +# and ensuring the process completes successfully without errors. +name: CodeGen Validation + +on: + pull_request: + paths: + - 'codegen/**' + - '.github/workflows/codegen-validation.yml' + - 'scripts/Invoke-CodeGen.ps1' + types: [opened, reopened, synchronize] + workflow_dispatch: + +jobs: + validate-codegen: + name: Validate Code Generation + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '22.x' + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + # Use the version specified in global.json + global-json-file: global.json + + - name: Run CodeGen Script + shell: pwsh + run: | + Write-Host "Running code generation validation..." + ./scripts/Invoke-CodeGen.ps1 + + if ($LASTEXITCODE -ne 0) { + Write-Error "Code generation failed with exit code: $LASTEXITCODE" + exit $LASTEXITCODE + } + + Write-Host "Code generation completed successfully!" + + - name: Check for uncommitted changes + run: | + # Check if there are any changes to tracked files after code generation + if ! git diff --quiet; then + echo "::error::Code generation produced uncommitted changes. Please run the codegen script locally and commit the results." + 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::Code generation produced untracked files. Please review and commit them if they should be included." + echo "Untracked files:" + git ls-files --others --exclude-standard + exit 1 + fi + + echo "No uncommitted changes detected - code generation is up to date!" \ No newline at end of file