-
Notifications
You must be signed in to change notification settings - Fork 24
82 lines (79 loc) · 2.35 KB
/
build_and_publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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