diff --git a/.agents/skills/repository-structure/SKILL.md b/.agents/skills/repository-structure/SKILL.md index 328a869..30aacaf 100644 --- a/.agents/skills/repository-structure/SKILL.md +++ b/.agents/skills/repository-structure/SKILL.md @@ -208,7 +208,8 @@ These are available in all subprojects as project properties (`projectVersion`, ## SDK Management The `.sdkmanrc` file pins exact SDK versions. Run `sdk env install` to install them. CI reads `.sdkmanrc` to determine -the Java version dynamically. +the Java version dynamically. `.sdkmanrc` and the Gradle wrapper are not overwritten by the template sync — each repo +owns them, and CI fails if `.sdkmanrc`'s `gradle` version differs from the wrapper's `distributionUrl`. ## CI/CD Pipeline diff --git a/.github/scripts/groovy.sh b/.github/scripts/groovy.sh new file mode 100755 index 0000000..8e1bbf0 --- /dev/null +++ b/.github/scripts/groovy.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +# WARNING: Do not edit this file directly in your own repository. +# It is maintained in the grails-plugin-template repository. +# To make changes, edit it there and they will be synced automatically: +# https://github.com/grails-plugins/grails-plugin-template/tree/main/.github/scripts +# +# Runs a Groovy script in the official Groovy Docker image, so workflows need +# neither a JDK nor sdkman to run the scripts in .github/scripts. The Groovy +# version is independent of .sdkmanrc: the scripts only need Groovy and its +# bundled YAML module. +# +# Usage: .github/scripts/groovy.sh [args...] +# +# The current directory is mounted at the same path, so relative and absolute +# paths into it keep working, and the script runs as the calling user, so files +# it writes stay owned by that user (and committable by the workflow). +# +# Environment: +# GROOVY_IMAGE overrides the image (default below) +# GITHUB_TOKEN, GITHUB_REPOSITORY, GITHUB_OUTPUT, FILTER_PROJECT, VERIFY_STRICT +# passed through to the script when set +set -euo pipefail + +image="${GROOVY_IMAGE:-groovy:5.0-jdk21}" + +docker_args=(--rm --user "$(id -u):$(id -g)" -e HOME=/tmp -v "${PWD}:${PWD}" -w "${PWD}") +for var in GITHUB_TOKEN GITHUB_REPOSITORY GITHUB_OUTPUT FILTER_PROJECT VERIFY_STRICT; do + if [ -n "${!var:-}" ]; then + docker_args+=(-e "${var}") + fi +done +# GITHUB_OUTPUT is a runner file outside the workspace +if [ -n "${GITHUB_OUTPUT:-}" ]; then + docker_args+=(-v "${GITHUB_OUTPUT}:${GITHUB_OUTPUT}") +fi + +exec docker run "${docker_args[@]}" "${image}" groovy "$@" diff --git a/.github/scripts/update-contributors.groovy b/.github/scripts/update-contributors.groovy index e0de9a1..bb56e09 100755 --- a/.github/scripts/update-contributors.groovy +++ b/.github/scripts/update-contributors.groovy @@ -2,7 +2,6 @@ // WARNING: Do not edit this file directly in your own repository. // It is maintained in the grails-plugin-template repository. // https://github.com/grails-plugins/grails-plugin-template/tree/main/.github/scripts -@Grab('org.apache.groovy:groovy-yaml') import groovy.json.JsonOutput import groovy.json.JsonSlurper import groovy.yaml.YamlBuilder diff --git a/.github/scripts/update-versions.groovy b/.github/scripts/update-versions.groovy index c0dd081..1061012 100755 --- a/.github/scripts/update-versions.groovy +++ b/.github/scripts/update-versions.groovy @@ -2,7 +2,6 @@ // WARNING: Do not edit this file directly in your own repository. // It is maintained in the grails-plugin-template repository. // https://github.com/grails-plugins/grails-plugin-template/tree/main/.github/scripts -@Grab('org.apache.groovy:groovy-yaml') import groovy.json.JsonSlurper import groovy.yaml.YamlBuilder import groovy.yaml.YamlSlurper diff --git a/.github/scripts/verify-repository.groovy b/.github/scripts/verify-repository.groovy index 2233894..3167d58 100644 --- a/.github/scripts/verify-repository.groovy +++ b/.github/scripts/verify-repository.groovy @@ -3,6 +3,8 @@ // // Run it locally with: // groovy .github/scripts/verify-repository.groovy +// or, without a local Groovy, through Docker like CI does: +// .github/scripts/groovy.sh .github/scripts/verify-repository.groovy // // It works both in the template repo itself and in any repo that received a // files-sync.yml sync from it — template-only checks are gated on the @@ -11,7 +13,6 @@ // Exit code is non-zero if any error was found. Warnings are printed but do // not fail the run unless VERIFY_STRICT=1 is set, in which case they are // escalated to errors too. -@Grab('org.apache.groovy:groovy-yaml') import groovy.yaml.YamlSlurper def errors = [] @@ -189,7 +190,8 @@ if (sdkmanrcFile.exists()) { def m = distUrl =~ /gradle-([0-9.]+)-/ if (m.find() && m.group(1) != sdkmanrc.getProperty('gradle')) { err(".sdkmanrc gradle version ('${sdkmanrc.getProperty('gradle')}') does not match the wrapper's " + - "distributionUrl version ('${m.group(1)}')") + "distributionUrl version ('${m.group(1)}') — update one to match the other, e.g. " + + "./gradlew wrapper --gradle-version ${sdkmanrc.getProperty('gradle')}") } } } @@ -427,6 +429,12 @@ if (isTemplate) { } } + def contributorsJob = loadYaml('.github/workflows/update-contributors.yml')?.jobs?.get('update-contributors') + if (contributorsJob != null && !((contributorsJob.'if' as String)?.contains(repoGuard))) { + err("update-contributors.yml job 'update-contributors' does not guard against running in the template " + + "repo itself (expected its 'if:' to contain \"${repoGuard}\")") + } + // ci.yml is synced, but synced repos have no conventions/ directory to test def templateOnlyGuard = "github.repository == 'grails-plugins/grails-plugin-template'" (ciYaml?.jobs?.build?.steps ?: []).each { step -> diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0b3deed..b5073b8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,26 +22,8 @@ jobs: steps: - name: "📥 Checkout repository" uses: actions/checkout@v7 - - name: "Export .sdkmanrc properties" - uses: apache/grails-github-actions/export-gradle-properties@asf - with: - file: ".sdkmanrc" - prefix: "SDKMANRC_" - - name: "Determine Java Version" - run: echo "SDKMANRC_java=${{ env.SDKMANRC_java }}" | sed 's/-.*//' >> $GITHUB_ENV - - name: "☕️ Setup JDK" - uses: actions/setup-java@v6 - with: - distribution: ${{ env.JAVA_DISTRIBUTION }} - java-version: ${{ env.SDKMANRC_java }} - - name: "🦊 Install Groovy ${{ env.SDKMANRC_groovy }}" - run: | - curl -s "https://get.sdkman.io" | bash - source "$HOME/.sdkman/bin/sdkman-init.sh" - sdk install groovy ${{ env.SDKMANRC_groovy }} < /dev/null - echo "$HOME/.sdkman/candidates/groovy/current/bin" >> $GITHUB_PATH - name: "🔍 Verify repository structure" - run: groovy .github/scripts/verify-repository.groovy + run: bash .github/scripts/groovy.sh .github/scripts/verify-repository.groovy build: name: "Build & Test" needs: verify @@ -89,7 +71,7 @@ jobs: --stacktrace --rerun-tasks - name: "☕️ Setup JDK 21 for the convention plugin tests" - # GrailsLineSpec also builds a Grails 8 consumer, whose Gradle plugin needs Java 21 + # GrailsLineSpec also builds Grails 8 and 9 consumers, whose Gradle plugins need Java 21 id: setup-java-21 if: ${{ github.repository == 'grails-plugins/grails-plugin-template' && !contains(github.event.head_commit.message, '[skip tests]') }} uses: actions/setup-java@v6 diff --git a/.github/workflows/update-contributors.yml b/.github/workflows/update-contributors.yml index 9b150b1..45a5f8a 100644 --- a/.github/workflows/update-contributors.yml +++ b/.github/workflows/update-contributors.yml @@ -15,11 +15,10 @@ permissions: contents: write pull-requests: write -env: - JAVA_DISTRIBUTION: 'liberica' - jobs: update-contributors: + # Contributors are only maintained in the plugin repos this workflow is synced to + if: ${{ github.repository != 'grails-plugins/grails-plugin-template' }} runs-on: ubuntu-24.04 steps: # A pull request opened with GITHUB_TOKEN never triggers workflows, so on a @@ -44,7 +43,7 @@ jobs: - name: "🔑 Mint GitHub App token" id: app-token if: steps.app-creds.outputs.available == 'true' - uses: actions/create-github-app-token@v2 + uses: actions/create-github-app-token@v3 with: app-id: ${{ secrets.APP_ID }} private-key: ${{ secrets.APP_PRIVATE_KEY }} @@ -54,33 +53,11 @@ jobs: with: token: ${{ steps.app-token.outputs.token || secrets.GITHUB_TOKEN }} - - name: "Export .sdkmanrc properties" - uses: apache/grails-github-actions/export-gradle-properties@asf - with: - file: ".sdkmanrc" - prefix: "SDKMANRC_" - - - name: "Determine Java Version" - run: echo "SDKMANRC_java=${{ env.SDKMANRC_java }}" | sed 's/-.*//' >> $GITHUB_ENV - - - name: "☕️ Setup JDK" - uses: actions/setup-java@v6 - with: - distribution: ${{ env.JAVA_DISTRIBUTION }} - java-version: ${{ env.SDKMANRC_java }} - - - name: "🦊 Install Groovy ${{ env.SDKMANRC_groovy }}" - run: | - curl -s "https://get.sdkman.io" | bash - source "$HOME/.sdkman/bin/sdkman-init.sh" - sdk install groovy ${{ env.SDKMANRC_groovy }} < /dev/null - echo "$HOME/.sdkman/candidates/groovy/current/bin" >> $GITHUB_PATH - - name: "👥 Update contributors in project.yml" env: GITHUB_TOKEN: ${{ github.token }} GITHUB_REPOSITORY: ${{ github.repository }} - run: groovy .github/scripts/update-contributors.groovy + run: bash .github/scripts/groovy.sh .github/scripts/update-contributors.groovy - name: "📝 Commit if changed" env: diff --git a/.github/workflows/update-versions.yml b/.github/workflows/update-versions.yml index 6a7e4a3..8cb94a0 100644 --- a/.github/workflows/update-versions.yml +++ b/.github/workflows/update-versions.yml @@ -17,9 +17,6 @@ permissions: contents: write pull-requests: write -env: - JAVA_DISTRIBUTION: 'liberica' - jobs: update-versions: runs-on: ubuntu-24.04 @@ -46,7 +43,7 @@ jobs: - name: "🔑 Mint GitHub App token" id: app-token if: steps.app-creds.outputs.available == 'true' - uses: actions/create-github-app-token@v2 + uses: actions/create-github-app-token@v3 with: app-id: ${{ secrets.APP_ID }} private-key: ${{ secrets.APP_PRIVATE_KEY }} @@ -58,33 +55,11 @@ jobs: token: ${{ steps.app-token.outputs.token || secrets.GITHUB_TOKEN }} fetch-depth: 0 - - name: "Export .sdkmanrc properties" - uses: apache/grails-github-actions/export-gradle-properties@asf - with: - file: ".sdkmanrc" - prefix: "SDKMANRC_" - - - name: "Determine Java Version" - run: echo "SDKMANRC_java=${{ env.SDKMANRC_java }}" | sed 's/-.*//' >> $GITHUB_ENV - - - name: "☕️ Setup JDK" - uses: actions/setup-java@v6 - with: - distribution: ${{ env.JAVA_DISTRIBUTION }} - java-version: ${{ env.SDKMANRC_java }} - - - name: "🦊 Install Groovy ${{ env.SDKMANRC_groovy }}" - run: | - curl -s "https://get.sdkman.io" | bash - source "$HOME/.sdkman/bin/sdkman-init.sh" - sdk install groovy ${{ env.SDKMANRC_groovy }} < /dev/null - echo "$HOME/.sdkman/candidates/groovy/current/bin" >> $GITHUB_PATH - - name: "🔢 Update versions in project.yml and generate index.html" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_REPOSITORY: ${{ github.repository }} - run: groovy .github/scripts/update-versions.groovy + run: bash .github/scripts/groovy.sh .github/scripts/update-versions.groovy - name: "📝 Commit project.yml if changed" env: diff --git a/settings.gradle b/settings.gradle index b1730ac..797af28 100644 --- a/settings.gradle +++ b/settings.gradle @@ -15,7 +15,7 @@ pluginManagement { resolutionStrategy { eachPlugin { if (requested.id.id.startsWith('config.')) { - useModule('org.grails.plugins.gradle:grails-plugin-conventions:1.0.0-RC3') + useModule('org.grails.plugins.gradle:grails-plugin-conventions:1.0.0-RC6') } } }