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]
TL;DR: Just commit the following to .github/workflows/mavenpublish.yml
and create a release via the GitHub web page to trigger the process:
name: Maven Package
on:
release:
types: [created]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- 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 -p ~/.m2
echo "gh $(echo "$GITHUB_REPOSITORY" | awk -F / '{print $1}') \${env.GITHUB_TOKEN} " > ~/.m2/settings.xml
REPO="gh::default::https://maven.pkg.github.com/${GITHUB_REPOSITORY}"
mvn deploy -DaltReleaseDeploymentRepository="${REPO}" -DaltSnapshotDeploymentRepository="${REPO}"
Some more info:
I have built the same thing before for Jenkins and can tell you that you don't need to create a settings.xml
nor adapt your pom.xml
in your repo.
You can even avoid writing your GitHub Token into the settings.xml
(which is more secure).
Also, you don't need to manually add your repo and username, these can be read from the environment.
If you want it to build on push, just change the lines behind on:
to [push]
.
Here`s a real-life example.