Github 操作无法从 Github 包存储库下载工件

Posted

技术标签:

【中文标题】Github 操作无法从 Github 包存储库下载工件【英文标题】:Github action cannot download artifact from Github package repository 【发布时间】:2021-03-23 20:15:55 【问题描述】:

我有两个不同的存储库。一个用于库,另一个用于需要来自其他存储库的库的应用程序。当我运行第二个存储库的 Github 操作时,我得到了一个

Authentication failed for https://maven.pkg.github.com/XXXX/YYYY/file.pom 401 Unauthorized

我已经尝试过更改 maven 设置(当我更改本地 maven 设置并安装我的应用程序时,这是有效的):

- uses: DamianReeves/write-file-action@v1.0
  with:
      path: ~/.m2/settings.xml
      contents: $ secrets.MAVEN_SETTINGS 
      write-mode: overwrite

Settings.xml 文件是:

<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
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <activeProfiles>
    <activeProfile>github</activeProfile>
  </activeProfiles>

  <profiles>
    <profile>
      <id>github</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>https://repo1.maven.org/maven2</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
        <repository>
          <id>github</id>
          <name>GitHub OWNER Apache Maven Packages</name>
          <url>https://maven.pkg.github.com/OWNER/REPOSITORY</url>
        </repository>
      </repositories>
    </profile>
  </profiles>

  <servers>
    <server>
      <id>github</id>
      <username>USERNAME</username>
      <password>TOKEN</password>
    </server>
  </servers>
</settings>

我也尝试过使用 maven-settings-action:

- name: Configure Maven
        uses: s4u/maven-settings-action@v2.2.0
        with:
          servers: |
            [
                "id": "imdb-github",
                "username": "$ secrets.MAVEN_USERNAME ",
                "password": "$ secrets.MAVEN_PASSWORD "
            ]

我也尝试使用 GITHUB_TOKEN 但没有任何运气。

需要该库的项目的 pom.xml 文件有一个 repositories 部分,如下所示:

<repositories>
        <repository>
            <id>imdb-github</id>
            <url>https://maven.pkg.github.com/user/repo</url>
        </repository>
    </repositories>

有人知道解决办法吗?

【问题讨论】:

【参考方案1】:

为了诊断此类问题,请使用调试选项-X 运行 maven 并诊断使用了哪个 serverId 的日志。

mvn -X ...

也请在本地环境中运行。

配置看起来不错,所以可能是提供了错误的用户名或密码

【讨论】:

Maven 的完整日志可以在以下位置找到:pastebin.pl/view/4a88c808【参考方案2】:

我发现了问题。我的流程是在 s4u/maven-settings-action 之后使用操作/缓存。所以缓存会覆盖设置文件。删除操作/缓存步骤问题已解决。还交换操作/缓存和 s4u/maven-settings-action 以便 maven-settings-action 在操作/缓存解决了我的问题之后。

【讨论】:

以上是关于Github 操作无法从 Github 包存储库下载工件的主要内容,如果未能解决你的问题,请参考以下文章

无法从 Github 发布 npm 包?

是否可以使用 pip 从私有 GitHub 存储库安装包?

在 Github Actions 上从 package.json 安装私有 github 包

如何从命令行列出 Github 包注册表存储库中的所有包?

使用来自 env 变量的令牌从私有 Github 存储库安装 NPM 包

将私有 github 存储库设置为 docker 中 package.json 中的依赖项在 github 操作中生成失败