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

Clarify credential environment variable inputs (#1134)

* Clarify credential environment variable inputs

Rename credential-related inputs to make their environment-variable semantics explicit while preserving deprecated aliases with migration warnings.

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

Copilot-Session: 70a3daa8-dbc9-4eb0-a57b-df198a459315

* Potential fix for pull request finding

Co-authored-by: default avatarCopilot Autofix powered by AI <[email protected]>

---------

Co-authored-by: default avatarCopilot Autofix powered by AI <[email protected]>
parent 46f62940
Loading
Loading
Loading
Loading
+12 −12
Changes for .github/workflows/e2e-publishing.yml: 12 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -38,9 +38,9 @@ jobs:
          distribution: 'adopt'
          java-version: '11'
          server-id: maven
          server-username: MAVEN_USERNAME
          server-password: MAVEN_CENTRAL_TOKEN
          gpg-passphrase: MAVEN_GPG_PASSPHRASE
          server-username-env-var: MAVEN_USERNAME
          server-password-env-var: MAVEN_CENTRAL_TOKEN
          gpg-passphrase-env-var: MAVEN_GPG_PASSPHRASE
      - name: Validate settings.xml
        run: |
          $xmlPath = Join-Path $HOME ".m2" "settings.xml"
@@ -93,9 +93,9 @@ jobs:
          distribution: 'adopt'
          java-version: '11'
          server-id: maven
          server-username: MAVEN_USERNAME
          server-password: MAVEN_CENTRAL_TOKEN
          gpg-passphrase: MAVEN_GPG_PASSPHRASE
          server-username-env-var: MAVEN_USERNAME
          server-password-env-var: MAVEN_CENTRAL_TOKEN
          gpg-passphrase-env-var: MAVEN_GPG_PASSPHRASE
      - name: Validate settings.xml is overwritten
        run: |
          $xmlPath = Join-Path $HOME ".m2" "settings.xml"
@@ -131,10 +131,10 @@ jobs:
          distribution: 'adopt'
          java-version: '11'
          server-id: maven
          server-username: MAVEN_USERNAME
          server-password: MAVEN_CENTRAL_TOKEN
          server-username-env-var: MAVEN_USERNAME
          server-password-env-var: MAVEN_CENTRAL_TOKEN
          overwrite-settings: false
          gpg-passphrase: MAVEN_GPG_PASSPHRASE
          gpg-passphrase-env-var: MAVEN_GPG_PASSPHRASE
      - name: Validate that settings.xml is not overwritten
        run: |
          $xmlPath = Join-Path $HOME ".m2" "settings.xml"
@@ -164,9 +164,9 @@ jobs:
          distribution: 'adopt'
          java-version: '11'
          server-id: maven
          server-username: MAVEN_USERNAME
          server-password: MAVEN_CENTRAL_TOKEN
          gpg-passphrase: MAVEN_GPG_PASSPHRASE
          server-username-env-var: MAVEN_USERNAME
          server-password-env-var: MAVEN_CENTRAL_TOKEN
          gpg-passphrase-env-var: MAVEN_GPG_PASSPHRASE
          settings-path: ${{ runner.temp }}
      - name: Validate settings.xml location
        run: |
+7 −5
Changes for README.md: 7 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -23,11 +23,13 @@ This action allows you to work with Java and Scala projects.
> [!NOTE]
> V6 is still in development (`main` branch) and is not yet recommended for production workflows.

- **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.
- **Migrated to ESM** to enable support for the latest `@actions/*` package versions. This is an internal implementation change.

## 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+.
- **Renamed inputs that accept environment-variable names** to make it clear that their values are not credentials. Replace `server-username`, `server-password`, and `gpg-passphrase` with `server-username-env-var`, `server-password-env-var`, and `gpg-passphrase-env-var`, respectively. The old names remain as deprecated aliases and emit a warning when used.

- **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`.** Set the environment variable name with `gpg-passphrase-env-var`, which defaults to `GPG_PASSPHRASE`. This 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.

@@ -75,15 +77,15 @@ For more details, see the full release notes on the [releases page](https://git

    - `server-id`: ID of the distributionManagement repository in the pom.xml file. Default is `github`.

    - `server-username`: Environment variable name for the username for authentication to the Apache Maven repository. Default is GITHUB\_ACTOR.
    - `server-username-env-var`: Environment variable name for the username for authentication to the Apache Maven repository. Default is GITHUB\_ACTOR.

    - `server-password`: Environment variable name for password or token for authentication to the Apache Maven repository. Default is GITHUB\_TOKEN.
    - `server-password-env-var`: Environment variable name for password or token for authentication to the Apache Maven repository. Default is GITHUB\_TOKEN.

    - `settings-path`: Maven related setting to point to the directory where the settings.xml file will be written. Default is \~/.m2.

    - `gpg-private-key`: GPG private key to import. Default is empty string.

    - `gpg-passphrase`: Environment variable name for the GPG private key passphrase. Default is GPG\_PASSPHRASE.
    - `gpg-passphrase-env-var`: Environment variable name for the GPG private key passphrase. Default is GPG\_PASSPHRASE.

    - `mvn-toolchain-id`: Name of Maven Toolchain ID if the default name of `${distribution}_${java-version}` is not wanted.

+51
Changes for __tests__/auth.test.ts: 51 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -270,4 +270,55 @@ describe('auth tests', () => {
      expectedSettings
    );
  });

  it('uses deprecated input aliases and warns', () => {
    const mockGetInput = core.getInput as jest.MockedFunction<
      typeof core.getInput
    >;
    const mockWarning = core.warning as jest.MockedFunction<
      typeof core.warning
    >;
    mockGetInput.mockImplementation(name =>
      name === 'server-username' ? 'LEGACY_USERNAME' : ''
    );

    expect(
      auth.getInputWithDeprecatedAlias(
        'server-username-env-var',
        'server-username',
        'GITHUB_ACTOR'
      )
    ).toBe('LEGACY_USERNAME');
    expect(mockWarning).toHaveBeenCalledWith(
      "The 'server-username' input is deprecated and may be removed in a future release. Please use 'server-username-env-var' instead."
    );

    mockGetInput.mockReset();
    mockWarning.mockReset();
  });

  it('prefers the replacement input over its deprecated alias', () => {
    const mockGetInput = core.getInput as jest.MockedFunction<
      typeof core.getInput
    >;
    mockGetInput.mockImplementation(name => {
      const inputs: Record<string, string> = {
        'server-password-env-var': 'NEW_PASSWORD',
        'server-password': 'LEGACY_PASSWORD'
      };
      return inputs[name] || '';
    });

    expect(
      auth.getInputWithDeprecatedAlias(
        'server-password-env-var',
        'server-password',
        'GITHUB_TOKEN'
      )
    ).toBe('NEW_PASSWORD');
    expect(core.warning).toHaveBeenCalled();

    mockGetInput.mockReset();
    (core.warning as jest.Mock).mockReset();
  });
});
+12 −5
Changes for action.yml: 12 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -46,16 +46,20 @@ inputs:
       file. Default is `github`'
    required: false
    default: 'github'
  server-username:
  server-username-env-var:
    description: 'Environment variable name for the username for authentication
       to the Apache Maven repository. Default is $GITHUB_ACTOR'
    required: false
    default: 'GITHUB_ACTOR'
  server-password:
  server-username:
    description: 'Deprecated alias for server-username-env-var'
    required: false
  server-password-env-var:
    description: 'Environment variable name for password or token for
       authentication to the Apache Maven repository. Default is $GITHUB_TOKEN'
    required: false
    default: 'GITHUB_TOKEN'
  server-password:
    description: 'Deprecated alias for server-password-env-var'
    required: false
  settings-path:
    description: 'Path to where the settings.xml file will be written. Default is ~/.m2.'
    required: false
@@ -67,8 +71,11 @@ inputs:
    description: 'GPG private key to import. Default is empty string.'
    required: false
    default: ''
  gpg-passphrase-env-var:
    description: 'Environment variable name for the GPG private key passphrase. Defaults to GPG_PASSPHRASE when gpg-private-key is set.'
    required: false
  gpg-passphrase:
    description: 'Environment variable name for the GPG private key passphrase. Defaults to GPG_PASSPHRASE when gpg-private-key is set; ignored otherwise.'
    description: 'Deprecated alias for gpg-passphrase-env-var'
    required: false
  cache:
    description: 'Name of the build platform to cache dependencies. It can be "maven", "gradle" or "sbt".'
+8 −3
Changes for dist/cleanup/index.js: 8 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -95928,12 +95928,17 @@ const INPUT_PROBLEM_MATCHER = 'problem-matcher';
const INPUT_VERIFY_SIGNATURE = 'verify-signature';
const INPUT_VERIFY_SIGNATURE_PUBLIC_KEY = 'verify-signature-public-key';
const INPUT_SERVER_ID = 'server-id';
const INPUT_SERVER_USERNAME = 'server-username';
const INPUT_SERVER_PASSWORD = 'server-password';
const INPUT_SERVER_USERNAME_ENV_VAR = 'server-username-env-var';
const INPUT_SERVER_PASSWORD_ENV_VAR = 'server-password-env-var';
const INPUT_SERVER_USERNAME_DEPRECATED = 'server-username';
const INPUT_SERVER_PASSWORD_DEPRECATED = 'server-password';
const INPUT_SETTINGS_PATH = 'settings-path';
const INPUT_OVERWRITE_SETTINGS = 'overwrite-settings';
const INPUT_GPG_PRIVATE_KEY = 'gpg-private-key';
const INPUT_GPG_PASSPHRASE = 'gpg-passphrase';
const INPUT_GPG_PASSPHRASE_ENV_VAR = 'gpg-passphrase-env-var';
const INPUT_GPG_PASSPHRASE_DEPRECATED = 'gpg-passphrase';
const INPUT_DEFAULT_SERVER_USERNAME = 'GITHUB_ACTOR';
const INPUT_DEFAULT_SERVER_PASSWORD = 'GITHUB_TOKEN';
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
Loading