Skip to content

Commit

Permalink
chore(build): Modernise and clean up build (#504)
Browse files Browse the repository at this point in the history
* chore(build): Modernise and clean up build

- Implement buildSrc to isolate build related code and deps
- Rename gradle plugin project dir to gradle-plugin
- Add gradle dir for version catalogs
- Implement version catalogs to handle versions
- Remove redundant gradle files from subprojects
- Move grailsCentralPublishing.gradle to gradle dir
- Use project.layout to reference files and dirs
- Make build more type-safe with IDE code completion
- Unify quote usage
- Clean up dependencies and tighten their scopes
- Use lazy configuration where possible
- Remove unused ext properties
- Create workarounds for grails-gradle-plugin exposing groovy
- Remove used resources and attribute to asciidoctor task
- Fix classpath issues with groovydoc task
- Change 'docs' task as there is nothing to copy
- Change jar manifest to reflect projects properties
- Remove redundant Application.groovy from views-markup
- Update example projects
- Add missing CompileStatic and make compatible with Groovy 3.0.21-SNAPSHOT

* fix(build): Move Snapshot repos to the right place

The snapshot repositories had accidentally been placed outside
the configuration of the PublishingExtension.

* build(chore): Clean up secret passing from GH action

By using the ORG_GRADLE_PROJECT_** env vars build files can
be cleaned up from checking at multiple places for the values.

* ci: Replace Java 14 with Java 17 in build matrix

* build: Declare grailsVersion in one place

With this change the Grails version is only declared once.

* build: Update Groovy Joint workflow

The groovy version was not resolved correctly previously. With this change it gets set as three different environment vars. CI_GROOVY_VERSION and GROOVY_VERSION as regular environment vars and with ORG_GRADLE_PROJECT_groovyVersion that sets the groovyVersion project property. This allows for some choices in how to handle this in the build script.

This change also adds a section to the settings.gradle file to allow for overriding the groovy version in the version catalog with the GROOVY_VERSION env variable.

* build: Create configuration for Groovydoc

The Groovydoc Gradle task need to be run with the same groovy
version as Gradle.

* build: Change workflow JDK to temurin

AdoptOpenJDK got moved to Eclipe Temurin and won't
be updated anymore.

* build: Cleanup handling of sonatype credentials

With this change there is no need to check both environment
variables and project properties.
Also move the sonatype repo info to a project property.

* chore(deps): Update grails-gradle-plugin to 6.1.2

* chore(deps): Update grails to 6.1.2

* build: Make groovy workflow version independent

With this change the workflow will use the versions of groovy
and gradle enterprise that are defined in the build rather
than hard-coding them in the actions file.

* build: Minor cleanups

* ci: Remove publishing of test reports

These can now be viewed in build scans.

* build: Remove unused import

* ci: Remove java version matrix for release

No need to run this on multiple versions

* build: Change author and git email

Puneet has a new email
  • Loading branch information
matrei committed Feb 21, 2024
1 parent e8908aa commit 05ddf14
Show file tree
Hide file tree
Showing 151 changed files with 992 additions and 3,184 deletions.
58 changes: 34 additions & 24 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,76 +9,86 @@ on:
- master
- '[2-9]+.[0-9]+.x'
jobs:

build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
java: ['11', '14']
java: [11, 17]

env:
WORKSPACE: ${{ github.workspace }}
GRADLE_OPTS: -Xmx1500m -Dfile.encoding=UTF-8

steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
- uses: gradle/wrapper-validation-action@v2
- uses: actions/setup-java@v4
with:
distribution: 'adopt'
distribution: temurin
java-version: ${{ matrix.java }}

- name: Run Tests
if: github.event_name == 'pull_request'
id: tests
uses: gradle/gradle-build-action@v2
with:
arguments: check -Dgeb.env=chromeHeadless
uses: gradle/actions/setup-gradle@v3
env:
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }}
GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }}
GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }}
with:
arguments: |
check
-Dgeb.env=chromeHeadless
- name: Run Build
if: github.event_name == 'push'
id: build
uses: gradle/gradle-build-action@v2
uses: gradle/actions/setup-gradle@v3
env:
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }}
GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }}
with:
arguments: build -Dgeb.env=chromeHeadless
- name: Publish Test Report
if: steps.build.outcome == 'failure' || steps.tests.outcome == 'failure'
uses: scacap/action-surefire-report@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
report_paths: '**/build/test-results/test/TEST-*.xml'
- name: Publish to repo.grails.org
arguments: |
build
-Dgeb.env=chromeHeadless
- name: Publish Snapshot to repo.grails.org
id: publish
uses: gradle/gradle-build-action@v2
uses: gradle/actions/setup-gradle@v3
if: steps.build.outcome == 'success' && github.event_name == 'push' && matrix.java == '11'
env:
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
ORG_GRADLE_PROJECT_artifactoryUsername: ${{ secrets.ARTIFACTORY_USERNAME }}
ORG_GRADLE_PROJECT_artifactoryPassword: ${{ secrets.ARTIFACTORY_PASSWORD }}
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }}
GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }}
with:
arguments: -Dorg.gradle.internal.publish.checksums.insecure=true publish
arguments: |
-Dorg.gradle.internal.publish.checksums.insecure=true
publish
- name: Build Docs
id: docs
if: steps.build.outcome == 'success' && github.event_name == 'push' && matrix.java == '11'
uses: gradle/gradle-build-action@v2
uses: gradle/actions/setup-gradle@v3
env:
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }}
GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }}
with:
arguments: views-docs:docs
- name: Publish to Github Pages

