Github action cannot download artifact from Github package repository

2k Views Asked by At

I have two different repositories. One for the library an another for the application that needs the library from the other repository. When I run the Github action of the second repository I got a

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

I tried already to change the maven settings with (this is working when I change my local maven settings and install my application):

- uses: DamianReeves/[email protected]
  with:
      path: ~/.m2/settings.xml
      contents: ${{ secrets.MAVEN_SETTINGS }}
      write-mode: overwrite

Settings.xml file was:

<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>

Also I tried using maven-settings-action:

- name: Configure Maven
        uses: s4u/[email protected]
        with:
          servers: |
            [{
                "id": "imdb-github",
                "username": "${{ secrets.MAVEN_USERNAME }}",
                "password": "${{ secrets.MAVEN_PASSWORD }}"
            }]

I also tried to use the GITHUB_TOKEN for it but without any luck.

The pom.xml file of the project that needs the library has a repositories section that looks like:

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

Does somebody knows the solution for this?

2

There are 2 best solutions below

0
On

I found the issue. My flow was using actions/cache after s4u/maven-settings-action. So the cache overwrite the settings file. Removing the actions/cache step the issue was resoled. Also swapping the actions/cache and s4u/maven-settings-action so that the maven-settings-action is after actions/cache has solved my issue.

1
On

In order to diagnose such issue, please run maven with debug options -X and diagnose logs which serverId is used.

mvn -X ...

Please also run the same on local environment.

Configuration look ok, so cause maybe wrong user name or password are provided