|
| 1 | +name: Validate Generated Code |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: # Typically, you'd want this on PRs to catch issues before merge |
| 5 | + branches: |
| 6 | + - main # Or your default branch, e.g., 'master' |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main # Also useful on push to ensure main is always clean |
| 10 | + workflow_dispatch: # Allows manual triggering from the GitHub UI |
| 11 | + |
| 12 | +jobs: |
| 13 | + validate_generated_code: |
| 14 | + runs-on: ubuntu-latest # Or your preferred runner environment |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Checkout repository |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Set up Node.js and Yarn |
| 21 | + uses: actions/setup-node@v4 |
| 22 | + with: |
| 23 | + node-version: '20' # Specify your Node.js version |
| 24 | + cache: 'yarn' # Cache Yarn dependencies |
| 25 | + |
| 26 | + - name: Enable Corepack |
| 27 | + run: corepack enable # This command enables Corepack to manage package managers like Yarn 2+ |
| 28 | + |
| 29 | + - name: Install dependencies |
| 30 | + run: yarn install --frozen-lockfile # Use --frozen-lockfile for CI environments |
| 31 | + |
| 32 | + - name: Build code |
| 33 | + run: yarn build |
| 34 | + |
| 35 | + - name: Check for uncommitted generated changes |
| 36 | + run: | |
| 37 | + # Check if there are any uncommitted changes after the build |
| 38 | + if git status --porcelain | grep -q .; then |
| 39 | + echo "Error: Generated code differences detected!" |
| 40 | + echo "Please run 'yarn build' locally and commit the changes." |
| 41 | + git status --porcelain # Show the specific files that are different |
| 42 | + exit 1 # Fail the workflow |
| 43 | + else |
| 44 | + echo "No differences found in generated code. Build is clean." |
| 45 | + fi |
0 commit comments