Skip to content

Commit

Permalink
Rearrange workflow into separate jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
ullgren committed Jul 13, 2024
1 parent 59b3778 commit 6188f5f
Showing 1 changed file with 41 additions and 11 deletions.
52 changes: 41 additions & 11 deletions .github/workflows/build_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,65 @@ env:

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 }}
- 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 }}
- 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 }}
- 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@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push the Docker image
run: |
docker build . --file Dockerfile --tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest --tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${GITHUB_REF##*/}
docker push -a ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- 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

0 comments on commit 6188f5f

Please sign in to comment.