Using github actions to publish to github package repository

I’m trying to use this workflow to package a release to github package repository.  But currently when I run it the tests pass but I get a 401. Any ideas?

name: Release workflow

    # Sequence of patterns matched against refs/tags
      - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
    name: Create Release
    runs-on: ubuntu-latest
      - name: Checkout code
        uses: actions/checkout@v2
      # TODO: Can I just download the artifact from the previous commit run??
      - name: Set up JDK 1.8
        uses: actions/setup-java@v1
          java-version: 1.8
      - uses: actions/cache@v1
          path: ~/.m2/repository
          key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
          restore-keys: |
            ${{ runner.os }}-maven-
      - name: Build with Maven
        run: mvn -B package --file pom.xml
      - name: push to github packages with maven
        continue-on-error: true
        run: mvn -B deploy --file pom.xml
      - name: clean up target folder
        run: rm -rf ./target/lib ./target/test-classes
      - name: Upload artifact
        uses: actions/upload-artifact@v1.0.0
        # TODO: make this only run if the build step at least ran
        if: always()
          # Artifact name
          name: auto-pipeline-jar
          # Directory containing files to upload
          path: ./target
      - name: Create zip
        run: cd target; zip -r ../ .
      - name: Create Release
        id: create_release
        uses: actions/create-release@v1
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
          tag_name: ${{ github.ref }}
          release_name: Release ${{ github.ref }}
          body: New release for ${{ github.ref }}
          draft: false
          prerelease: false
      - name: Upload Release Asset
        id: upload-release-asset
        uses: actions/upload-release-asset@v1
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info:
          asset_path: ./
          asset_content_type: application/zip
      # TODO: Upload the jars individually, but for now this is good enough

Did you get 401 message in step " push to github packages with maven" ? 

When you try to deploy maven package in your workflow, you could use a specific settings.xml including your personal access token . You could store the PAT in secrets and use it as an environment variable value when run mvn deploy command. 

Please see my example here: 

name: deploy maven package
on: push
    runs-on: ubuntu-latest
    - uses: actions/checkout@v2
    - run: mvn deploy --settings settings.xml
        PackagePAT: ${{secrets.PackagePAT}}

In my repo, I have a settings.xml in the root . In servers section, I set ${env.PackagePAT} as the password. 

@jtratner How are things going now? Please check my previous reply, could specific settings.xml and pass PAT to it work for you ?      

1 Like

Hi @yanjingzhu,
Your settings.xml file worked for me indeed.

1 Like