deploy to Github Package Registry from Github Action

后端 未结 5 1631
暗喜
暗喜 2020-12-16 16:10

I would like to deploy to a GitHub Package Registry from a GitHub Action of a public repo.

I have a yml file for a workflow:

name: My CI

on: [push]
         


        
5条回答
  •  太阳男子
    2020-12-16 16:24

    To make it work, you need to do two things:

    1. Add the following to your pom.xml:
    
       
         github
         GitHub OWNER Apache Maven Packages
         https://maven.pkg.github.com/OWNER/REPOSITORY
       
    
    

    source: https://help.github.com/en/articles/configuring-apache-maven-for-use-with-github-package-registry#publishing-a-package

    1. Setup a Maven settings file with the username/password from within your build action. In my case I did something like this:
    name: Java CI
    
    on: [push]
    
    jobs:
      build:
    
        runs-on: ubuntu-latest
    
        steps:
        - uses: actions/checkout@v1
        - name: Set up JDK 1.8
          uses: actions/setup-java@v1
          with:
            java-version: 1.8
        - name: Deploy to Github Package Registry
          env:
            GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          run: |
            mkdir ~/.m2
            echo "githubOWNER${GITHUB_TOKEN}" > ~/.m2/settings.xml
            mvn deploy
    

    Unfortunately, I don't think you can pass the username/password as arguments to Maven and so you need to set up the settings file instead. source: Is it possible to pass a password in Maven Deploy in the command line?

    Lastly, I confirm that this only works for non-SNAPSHOT artifacts. When I try deploying a SNAPSHOT version it fails with a 400 error as described.

提交回复
热议问题