Unverified Commit 7d485884 authored by Bruno Borges's avatar Bruno Borges Committed by GitHub
Browse files

Use gpg.passphraseEnvName instead of the deprecated gpg.passphrase server (#1123)

* Use gpg.passphraseEnvName instead of gpg.passphrase server

The maven-gpg-plugin's `gpg.passphrase`/`passphraseServerId` mechanism is
deprecated and fails when the plugin's `bestPractices` mode is enabled.
Stop writing the `gpg.passphrase` server to settings.xml and instead set
`gpg.passphraseEnvName` via an active profile when the configured passphrase
env var name differs from the plugin default (MAVEN_GPG_PASSPHRASE).

The default `gpg-passphrase` input value (GPG_PASSPHRASE) is unchanged, so the
plugin reads the same environment variable as before.

Fixes #760

Co-authored-by: default avatarCopilot App <[email protected]>

* Fix settings.xml publishing validation

Update the publishing e2e check to assert the settings.xml generated when gpg-passphrase is MAVEN_GPG_PASSPHRASE. In that default case the action no longer writes a gpg.passphrase server entry.

Co-authored-by: default avatarCopilot App <[email protected]>

Copilot-Session: 7d0a510e-aebf-4ec4-a667-efeb3e4edeb1

* Default gpg-passphrase to MAVEN_GPG_PASSPHRASE

Align the default `gpg-passphrase` input value with the maven-gpg-plugin
default environment variable name (MAVEN_GPG_PASSPHRASE). With this default,
setup-java writes no extra GPG configuration to settings.xml and the plugin
reads the passphrase from MAVEN_GPG_PASSPHRASE out of the box.

Also document that reading the passphrase from an environment variable via
`gpg.passphraseEnvName` requires maven-gpg-plugin 3.2.0 or newer.

Co-authored-by: default avatarCopilot App <[email protected]>
Copilot-Session: 7d0a510e-aebf-4ec4-a667-efeb3e4edeb1

* Document gpg-passphrase breaking change in V6

Add a "Breaking changes in V6" section to the README covering the switch to
gpg.passphraseEnvName, the new MAVEN_GPG_PASSPHRASE default, and the
maven-gpg-plugin 3.2.0+ requirement.

Co-authored-by: default avatarCopilot App <[email protected]>
Copilot-Session: 7d0a510e-aebf-4ec4-a667-efeb3e4edeb1

* Keep GPG_PASSPHRASE default for v5 compatibility

Revert the gpg-passphrase input default back to GPG_PASSPHRASE so existing v5
workflows that set the GPG_PASSPHRASE environment variable keep working without
changes. setup-java writes gpg.passphraseEnvName=GPG_PASSPHRASE into an active
profile, so the maven-gpg-plugin reads the same variable as before.

The only remaining compatibility requirement is maven-gpg-plugin 3.2.0+, which
is documented in the README and advanced usage guide.

Co-authored-by: default avatarCopilot App <[email protected]>
Copilot-Session: 7d0a510e-aebf-4ec4-a667-efeb3e4edeb1

* Clarify GPG passphrase profile compatibility

Co-authored-by: default avatarCopilot App <[email protected]>
Copilot-Session: 7d0a510e-aebf-4ec4-a667-efeb3e4edeb1
Co-authored-by: default avatarCopilot <[email protected]>

---------

Co-authored-by: default avatarCopilot App <[email protected]>
parent c3568cc9
Loading
Loading
Loading
Loading
+18 −6
Changes for .github/workflows/e2e-publishing.yml: 18 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -46,13 +46,25 @@ jobs:
          $xmlPath = Join-Path $HOME ".m2" "settings.xml"
          Get-Content $xmlPath | ForEach-Object { Write-Host $_ }

          [xml]$xml = Get-Content $xmlPath
          $servers = $xml.settings.servers.server
          if (($servers[0].id -ne 'maven') -or ($servers[0].username -ne '${env.MAVEN_USERNAME}') -or ($servers[0].password -ne '${env.MAVEN_CENTRAL_TOKEN}')) {
            throw "Generated XML file is incorrect"
          }
          $content = [System.IO.File]::ReadAllText($xmlPath)
          $expected = @(
            '<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"'
            '  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
            '  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">'
            '  <interactiveMode>false</interactiveMode>'
            '  <servers>'
            '    <server>'
            '      <id>maven</id>'
            '      <username>${env.MAVEN_USERNAME}</username>'
            '      <password>${env.MAVEN_CENTRAL_TOKEN}</password>'
            '    </server>'
            '  </servers>'
            '</settings>'
          ) -join "`n"

          if (($servers[1].id -ne 'gpg.passphrase') -or ($servers[1].passphrase -ne '${env.MAVEN_GPG_PASSPHRASE}')) {
          if ($content -ne $expected) {
            Write-Host "Expected settings.xml:"
            $expected -split "`n" | ForEach-Object { Write-Host $_ }
            throw "Generated XML file is incorrect"
          }

+6
Changes for README.md: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -22,6 +22,12 @@ This action allows you to work with Java and Scala projects.

- **Migrated to ESM** to enable support for the latest `@actions/*` package versions. This is an internal implementation change only. No changes are required to your workflow configuration, and the action's behavior is unchanged. Existing workflows continue to work as before.

## Breaking changes in V6

- **The GPG passphrase is now passed to the Maven GPG Plugin through an environment variable (`gpg.passphraseEnvName`) instead of the deprecated `gpg.passphrase` server in `settings.xml`.** The `gpg-passphrase` input and its default (`GPG_PASSPHRASE`) are unchanged, so if you already set that environment variable in your build step your workflow keeps working. However, this now requires `maven-gpg-plugin` **3.2.0 or newer**; older versions do not honor `gpg.passphraseEnvName` and, because the `gpg.passphrase` server is no longer written, will not pick up the passphrase. Upgrade the plugin to 3.2.0+.

  See [GPG](docs/advanced-usage.md#gpg) for details.

## Breaking changes in V5

- Upgraded action from node20 to node24
+33 −2
Changes for __tests__/auth.test.ts: 33 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -228,9 +228,40 @@ describe('auth tests', () => {
      <username>\${env.${username}}</username>
      <password>\${env.&amp;&lt;&gt;"''"&gt;&lt;&amp;}</password>
    </server>
  </servers>
  <profiles>
    <profile>
      <id>setup-java-gpg</id>
      <properties>
        <gpg.passphraseEnvName>${gpgPassphrase}</gpg.passphraseEnvName>
      </properties>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>setup-java-gpg</activeProfile>
  </activeProfiles>
</settings>`;

    expect(auth.generate(id, username, password, gpgPassphrase)).toEqual(
      expectedSettings
    );
  });

  it('does not add a gpg profile when the passphrase env var is the maven-gpg-plugin default', () => {
    const id = 'packages';
    const username = 'USER';
    const password = '&<>"\'\'"><&';
    const gpgPassphrase = 'MAVEN_GPG_PASSPHRASE';

    const expectedSettings = `<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <interactiveMode>false</interactiveMode>
  <servers>
    <server>
      <id>gpg.passphrase</id>
      <passphrase>\${env.${gpgPassphrase}}</passphrase>
      <id>${id}</id>
      <username>\${env.${username}}</username>
      <password>\${env.&amp;&lt;&gt;"''"&gt;&lt;&amp;}</password>
    </server>
  </servers>
</settings>`;
+6
Changes for dist/cleanup/index.js: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -95849,6 +95849,12 @@ const INPUT_GPG_PRIVATE_KEY = 'gpg-private-key';
const INPUT_GPG_PASSPHRASE = 'gpg-passphrase';
const INPUT_DEFAULT_GPG_PRIVATE_KEY = (/* unused pure expression or super */ null && (undefined));
const INPUT_DEFAULT_GPG_PASSPHRASE = 'GPG_PASSPHRASE';
// The default name of the environment variable the maven-gpg-plugin reads the
// passphrase from (property `gpg.passphraseEnvName`). When the configured
// passphrase env var name matches this, no extra configuration is required.
const MAVEN_GPG_PASSPHRASE_DEFAULT_ENV = 'MAVEN_GPG_PASSPHRASE';
// Id of the settings.xml profile used to set `gpg.passphraseEnvName`.
const GPG_PASSPHRASE_PROFILE_ID = 'setup-java-gpg';
const INPUT_CACHE = 'cache';
const INPUT_CACHE_DEPENDENCY_PATH = 'cache-dependency-path';
const INPUT_JOB_STATUS = 'job-status';
+24 −5
Changes for dist/setup/index.js: 24 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -73294,6 +73294,12 @@ const INPUT_GPG_PRIVATE_KEY = 'gpg-private-key';
const INPUT_GPG_PASSPHRASE = 'gpg-passphrase';
const INPUT_DEFAULT_GPG_PRIVATE_KEY = undefined;
const INPUT_DEFAULT_GPG_PASSPHRASE = 'GPG_PASSPHRASE';
// The default name of the environment variable the maven-gpg-plugin reads the
// passphrase from (property `gpg.passphraseEnvName`). When the configured
// passphrase env var name matches this, no extra configuration is required.
const MAVEN_GPG_PASSPHRASE_DEFAULT_ENV = 'MAVEN_GPG_PASSPHRASE';
// Id of the settings.xml profile used to set `gpg.passphraseEnvName`.
const GPG_PASSPHRASE_PROFILE_ID = 'setup-java-gpg';
const INPUT_CACHE = 'cache';
const INPUT_CACHE_DEPENDENCY_PATH = 'cache-dependency-path';
const constants_INPUT_JOB_STATUS = 'job-status';
@@ -127311,12 +127317,25 @@ function generate(id, username, password, gpgPassphrase) {
            }
        }
    };
    if (gpgPassphrase) {
        const gpgServer = {
            id: 'gpg.passphrase',
            passphrase: `\${env.${gpgPassphrase}}`
    // The maven-gpg-plugin reads the passphrase from the environment variable
    // named by the `gpg.passphraseEnvName` property (default MAVEN_GPG_PASSPHRASE).
    // Only configure it when the requested env var name differs from that default;
    // otherwise the plugin already reads the right variable and no extra settings
    // are needed. Writing `gpg.passphrase` to settings.xml is deprecated and fails
    // when the plugin's `bestPractices` mode is enabled.
    if (gpgPassphrase &&
        gpgPassphrase !== MAVEN_GPG_PASSPHRASE_DEFAULT_ENV) {
        xmlObj.settings.profiles = {
            profile: {
                id: GPG_PASSPHRASE_PROFILE_ID,
                properties: {
                    'gpg.passphraseEnvName': gpgPassphrase
                }
            }
        };
        xmlObj.settings.activeProfiles = {
            activeProfile: GPG_PASSPHRASE_PROFILE_ID
        };
        xmlObj.settings.servers.server.push(gpgServer);
    }
    return (0,lib/* create */.vt)(xmlObj).end({
        headless: true,
Loading