diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000000..00483c1e0b --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,8 @@ +# Changes to these paths can move secrets, publish artifacts, or change what ships to users, +# so they need an owner's review. Takes effect once branch protection on main requires +# approvals and "require review from Code Owners". +/.github/ @nedtwigg @edgartwigg +/build-logic/ @nedtwigg @edgartwigg +/settings.gradle.kts @nedtwigg @edgartwigg +/build.gradle.kts @nedtwigg @edgartwigg +/gradle.properties @nedtwigg @edgartwigg diff --git a/.github/scripts/configure_publishing_secrets.py b/.github/scripts/configure_publishing_secrets.py deleted file mode 100644 index 9dd1ef9f98..0000000000 --- a/.github/scripts/configure_publishing_secrets.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env python3 -import base64 -import os -import re -import uuid - - -def decode_secret(env_var_name: str) -> str: - raw = os.environ.get(env_var_name, "") - if not raw: - return "" - # MIME Base64: ignore non-base64 chars (newlines, carriage returns, spaces, etc.) - cleaned = re.sub(r"[^A-Za-z0-9+/=]", "", raw) - if not cleaned: - return "" - return base64.b64decode(cleaned).decode("utf-8").strip() - - -def main(): - github_env = os.environ.get("GITHUB_ENV") - if not github_env: - return - - env_updates = {} - - # 1. Maven Central Password - maven_central_password = decode_secret("NEXUS_PASS64") - if maven_central_password: - env_updates["ORG_GRADLE_PROJECT_mavenCentralPassword"] = maven_central_password - - # 2. GPG Signing Key - gpg_key = decode_secret("GPG_KEY64") - if gpg_key: - env_updates["ORG_GRADLE_PROJECT_signingInMemoryKey"] = gpg_key - env_updates["ORG_GRADLE_PROJECT_signingInMemoryKeyId"] = "0x4272C851" - - # 3. GPG Passphrase - gpg_passphrase = os.environ.get("GPG_PASSPHRASE", "") - if gpg_passphrase: - env_updates["ORG_GRADLE_PROJECT_signingInMemoryKeyPassword"] = gpg_passphrase - - with open(github_env, "a", encoding="utf-8") as f: - for key, value in env_updates.items(): - if "\n" in value or "\r" in value: - delimiter = f"EOF_{uuid.uuid4().hex}" - f.write(f"{key}<<{delimiter}\n{value}\n{delimiter}\n") - else: - f.write(f"{key}={value}\n") - - if "ORG_GRADLE_PROJECT_mavenCentralPassword" in env_updates: - print("Configured ORG_GRADLE_PROJECT_mavenCentralPassword=***") - if "ORG_GRADLE_PROJECT_signingInMemoryKey" in env_updates: - print("Configured ORG_GRADLE_PROJECT_signingInMemoryKey=***") - if "ORG_GRADLE_PROJECT_signingInMemoryKeyPassword" in env_updates: - print("Configured ORG_GRADLE_PROJECT_signingInMemoryKeyPassword=***") - - -if __name__ == "__main__": - main() diff --git a/.github/workflows/changelog-print.yml b/.github/workflows/changelog-print.yml index dc0223f036..e55cc0037c 100644 --- a/.github/workflows/changelog-print.yml +++ b/.github/workflows/changelog-print.yml @@ -4,6 +4,9 @@ on: push: branches: [main] +permissions: + contents: read + jobs: build: runs-on: ubuntu-latest diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a1aa253424..f34b197ce0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,10 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +# least privilege by default; jobs opt in to more below +permissions: + contents: read + jobs: sanity-check: name: Sanity Check @@ -35,6 +39,9 @@ jobs: build-gradle: name: Gradle (Java ${{ matrix.jre }}, ${{ matrix.os }}) needs: sanity-check + permissions: + contents: read + checks: write # mikepenz/action-junit-report posts check runs strategy: fail-fast: false matrix: @@ -63,6 +70,9 @@ jobs: build-maven: name: Maven (Java ${{ matrix.jre }}, ${{ matrix.os }}) needs: sanity-check + permissions: + contents: read + checks: write # mikepenz/action-junit-report posts check runs strategy: fail-fast: false matrix: @@ -91,6 +101,9 @@ jobs: test-npm: name: NPM needs: sanity-check + permissions: + contents: read + checks: write # mikepenz/action-junit-report posts check runs runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 @@ -111,6 +124,9 @@ jobs: test-shfmt: name: Shfmt needs: sanity-check + permissions: + contents: read + checks: write # mikepenz/action-junit-report posts check runs runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 @@ -138,6 +154,9 @@ jobs: test-idea: name: IntelliJ IDEA needs: sanity-check + permissions: + contents: read + checks: write # mikepenz/action-junit-report posts check runs runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 @@ -183,29 +202,3 @@ jobs: exit 1 fi echo "All required jobs completed successfully." - - publish-snapshots: - name: Publish Snapshots - needs: final-status - if: github.event.repository.fork == false && github.ref == 'refs/heads/main' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v7 - with: - fetch-depth: 0 - - uses: actions/setup-java@v6 - with: - distribution: "temurin" - java-version: 21 - - uses: gradle/actions/setup-gradle@v6 - with: - cache-read-only: true - - name: Configure publishing secrets - env: - NEXUS_PASS64: ${{ secrets.NEXUS_PASS64 }} - GPG_KEY64: ${{ secrets.GPG_KEY64 }} - GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} - run: python3 .github/scripts/configure_publishing_secrets.py - - run: ./gradlew publishToMavenCentral - env: - ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.NEXUS_USER }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0391573a0a..943910749a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,13 +1,18 @@ # NEXUS_USER -# NEXUS_PASS64 (base64 NOTE: `base64` and `openssl base64` failed, had to use Java -# byte[] data = "{{password}}".getBytes(StandardCharsets.UTF_8); -# String encoded = new String(Base64.getEncoder().encode(data), StandardCharsets.UTF_8); -# System.out.println(encoded); +# NEXUS_PASS # GPG_PASSPHRASE -# GPG_KEY64 (base64) -# gpg --export-secret-keys --armor KEY_ID | openssl base64 | pbcopy +# GPG_KEY +# gpg --export-secret-subkeys --armor SUBKEY_ID! | pbcopy +# subkeys only, so the primary key never lands in CI # GRADLE_KEY # GRADLE_SECRET +# +# NEXUS_PASS and GPG_KEY are environment secrets on `maven-central`, not org secrets. +# +# Store each secret in the exact form the build consumes. GitHub masks the value it was given, +# so anything a workflow step decodes or reshapes is no longer masked and lands in the log. +# That is why the base64 variants (NEXUS_PASS64, GPG_KEY64) were deleted on 2026-09-17; do not +# reintroduce them. name: deploy on: @@ -28,21 +33,24 @@ jobs: build: runs-on: ubuntu-latest name: deploy + # holds the publishing secrets; its branch policy allows only `release`, which only + # nedtwigg can push to, so nothing else in the repo can reach them + environment: maven-central permissions: contents: write env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.NEXUS_USER }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.NEXUS_PASS }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.GPG_KEY }} + # signing subkey issued 2026-09-17, replacing 0x4272C851 whose encrypted copy was exposed + # in public CI logs: https://github.com/diffplug/spotless/issues/3089 + ORG_GRADLE_PROJECT_signingInMemoryKeyId: "0xFA5C18CFB74EC7C6" + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.GPG_PASSPHRASE }} steps: - uses: actions/checkout@v7 with: persist-credentials: false - - name: Configure publishing secrets - env: - NEXUS_PASS64: ${{ secrets.NEXUS_PASS64 }} - GPG_KEY64: ${{ secrets.GPG_KEY64 }} - GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} - run: python3 .github/scripts/configure_publishing_secrets.py - name: Configure git credentials for JGit run: | git config --local http.https://github.com/.extraheader "AUTHORIZATION: basic $(echo -n x-access-token:${{ secrets.GITHUB_TOKEN }} | base64 -w0)" diff --git a/.github/workflows/renovate-changelog.yml b/.github/workflows/renovate-changelog.yml index 7d5905148a..be4f44f42f 100644 --- a/.github/workflows/renovate-changelog.yml +++ b/.github/workflows/renovate-changelog.yml @@ -20,20 +20,29 @@ jobs: ref: ${{ github.head_ref }} fetch-depth: 0 - uses: actions/setup-python@v7 + # branch and PR fields arrive through env, never spliced into the shell: a branch name is + # attacker-controlled text, and ${{ }} would run it as part of the command - name: Update Changelogs + env: + BASE_REF: ${{ github.base_ref }} + PR_NUMBER: ${{ github.event.pull_request.number }} + PR_URL: ${{ github.event.pull_request.html_url }} run: | python3 .github/scripts/update_renovate_changelogs.py \ - --base-ref "origin/${{ github.base_ref }}" \ - --pr-number "${{ github.event.pull_request.number }}" \ - --pr-url "${{ github.event.pull_request.html_url }}" + --base-ref "origin/$BASE_REF" \ + --pr-number "$PR_NUMBER" \ + --pr-url "$PR_URL" - name: Commit and push changes + env: + HEAD_REF: ${{ github.head_ref }} + PR_NUMBER: ${{ github.event.pull_request.number }} run: | if [ -n "$(git status --porcelain CHANGES.md plugin-gradle/CHANGES.md plugin-maven/CHANGES.md)" ]; then git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git add CHANGES.md plugin-gradle/CHANGES.md plugin-maven/CHANGES.md - git commit -m "Update changelogs for default formatter version bump (#${{ github.event.pull_request.number }})" - git push origin HEAD:${{ github.head_ref }} + git commit -m "Update changelogs for default formatter version bump (#$PR_NUMBER)" + git push origin "HEAD:$HEAD_REF" else echo "No changelog updates needed." fi diff --git a/.github/workflows/scheduled-cleanup.yml b/.github/workflows/scheduled-cleanup.yml index e0c5a031ef..8d4089309b 100644 --- a/.github/workflows/scheduled-cleanup.yml +++ b/.github/workflows/scheduled-cleanup.yml @@ -6,6 +6,9 @@ on: concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +permissions: + contents: read + jobs: sanity: name: Sanity 🦢 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index af502cc437..3f2ebda035 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -211,25 +211,12 @@ pluginManagement { ### Gradle - snapshot builds -Snapshot builds are automatically published to Maven Central Snapshots on every commit to `main`. In any project, you can use the following snippet in your `settings.gradle` (for Gradle 6.0+). - -```gradle -pluginManagement { - repositories { - maven { - url 'https://central.sonatype.com/repository/maven-snapshots/' - content { - includeGroup 'com.diffplug.spotless' - } - } - gradlePluginPortal() - } -} -``` +We don't publish snapshots. Publishing credentials are reachable only from the `release` branch, so +`main` cannot publish anything. Use the local workflow above to test an unreleased change. ### Maven -Run `./gradlew publishToMavenLocal` to publish this to your local repository. You can also use snapshot artifacts from `https://central.sonatype.com/repository/maven-snapshots/`. +Run `./gradlew publishToMavenLocal` to publish this to your local repository. ## License