我正在尝试创建一个 GitHub Actions 工作流程,它发布我的 Maven 项目(使用 maven-release-plugin)并将(签名的)工件推送到中央 Maven 存储库。
release:prepare
步骤运行良好(将标签推送到 GitHub),但在 release:perform
我收到以下错误:
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
这是我的工作流程:
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 }}
pom的SCM部分:
<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>
这是由
settings.xml
操作生成的 setup-java@v3
:
<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>
如何让 git 在
release:perform
步骤中工作?
最后,我将存储库的可见性从
private
更改为 public
,这为我解决了问题。
配置按照发布的方式工作。
git克隆错误可能与以下内容有关: GitHub - 致命:无法读取“https://github.com”的用户名:没有这样的文件或目录
这可能与您尝试克隆的存储库的某些凭据问题有关。
您也可以尝试:
- 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 }}
您可以在 mvn 行之前显式添加 git config user.email 和 user.name 执行。
您还可以设置:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false
...仅当结账时的凭据与来自 mvn 的 git 克隆的目标存储库不同时
另外,我不确定你的 github 用户名中是否可以有空格:
git config user.name "Github Actions Bot"
可能需要修改为:
git config user.name "Github-Actions-Bot"
我可以通过指示 scm 插件使用“github”服务器作为凭据来解决相同的错误。
这可以通过在
pom.xml
中添加以下属性来完成:
<properties>
<project.scm.id>github</project.scm.id>
</properties>
在我的 Maven
settings.xml
我的 github 服务器有以下配置:
<server>
<id>github</id>
<username>$GITHUB_ACTOR</username>
<password>$GITHUB_TOKEN</password>
</server>