refactor: simplify pre-commit workflow and update welcome message #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Lint with Pre-commit | |
| on: | |
| push: | |
| branches: [master, main, develop] | |
| pull_request: | |
| branches: [master, main, develop] | |
| jobs: | |
| pre-commit-checks: | |
| name: Pre-commit Checks (JDK ${{ matrix.java-version }}) | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| pull-requests: write | |
| checks: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up JDK | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: temurin | |
| java-version: 25 | |
| cache: gradle | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v5 | |
| with: | |
| build-scan-publish: true | |
| build-scan-terms-of-use-url: "https://gradle.com/help/legal-terms-of-use" | |
| build-scan-terms-of-use-agree: "yes" | |
| cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/master' }} | |
| - name: Cache pre-commit environments | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cache/pre-commit | |
| ~/.local/share/pre-commit | |
| key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}-${{ runner.os }} | |
| restore-keys: | | |
| pre-commit-${{ runner.os }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.13' | |
| - name: Install pre-commit | |
| run: pip install pre-commit | |
| - name: Make gradlew executable | |
| run: chmod +x ./gradlew | |
| - name: Run pre-commit hooks | |
| id: precommit | |
| continue-on-error: false | |
| run: | | |
| set -e # Exit immediately on error | |
| echo "Running pre-commit checks..." | |
| pre-commit run --all-files --show-diff-on-failure --color=always --verbose | |
| - name: Comment on PR with results | |
| if: github.event_name == 'pull_request' && always() | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const result = '${{ steps.precommit.outcome }}'; | |
| if (result === 'failure') { | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: `❌ Pre-commit checks failed for JDK 25. Please check the workflow run for details.` | |
| }); | |
| } else if (result === 'success') { | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: `✅ Pre-commit checks passed!` | |
| }); | |
| } |