- name: Publish Snapshot docs to Github Pages
if: steps.docs.outcome == 'success' && github.event_name == 'push' && matrix.java == '11'
uses: micronaut-projects/github-pages-deploy-action@grails
env:
TARGET_REPOSITORY: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
BRANCH: gh-pages
FOLDER: docs/build/docs
COMMIT_EMAIL: behlp@objectcomputing.com
COMMIT_EMAIL: behlp@unityfoundation.io
COMMIT_NAME: Puneet Behl
172 changes: 96 additions & 76 deletions .github/workflows/groovy-joint-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,107 +1,124 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: "Grails Joint Validation Build"
# GROOVY_2_5_X == Grails 4.0.x
# GROOVY_3_0_X == grails master
# Groovy master branch does not map to any due to changed package names.
name: "Groovy Joint Validation Build"
on:
push:
branches:
- '[3-9]+.[1-9]+.x'
- '[3-9]+.[0-9]+.x'
pull_request:
branches:
- '[3-9]+.[1-9]+.x'
- '[3-9]+.[0-9]+.x'
workflow_dispatch:
permissions:
contents: read
env:
CI_GROOVY_VERSION:
jobs:
build_groovy:
strategy:
fail-fast: true
runs-on: ubuntu-latest
outputs:
groovyVersion: ${{ steps.groovy-version.outputs.value }}
groovySnapshotVersion: ${{ steps.groovy_snapshot_version.outputs.value }}
steps:

- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: '11.0.6'
distribution: temurin
java-version: 11

- name: Cache local Maven repository & Groovy
uses: actions/cache@v4
with:
path: |
~/groovy
~/.m2/repository
key: cache-local-groovy-maven-${{ github.sha }}
- name: Checkout Groovy 3_0_X (Grails 5 and later)
if: startsWith(github.ref, 'refs/heads/3.') || startsWith(github.base_ref, '3.')
run: cd .. && git clone --depth 1 https://github.com/apache/groovy.git -b GROOVY_3_0_X --single-branch
- name: Set CI_GROOVY_VERSION for Grails
id: groovy-version

