-
-
Notifications
You must be signed in to change notification settings - Fork 0
95 lines (82 loc) · 2.89 KB
/
pre-commit.yml
File metadata and controls
95 lines (82 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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
strategy:
matrix:
java-version: [21, 25]
fail-fast: false
permissions:
contents: read
pull-requests: write
checks: write
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v5
with:
distribution: temurin
java-version: ${{ matrix.java-version }}
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'
cache: 'pip'
- 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 ${{ matrix.java-version }}. 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 for JDK ${{ matrix.java-version }}!`
});
}