Skip to content

Commit

Permalink
Update to latest Gradle Action, tweak build for configuration cache (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jskov authored Nov 20, 2024
1 parent 8540ecc commit f7457b2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@ jobs:
with:
fetch-depth: 0 # Allows sonar to collect blame information

- name: Setup Gradle
uses: gradle/actions/setup-gradle@d156388eb19639ec20ade50009f3d199ce1e2808
# v4
with:
validate-wrappers: true

# From https://docs.sonarqube.org/latest/analysis/github-integration/
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Setup Gradle
uses: gradle/actions/setup-gradle@cc4fc85e6b35bafd578d5ffbc76a5518407e1af0
# v4.2.1
with:
validate-wrappers: true
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}

- name: Run tests
run: ./gradlew check javadoc publish sonar -s -Pversion=${BUILD_LABEL//\//_}
run: ./gradlew --configuration-cache check javadoc publish sonar -s -Pversion=${BUILD_LABEL//\//_}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Expand Down
34 changes: 23 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ plugins {
ext {
mavenDisplayName = 'Plugin for enforcing java dk.mada coding style'
mavenDescription = 'A plugin that sets up null-checking and code formatting style for dk.mada development.'

def configDir = layout.getProjectDirectory().dir('src/main/resources/config')
eclipseFormatterConfigFiles = [configDir.file('spotless/eclipse-formatter-mada.xml')]
checkstyleConfigFiles = [configDir.file('checkstyle/checkstyle-mada.xml'),
configDir.file('checkstyle/suppressions-mada.xml')]

errorProneDependencies = project.getProviders().provider(() -> getErrorProneDependencies())
}

group = 'dk.mada.style'
Expand Down Expand Up @@ -44,19 +51,18 @@ dependencies {
}

tasks.named('processResources').configure {
inputs.files(eclipseFormatterConfigFiles)
inputs.files(checkstyleConfigFiles)
inputs.property('errorProneDeps', errorProneDependencies)

// Checksum each configuration file so it is easy for the plugin to reason about their state
filesMatching('config/datafile-checksums.properties') {
def eclipseFormatterMadaChecksum = digestFiles([file('src/main/resources/config/spotless/eclipse-formatter-mada.xml')])
def checkstyleMadaChecksum = digestFiles([file('src/main/resources/config/checkstyle/checkstyle-mada.xml'), file('src/main/resources/config/checkstyle/suppressions-mada.xml')])
filter { l -> l.replace('@ECLIPSE_FORMATTER_MADA@', eclipseFormatterMadaChecksum)
.replace('@CHECKSTYLE_MADA@', checkstyleMadaChecksum) }
filter { l -> l.replace('@ECLIPSE_FORMATTER_MADA@', digestFiles(eclipseFormatterConfigFiles))
.replace('@CHECKSTYLE_MADA@', digestFiles(checkstyleConfigFiles)) }
}
// Provide the plugin with versions for the dependencies it adds to the client build
filesMatching('config/datafile-dependencies.properties') {
def depVersions = configurations.addedDependencies.collect { f ->
f.toString().replaceAll(".*files-2.1/", "").replaceFirst("/", "\\\\:").replaceFirst("/", "=").replaceAll("/.*", "")
}.join('\n')
filter { l -> l.replace('@DEPENDENCIES@', depVersions) }
filter { l -> l.replace('@DEPENDENCIES@', errorProneDependencies) }
}
}

Expand Down Expand Up @@ -114,11 +120,17 @@ tasks.named('eclipse').configure {
doLast { project.mkdir("build/pluginUnderTestMetadata") }
}

String digestFiles(List<File> files) {
String digestFiles(List<RegularFile> files) {
def digester = java.security.MessageDigest.getInstance("MD5")
for (File f : files) {
byte[] b = f.readBytes()
for (RegularFile f : files) {
byte[] b = f.getAsFile().readBytes()
digester.update(b)
}
return java.util.HexFormat.of().formatHex(digester.digest())
}

String getErrorProneDependencies() {
return project.configurations.addedDependencies.collect { f ->
f.toString().replaceAll(".*files-2.1/", "").replaceFirst("/", "\\\\:").replaceFirst("/", "=").replaceAll("/.*", "")
}.join('\n')
}

0 comments on commit f7457b2

Please sign in to comment.