maven - github操作中的Maven部署不断失败,但在本地运行良好
问题描述
嘿,我一直在尝试让我的 github 操作在构建和测试我的更改后部署 github 包,但无论我尝试什么,我都会收到以下错误:
[INFO]
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ topfind-common ---
[INFO] Uploading to github: https://maven.pkg.github.com/topfind/topfindscraper/com/topfind/topfind-common/1.121/topfind-common-1.121.jar
[INFO] Uploading to github: https://maven.pkg.github.com/topfind/topfindscraper/com/topfind/topfind-common/1.121/topfind-common-1.121.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 21.077 s
[INFO] Finished at: 2020-08-26T14:01:59Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project topfind-common: Failed to deploy artifacts: Could not find artifact com.topfind:topfind-common:jar:1.121 in github (https://maven.pkg.github.com/topfind/topfindscraper) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project topfind-common: Failed to deploy artifacts: Could not find artifact com.topfind:topfind-common:jar:1.121 in github
测试通过没有问题,我的工作流文件中有以下内容:
name: Build
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 13
uses: actions/setup-java@v1
with:
java-version: 13
- name: Get user
run: echo 'The username is' ${{ github.actor }}
- name: Build with Maven
env:
USERNAME: ${{ github.actor }}
PASSWORD: ${{ secrets.GITHUB_TOKEN }}
run: mvn -B -e deploy --file pom.xml --settings settings.xml
- uses: actions/delete-package-versions@v1
with:
package-name: 'com.topfind.topfind-scraper'
我的 pom 文件有一个指向存储库的 distributionManagement。当我在本地进行 mvn deploy 并且它不要求其他任何东西时,一切正常。有谁知道我做错了什么或我错过了什么?
解决方案
由于无法看到您的 pom 文件,我认为设置需要进行一些细微的调整。根据您的本地构建工作正常的声明,那么我的想法是查看您的管道设置。
无需传递密码,只需传递令牌。可以在此处找到有关如何设置发布工作流的确切示例 https://docs.github.com/en/actions/language-and-framework-guides/publishing-java-packages-with-maven
分发经理应该具备以下条件(如果还没有的话)
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/topfind/topfindscraper</url>
</repository>
</distributionManagement>
您的工作流程步骤应如下所示
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: 13
- name: Publish package
run: mvn -B deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
注意:确保您的 github 令牌作为对包的读/写访问权限,以确保允许部署
更新 1
根据评论中的请求,这里是创建用于发布的令牌的设置
https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token
如果令牌是私有仓库,令牌也需要访问仓库。除此以外。您只需要以下权限,具体取决于您在处理 github 包时是否希望您的令牌允许读取、写入或删除。
https://docs.github.com/en/packages/publishing-and-managing-packages/about-github-packages