Skip to content

Trigger workflow on tag #34

Trigger workflow on tag

Trigger workflow on tag #34

name: Build and publish
on:
push:
branches:
- master
tags:
- 'v*'
env:
REGISTRY: ghcr.io
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache Target
id: cache-target
uses: actions/cache@v4
with:
path: target/
key: maven-target-${{ github.run_id }}-${{ github.run_number }}
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
- name: Build with Maven
run: mvn -B package --file pom.xml
publish_maven:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Restore cached Target
id: cache-primes-restore
uses: actions/cache/restore@v4
with:
path: target/
key: maven-target-${{ github.run_id }}-${{ github.run_number }}
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
- name: Publish to GitHub Packages Apache Maven
run: mvn deploy
env:
GITHUB_TOKEN: ${{ github.token }} # GITHUB_TOKEN is the default env for the password
publish_container:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Restore cached Target
id: cache-primes-restore
uses: actions/cache/restore@v4
with:
path: target/
key: maven-target-${{ github.run_id }}-${{ github.run_number }}
- uses: docker/metadata-action@v3
id: metadata
with:
images: ghcr.io/${{ github.repository }}
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push the container image
uses: int128/kaniko-action@v1
with:
push: true
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
cache: true
cache-repository: ghcr.io/${{ github.repository }}/cache