-
-
Notifications
You must be signed in to change notification settings - Fork 69
97 lines (82 loc) · 2.7 KB
/
pr-format.yaml
File metadata and controls
97 lines (82 loc) · 2.7 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
96
97
name: Format PR Code
on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
push:
branches:
- master
paths:
- "**/*.java"
jobs:
format:
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout branch
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref_name }}
fetch-depth: 0
- name: Set up Java 21
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "21"
cache: gradle
- name: Expose Java 21 to Gradle toolchains
run: |
echo "JAVA_HOME=$JAVA_HOME" >> "$GITHUB_ENV"
echo "ORG_GRADLE_JAVA_INSTALLATIONS_PATHS=$JAVA_HOME" >> "$GITHUB_ENV"
java -version
javac -version
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4
- name: Format Java sources
run: ./gradlew formatJava
- name: Commit formatted changes
run: |
if git diff --quiet; then
echo "No formatting changes detected"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "Apply Palantir Java Format"
git push
check-format:
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout branch
uses: actions/checkout@v4
- name: Set up Java 21
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "21"
cache: gradle
- name: Expose Java 21 to Gradle toolchains
run: |
echo "JAVA_HOME=$JAVA_HOME" >> "$GITHUB_ENV"
echo "ORG_GRADLE_JAVA_INSTALLATIONS_PATHS=$JAVA_HOME" >> "$GITHUB_ENV"
java -version
javac -version
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4
- name: Check Java formatting
run: ./gradlew checkFormatJava
- name: Explain how to fix formatting
if: failure()
run: |
echo "Java formatting check failed."
echo "This pull request comes from a fork, so CI cannot push formatting commits back to the branch."
echo "Run './gradlew formatJava' locally and push the formatted changes to update the PR."