- name: Checkout project to fetch some versions it uses
uses: actions/checkout@v4
with:
sparse-checkout-cone-mode: false
sparse-checkout: |
settings.gradle
gradle/libs.versions.toml
- name: Get version of Gradle Enterprise plugin
id: gradle_enterprise_version
run: |
GE_PLUGIN_VERSION=$(grep -m 1 'id\s*\(\"com.gradle.enterprise\"\|'"'com.gradle.enterprise'"'\)\s*version' settings.gradle | sed -E "s/.*version[[:space:]]*['\"]?([0-9]+\.[0-9]+\.[0-9]+)['\"]?.*/\1/" | tr -d [:space:])
GE_USER_DATA_PLUGIN_VERSION=$(grep -m 1 'id\s*\(\"com.gradle.common-custom-user-data-gradle-plugin\"\|'"'com.gradle.common-custom-user-data-gradle-plugin'"'\)\s*version' settings.gradle | sed -E "s/.*version[[:space:]]*['\"]?([0-9]+\.[0-9]+\.[0-9]+)['\"]?.*/\1/" | tr -d [:space:])
echo "Project uses Gradle Enterprise Plugin version: $GE_PLUGIN_VERSION"
echo "Project uses Gradle Common Custom User Data Plugin version: $GE_USER_DATA_PLUGIN_VERSION"
echo "ge_plugin_version=$GE_PLUGIN_VERSION" >> $GITHUB_OUTPUT
echo "ge_user_data_plugin_version=$GE_USER_DATA_PLUGIN_VERSION" >> $GITHUB_OUTPUT
rm settings.gradle
- name: Select Groovy Branch to checkout
id: groovy_branch
run: |
PROJECT_GROOVY_VERSION=$(grep -m 1 groovy gradle/libs.versions.toml | cut -d\= -f2 | tr -d "[:space:]'\"")
MAJOR_VERSION=$(echo $PROJECT_GROOVY_VERSION | cut -d'.' -f1)
MINOR_VERSION=$(echo $PROJECT_GROOVY_VERSION | cut -d'.' -f2)
BRANCH="GROOVY_${MAJOR_VERSION}_${MINOR_VERSION}_X"
echo "Project uses Groovy $PROJECT_GROOVY_VERSION"
echo "value=$BRANCH" >> $GITHUB_OUTPUT
rm -rf gradle
- name: Checkout Groovy Snapshot
run: |
BRANCH=${{ steps.groovy_branch.outputs.value }}
echo "Checking out Groovy branch $BRANCH"
cd .. && git clone --depth 1 https://github.com/apache/groovy.git -b $BRANCH --single-branch
- name: Set Groovy Snapshot version for project build
id: groovy_snapshot_version
run: |
cd ../groovy
echo "CI_GROOVY_VERSION=$(cat gradle.properties | grep groovyVersion | cut -d\= -f2 | tr -d '[:space:]')" >> $GITHUB_ENV
echo "value=$(cat gradle.properties | grep groovyVersion | cut -d\= -f2 | tr -d '[:space:]')" >> $GITHUB_OUTPUT
- name: Prepare GE Set-up Configuration
GROOVY_SNAPSHOT_VERSION=$(cat gradle.properties | grep groovyVersion | cut -d\= -f2 | tr -d "[:space:]")
echo "value=$GROOVY_SNAPSHOT_VERSION" >> $GITHUB_OUTPUT
- name: Prepare Gradle Enterprise Set-up Configuration
id: ge_conf
run: |
echo "VALUE<<EOF" >> $GITHUB_OUTPUT
echo "plugins { " >> $GITHUB_OUTPUT
echo " id 'com.gradle.enterprise' version '3.15.1'" >> $GITHUB_OUTPUT
echo " id 'com.gradle.common-custom-user-data-gradle-plugin' version '1.11.3'" >> $GITHUB_OUTPUT
echo "}" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "gradleEnterprise {" >> $GITHUB_OUTPUT
echo " server = 'https://ge.grails.org'" >> $GITHUB_OUTPUT
echo " buildScan {" >> $GITHUB_OUTPUT
echo " publishAlways()" >> $GITHUB_OUTPUT
echo " publishIfAuthenticated()" >> $GITHUB_OUTPUT
echo " uploadInBackground = System.getenv('CI') == null" >> $GITHUB_OUTPUT
echo " capture {" >> $GITHUB_OUTPUT
echo " taskInputFiles = true" >> $GITHUB_OUTPUT
echo " }" >> $GITHUB_OUTPUT
echo " }" >> $GITHUB_OUTPUT
echo "}" >> $GITHUB_OUTPUT
echo " id 'com.gradle.enterprise' version '${{ steps.gradle_enterprise_version.outputs.ge_plugin_version }}'" >> $GITHUB_OUTPUT
echo " id 'com.gradle.common-custom-user-data-gradle-plugin' version '${{ steps.gradle_enterprise_version.outputs.ge_user_data_plugin_version }}'" >> $GITHUB_OUTPUT
echo "}" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "gradleEnterprise {" >> $GITHUB_OUTPUT
echo " server = 'https://ge.grails.org'" >> $GITHUB_OUTPUT
echo " buildScan {" >> $GITHUB_OUTPUT
echo " publishAlways()" >> $GITHUB_OUTPUT
echo " publishIfAuthenticated()" >> $GITHUB_OUTPUT
echo " uploadInBackground = false" >> $GITHUB_OUTPUT
echo " capture {" >> $GITHUB_OUTPUT
echo " taskInputFiles = true" >> $GITHUB_OUTPUT
echo " }" >> $GITHUB_OUTPUT
echo " }" >> $GITHUB_OUTPUT
echo "}" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "buildCache {" >> $GITHUB_OUTPUT
echo " local { enabled = System.getenv('CI') != 'true' }" >> $GITHUB_OUTPUT
echo " remote(HttpBuildCache) {" >> $GITHUB_OUTPUT
echo " push = System.getenv('CI') == 'true'" >> $GITHUB_OUTPUT
echo " enabled = true" >> $GITHUB_OUTPUT
echo " url = 'https://ge.grails.org/cache/'" >> $GITHUB_OUTPUT
echo " credentials {" >> $GITHUB_OUTPUT
echo " username = System.getenv('GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER')" >> $GITHUB_OUTPUT
echo " password = System.getenv('GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY')" >> $GITHUB_OUTPUT
echo " }" >> $GITHUB_OUTPUT
echo " }" >> $GITHUB_OUTPUT
echo "}" >> $GITHUB_OUTPUT
echo "buildCache {" >> $GITHUB_OUTPUT
echo " local { enabled = false }" >> $GITHUB_OUTPUT
echo " remote(HttpBuildCache) {" >> $GITHUB_OUTPUT
echo " push = true" >> $GITHUB_OUTPUT
echo " enabled = true" >> $GITHUB_OUTPUT
echo " url = 'https://ge.grails.org/cache/'" >> $GITHUB_OUTPUT
echo " credentials {" >> $GITHUB_OUTPUT
echo " username = System.getenv('GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER')" >> $GITHUB_OUTPUT
echo " password = System.getenv('GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY')" >> $GITHUB_OUTPUT
echo " }" >> $GITHUB_OUTPUT
echo " }" >> $GITHUB_OUTPUT
echo "}" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Gradle Enterprise Set-up
run: |
cd ../groovy
# Delete exiting plugins and build-scan from settings.gradle file
sed -i '21,31d' settings.gradle
# Add Gradle Enterprise set-up related configuration after line no 20 in settings.gradle
echo "${{ steps.ge_conf.outputs.value}}" | sed -i -e "20r /dev/stdin" settings.gradle
echo "${{ steps.ge_conf.outputs.value }}" | sed -i -e "20r /dev/stdin" settings.gradle
- name: Build and install groovy (no docs)
uses: gradle/gradle-build-action@v2
uses: gradle/actions/setup-gradle@v3
env:
GRADLE_SCANS_ACCEPT: yes
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
Expand All @@ -117,36 +134,39 @@ jobs:
-x groovydocAll
-x asciidoc
-x docGDK
build_grails_views:
build_project:
needs: [build_groovy]
strategy:
fail-fast: true
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: '11'
distribution: temurin
java-version: 11

- name: Cache local Maven repository & Groovy
uses: actions/cache@v4
with:
path: |
~/groovy
~/.m2/repository
key: cache-local-groovy-maven-${{ github.sha }}
- name: Set CI_GROOVY_VERSION for Grails
run: |
echo "CI_GROOVY_VERSION=${{needs.build_groovy.outputs.groovyVersion}}" >> $GITHUB_ENV
- name: Build
id: build
uses: gradle/gradle-build-action@v2

- name: Build Project
uses: gradle/actions/setup-gradle@v3
env:
GROOVY_VERSION: ${{ needs.build_groovy.outputs.groovySnapshotVersion }}
CI_GROOVY_VERSION: ${{ needs.build_groovy.outputs.groovySnapshotVersion }}
ORG_GRADLE_PROJECT_groovyVersion: ${{ needs.build_groovy.outputs.groovySnapshotVersion }}
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GRADLE_ENTERPRISE_ACCESS_KEY }}
GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_USER }}
GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY: ${{ secrets.GRADLE_ENTERPRISE_BUILD_CACHE_NODE_KEY }}
with:
arguments: |
build
-x groovydoc
-Dgeb.env=chromeHeadless

0 comments on commit 05ddf14

Please sign in to comment.