-
Notifications
You must be signed in to change notification settings - Fork 82
93 lines (78 loc) · 3.21 KB
/
java-autoformat.yml
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
name: Java Code Auto Format
on: pull_request
jobs:
format_dev:
if: |
github.event.pull_request.head.ref == 'dev' &&
github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v1
with:
ref: ${{ github.head_ref }}
- name: Set up JDK 21
uses: actions/setup-java@v1
with:
java-version: 21
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build -x test
- name: Run spotless
run: ./gradlew :spotlessApply
- name: Check for modified files
id: git-check
run: echo "modified=$(if [[ -n $(git status -s) ]]; then echo "true"; else echo "false"; fi)" >> $GITHUB_OUTPUT
- name: Create temporary branch and pull request
if: steps.git-check.outputs.modified == 'true'
run: |
git config --global user.name 'Bram van Heuveln'
git config --global user.email '[email protected]'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
branch_name="auto-format-code-$(date +%s)"
git checkout -b $branch_name
./gradlew :spotlessApply
git add .
git commit -am "Automated Java code formatting changes"
git push --set-upstream origin $branch_name
gh pr create -B dev -H $branch_name --title 'Automated Java code formatting changes' --body 'This pull request contains automated code formatting changes.' --reviewer ${{ github.actor }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Must approve auto-format pull request
if: steps.git-check.outputs.modified == 'true'
run: |
echo "Please review and approve the appropriate auto-format-code pull request."
exit 1
format_pull_request_to_dev:
if: |
github.event.pull_request.base.ref == 'dev' &&
github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v1
with:
ref: ${{ github.head_ref }}
- name: Set up JDK 21
uses: actions/setup-java@v1
with:
java-version: 21
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build -x test
- name: Run spotless
run: ./gradlew :spotlessApply
- name: Check for modified files
id: git-check
run: echo "modified=$(if [[ -n $(git status -s) ]]; then echo "true"; else echo "false"; fi)" >> $GITHUB_OUTPUT
- name: Push changes
if: steps.git-check.outputs.modified == 'true'
run: |
git config --global user.name 'Bram van Heuveln'
git config --global user.email '[email protected]'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git add .
git commit -am "Automated Java code formatting changes"
git push