meva
meva

Reputation: 333

Github Actions: Could not read Username for 'https://github.com' when maven-release-plugin runs release:perform

I'm trying to create a GitHub Actions workflow which releases my maven project (using maven-release-plugin) and pushes the (signed) artifacts to the central maven repository.

The release:prepare step runs fine (pushes tags to GitHub), but on the release:perform I'm getting the following error:

Error:  Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.3:perform (default-cli) on project myproject: Unable to checkout from SCM
Error:  Provider message:
Error:  The git-clone command failed.
Error:  Command output:
Error:  Cloning into '/home/runner/work/myproject/myproject/target/checkout'...
Error:  fatal: could not read Username for 'https://github.com': No such device or address

Here's my workflow:

name: Release MyProject

on:
  workflow_dispatch:
    inputs:
      releaseVersion:
        description: 'Release version'
        required: true
        type: string
      developmentVersion:
        description: 'Development version after release'
        required: true
        type: string
      publishTo:
        description: 'Publish to'
        required: true
        default: 'MavenCentral'
        type: choice
        options:
          - 'MavenCentral'
          - 'none (dry run)'

env:
  RELEASE_VERSION: ${{ inputs.releaseVersion }}
  DEVELOPMENT_VERSION: ${{ inputs.developmentVersion }}
  PUBLISH_TO: ${{ inputs.publishTo }}

jobs:
  build_release:
    name: build myproject release
    runs-on: ubuntu-latest
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Set up JDK 11
        uses: actions/setup-java@v3
        with:
          java-version: '11.0.11'
          distribution: 'zulu'
          cache: 'maven'
          server-id: 'ossrh' # Value of the distributionManagement/repository/id field of the pom.xml
          server-username: MAVEN_USERNAME # same name as below env variable
          server-password: MAVEN_PASSWORD # same name as below env variable
          gpg-private-key: ${{ secrets.PGP_PRIVATE_KEY }}
          gpg-passphrase: GPG_PASSPHRASE # same name as below env variable
      - name: Configure git user
        run: |
          git config user.email "[email protected]"
          git config user.name "Github Actions Bot"
      - name: Maven clean
        run: mvn --batch-mode clean release:clean
        shell: bash
      - name: Maven release:prepare
        run: mvn --batch-mode -DdryRun=${{ env.PUBLISH_TO == 'none (dry run)' }} -DdevelopmentVersion=$DEVELOPMENT_VERSION -DreleaseVersion=$RELEASE_VERSION release:prepare
        shell: bash
      - name: Maven release:perform
        run: mvn --batch-mode -DdryRun=${{ env.PUBLISH_TO == 'none (dry run)' }} release:perform
        shell: bash
        env:
          MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
          MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
          GPG_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}

SCM section of the pom:

  <scm>
    <connection>scm:git:https://github.com/mycompany/myproject.git</connection>
    <developerConnection>scm:git:https://github.com/mycompany/myproject.git</developerConnection>
    <url>https://github.com/mycompany/myproject</url>
    <tag>HEAD</tag>
  </scm>

Here's the settings.xml generated by the setup-java@v3 action:

<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">
  <servers>
    <server>
      <id>ossrh</id>
      <username>${env.MAVEN_USERNAME}</username>
      <password>${env.MAVEN_PASSWORD}</password>
    </server>
    <server>
      <id>gpg.passphrase</id>
      <passphrase>${env.GPG_PASSPHRASE}</passphrase>
    </server>
  </servers>
</settings>

How do I get git to work in the release:perform step?

Upvotes: 4

Views: 3256

Answers (3)

Enrico
Enrico

Reputation: 422

I could solve the same error by instructing the scm plugin to use the 'github' server for the credentials.
This can be done by adding the following property in the pom.xml:

<properties>
    <project.scm.id>github</project.scm.id>
</properties>

In my Maven settings.xml I have the following configuration for the github server:

<server>
  <id>github</id>                     
  <username>$GITHUB_ACTOR</username>
  <password>$GITHUB_TOKEN</password>
</server>

Upvotes: 1

meva
meva

Reputation: 333

In the end I changed the repository's visibility from private to public which resolved the issue for me.

The configuration worked as posted.

Upvotes: 2

Carl M. Cartagena
Carl M. Cartagena

Reputation: 111

The git clone error may be related to: GitHub - fatal: could not read Username for 'https://github.com': No such file or directory

This would probably be related to some credential issue with the repo you are attempting to clone.

You could also try:

  - name: Maven release:perform
    run: |
      git config user.email "[email protected]"
      git config user.name "Github Actions Bot"
      mvn --batch-mode -DdryRun=${{ env.PUBLISH_TO == 'none (dry run)' }} release:perform
    shell: bash
    env:
      MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
      MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
      GPG_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}

You may explicitly add the git config user.email and user.name executions right before the mvn line.

You may also set:

  - name: Checkout
    uses: actions/checkout@v3
    with:
      persist-credentials: false

...only if the credentials from the checkout will be different than the target repo for the git clone from mvn

Also, I'm not sure if you can have spaces in your github user.name:

  git config user.name "Github Actions Bot"

may need to be revised to:

  git config user.name "Github-Actions-Bot"

Upvotes: 0

Related Questions