Skip to content

Commit af5f2fd

Browse files
authored
Enforce code style (#15016)
* style: conform to style rules * fix: add style enforcement * ci: run style checks in dedicated workflow Style/formatting checks are executed only by the new workflow, keeping the main pipelines focused on build/test. * fix: `skipCodeStyle` task condition * ci: add report upload * ci: set correct report directory * chore: trigger code style errors To test if reports are uploaded to the workflow summary page. * ci: specify code style reports more granular * ci: add `--continue` to get all codestyle errors * ci: set correct `skipCodeStyle` condition for `grails-gradle` * ci: stop using Gradle --continue for code style checks Code style tools (Checkstyle/CodeNarc) generate reports even when clean. Fail fast on style violations instead of continuing and producing pages of reports. Developers can still use `--continue` locally when needed. * Revert "chore: trigger code style errors" This reverts commit 12a1270. * style: conform to code style * refactor(build): dry up `code-style-config` * fix(build): align code style checking in `grails-forge` Grails Forge is still using its own Checkstyle rules after this change. * ci: add `grails-forge` code style checking * ci: fix typos * ci: remove redundant gradle param `-Dorg.gradle.internal.publish.checksums.insecure=true` is no longer required as it is set by the publish plugin by default. * docs: add `skipCodeStyle` to `DEVELOPMENT.md` * docs: update `DEVELOPMENT.md` * docs: update `DEVELOPMENT.md` Add info about useful custom Gradle tasks. * docs: update `CONTRIBUTING.md` Update the section on code style.
1 parent 6d70093 commit af5f2fd

File tree

120 files changed

+736
-119
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+736
-119
lines changed

.github/workflows/codestyle.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
name: "Code Style"
17+
on:
18+
push:
19+
branches:
20+
- '[0-9]+.[0-9]+.x'
21+
pull_request:
22+
workflow_dispatch:
23+
# queue jobs and only allow 1 run per branch due to the likelihood of hitting GitHub resource limits
24+
concurrency:
25+
group: ${{ github.workflow }}-${{ github.ref }}
26+
cancel-in-progress: false
27+
jobs:
28+
check_core_projects:
29+
name: "Core Projects"
30+
runs-on: ubuntu-24.04
31+
steps:
32+
- name: "🌐 Output Agent IP" # in the event RAO blocks this agent, this can be used to debug it
33+
run: curl -s https://api.ipify.org
34+
- name: "📥 Checkout repository"
35+
uses: actions/checkout@v4
36+
- name: "☕️ Setup JDK"
37+
uses: actions/setup-java@v4
38+
with:
39+
distribution: liberica
40+
java-version: 17
41+
- name: "🐘 Setup Gradle"
42+
uses: gradle/actions/setup-gradle@v4
43+
with:
44+
develocity-access-key: ${{ secrets.GRAILS_DEVELOCITY_ACCESS_KEY }}
45+
- name: "🔎 Check Core Projects"
46+
run: ./gradlew codeStyle
47+
- name: "📤 Upload Failure Reports"
48+
if: failure()
49+
uses: actions/upload-artifact@v4
50+
with:
51+
name: core-reports
52+
path: |
53+
**/build/reports/checkstyle/
54+
**/build/reports/codenarc/
55+
check_gradle_plugin_projects:
56+
name: "Gradle Plugin Projects"
57+
runs-on: ubuntu-24.04
58+
steps:
59+
- name: "🌐 Output Agent IP" # in the event RAO blocks this agent, this can be used to debug it
60+
run: curl -s https://api.ipify.org
61+
- name: "📥 Checkout repository"
62+
uses: actions/checkout@v4
63+
- name: "☕️ Setup JDK"
64+
uses: actions/setup-java@v4
65+
with:
66+
distribution: liberica
67+
java-version: 17
68+
- name: "🐘 Setup Gradle"
69+
uses: gradle/actions/setup-gradle@v4
70+
with:
71+
develocity-access-key: ${{ secrets.GRAILS_DEVELOCITY_ACCESS_KEY }}
72+
- name: "🔎 Check Gradle Plugin Projects"
73+
working-directory: grails-gradle
74+
run: ./gradlew codeStyle
75+
- name: "📤 Upload Failure Reports"
76+
if: failure()
77+
uses: actions/upload-artifact@v4
78+
with:
79+
name: gradle-plugin-reports
80+
path: |
81+
grails-gradle/**/build/reports/checkstyle/
82+
grails-gradle/**/build/reports/codenarc/
83+
check_grails_forge_projects:
84+
name: "Forge Projects"
85+
runs-on: ubuntu-24.04
86+
steps:
87+
- name: "🌐 Output Agent IP" # in the event RAO blocks this agent, this can be used to debug it
88+
run: curl -s https://api.ipify.org
89+
- name: "📥 Checkout repository"
90+
uses: actions/checkout@v4
91+
- name: "☕️ Setup JDK"
92+
uses: actions/setup-java@v4
93+
with:
94+
distribution: liberica
95+
java-version: 17
96+
- name: "🐘 Setup Gradle"
97+
uses: gradle/actions/setup-gradle@v4
98+
with:
99+
develocity-access-key: ${{ secrets.GRAILS_DEVELOCITY_ACCESS_KEY }}
100+
- name: "🔎 Check Forge Projects"
101+
working-directory: grails-forge
102+
run: ./gradlew codeStyle
103+
- name: "📤 Upload Failure Reports"
104+
if: failure()
105+
uses: actions/upload-artifact@v4
106+
with:
107+
name: forge-reports
108+
path: |
109+
grails-forge/**/build/reports/checkstyle/
110+
grails-forge/**/build/reports/checkstyleNohttp/
111+
grails-forge/**/build/reports/codenarc/

.github/workflows/gradle.yml

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,19 @@ jobs:
5151
working-directory: 'grails-gradle'
5252
run: >
5353
./gradlew build
54-
--continue --stacktrace -PskipTests
54+
--continue
55+
--stacktrace
56+
-PskipCodeStyle
57+
-PskipTests
5558
- name: "🔨 Build project with tests"
5659
if: ${{ !contains(github.event.head_commit.message, '[skip tests]') }}
5760
working-directory: 'grails-gradle'
5861
run: >
5962
./gradlew build
60-
--continue --stacktrace
63+
--continue
64+
--stacktrace
6165
--rerun-tasks
66+
-PskipCodeStyle
6267
build:
6368
if: ${{ !contains(github.event.head_commit.message, '[skip tests]') }}
6469
name: 'Build Grails-Core'
@@ -85,8 +90,11 @@ jobs:
8590
- name: "🔨 Build project"
8691
run: >
8792
./gradlew build :grails-shell-cli:installDist groovydoc
88-
--continue --stacktrace -PonlyCoreTests
93+
--continue
8994
--rerun-tasks
95+
--stacktrace
96+
-PonlyCoreTests
97+
-PskipCodeStyle
9098
buildForge:
9199
name: "Build Grails Forge"
92100
strategy:
@@ -113,14 +121,19 @@ jobs:
113121
working-directory: 'grails-forge'
114122
run: >
115123
./gradlew build
116-
--continue --stacktrace -PskipTests
124+
--continue
125+
--stacktrace
126+
-PskipCodeStyle
127+
-PskipTests
117128
- name: "🔨 Build project with tests"
118129
if: ${{ !contains(github.event.head_commit.message, '[skip tests]') }}
119130
working-directory: 'grails-forge'
120131
run: >
121132
./gradlew build
122-
--continue --stacktrace
133+
--continue
123134
--rerun-tasks
135+
--stacktrace
136+
-PskipCodeStyle
124137
- name: "✅ Verify combined CLI"
125138
run: |
126139
cd grails-forge
@@ -162,11 +175,13 @@ jobs:
162175
- name: "🏃 Run Functional Tests"
163176
run: >
164177
./gradlew bootJar check
165-
--continue --stacktrace
178+
--continue
179+
--rerun-tasks
180+
--stacktrace
166181
-PonlyFunctionalTests
182+
-PskipCodeStyle
167183
-PskipHibernate5Tests
168184
-PskipMongodbTests
169-
--rerun-tasks
170185
mongodbFunctional:
171186
if: ${{ !contains(github.event.head_commit.message, '[skip tests]') }}
172187
name: "Mongodb Functional Tests"
@@ -195,10 +210,12 @@ jobs:
195210
GITHUB_MAVEN_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
196211
run: >
197212
./gradlew bootJar cleanTest check
198-
--continue --stacktrace
213+
--continue
214+
--rerun-tasks
215+
--stacktrace
199216
-PonlyMongodbTests
200217
-PmongodbContainerVersion=${{ matrix.mongodb-version }}
201-
--rerun-tasks
218+
-PskipCodeStyle
202219
hibernate5Functional:
203220
if: ${{ !contains(github.event.head_commit.message, '[skip tests]') }}
204221
name: "Hibernate5 Functional Tests"
@@ -226,9 +243,11 @@ jobs:
226243
GITHUB_MAVEN_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
227244
run: >
228245
./gradlew bootJar cleanTest check
229-
--continue --stacktrace
230-
-PonlyHibernate5Tests
246+
--continue
231247
--rerun-tasks
248+
--stacktrace
249+
-PonlyHibernate5Tests
250+
-PskipCodeStyle
232251
publishGradle:
233252
if: github.repository_owner == 'apache' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
234253
needs: [ buildGradle ]
@@ -256,7 +275,8 @@ jobs:
256275
working-directory: 'grails-gradle'
257276
run: >
258277
./gradlew publish aggregateChecksums aggregatePublishedArtifacts
259-
-Dorg.gradle.internal.publish.checksums.insecure=true --no-build-cache --rerun-tasks
278+
--no-build-cache
279+
--rerun-tasks
260280
- name: "📤 Upload grails-gradle checksums"
261281
uses: actions/upload-artifact@v4
262282
with:
@@ -360,7 +380,8 @@ jobs:
360380
working-directory: 'grails-forge'
361381
run: >
362382
./gradlew publish aggregateChecksums aggregatePublishedArtifacts
363-
-Dorg.gradle.internal.publish.checksums.insecure=true --no-build-cache --rerun-tasks
383+
--no-build-cache
384+
--rerun-tasks
364385
- name: "📤 Upload grails-forge checksums"
365386
uses: actions/upload-artifact@v4
366387
with:

.github/workflows/groovy-joint-workflow.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,4 @@ jobs:
161161
run: >
162162
./gradlew build
163163
-x groovydoc
164+
-PskipCodeStyle

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ changes.
239239

240240
## Code Style
241241

242-
Grails code style mostly mirrors the Spring Framework's [Style Guide](https://github.com/spring-projects/spring-framework/blob/main/CONTRIBUTING.md#source-code-style). We are currently working on a more detailed proposal under ticket [#13754](https://github.com/apache/grails-core/issues/13754).
242+
Grails has a limited set of code styles enforced by Checkstyle (for Java) and CodeNarc (for Groovy).
243+
To check compliance with the code styles, run the `codeStyle` Gradle task.
243244

244245
### Commit Messages
245246

DEVELOPMENT.md

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,34 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
-->
1616

17-
# Various properties that control which & how tests run
18-
* onlyFunctionalTests - runs only grails-test-examples/* tests
19-
* onlyHibernate5Tests - runs only a hibernate5 related test
20-
* onlyMongodbTests - runs only a mongodb related test
21-
* onlyCoreTests - runs tests that do not include mongo, hibernate, or functional
22-
* skipFunctionalTests - does not run the functional tests
23-
* skipHibernate5Tests - does not run hibernate5 related tests
24-
* skipMongodbTests - does not run mongo related tests
25-
* skipCoreTests - does not run the "core" tests
26-
* serializeMongoTests - if true, only integration tests from one mongo project will run at a time
27-
* skipTests - no tests will run
28-
29-
# Start a mongo docker container (containers will start by default)
17+
# Development
18+
19+
## Useful Custom Gradle tasks
20+
21+
These tasks can be run like so:
22+
23+
`./gradlew publishGuide`
24+
25+
* `codeStyle` - runs all code style checks
26+
* `publishGuide` - generates the user guide in the `grails-doc/build/original-guide`
27+
28+
## Various properties that control which tasks to run
29+
30+
These can be set on the command line like so:
31+
32+
`./gradlew check -PskipCodeStyle`
33+
34+
* `onlyCoreTests` - runs tests that do not include mongo, hibernate, or functional
35+
* `onlyFunctionalTests` - runs only grails-test-examples/* tests
36+
* `onlyHibernate5Tests` - runs only a hibernate5 related test
37+
* `onlyMongodbTests` - runs only a mongodb related test
38+
* `serializeMongoTests` - if true, only integration tests from one mongo project will run at a time
39+
* `skipCodeStyle` - does not run code style checks
40+
* `skipCoreTests` - does not run the "core" tests
41+
* `skipFunctionalTests` - does not run the functional tests
42+
* `skipHibernate5Tests` - does not run hibernate5 related tests
43+
* `skipMongodbTests` - does not run mongo related tests
44+
* `skipTests` - no tests will run
45+
46+
## Start a mongo docker container (containers will start by default)
3047
`docker run -d --name mongo-on-docker -p 27017:27017 mongo`
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<!DOCTYPE suppressions PUBLIC "-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN" "https://checkstyle.org/dtds/suppressions_1_2.dtd">
21+
<suppressions>
22+
</suppressions>

0 commit comments

Comments
 (0)