-
Notifications
You must be signed in to change notification settings - Fork 8
90 lines (76 loc) · 2.36 KB
/
java-build.yaml
File metadata and controls
90 lines (76 loc) · 2.36 KB
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
83
84
85
86
87
88
89
90
name: Build and Deploy Java
permissions:
id-token: write
contents: read
packages: write
pull-requests: write
on:
workflow_dispatch:
inputs:
version:
description: 'Version string for the build'
required: true
default: '1.0.0-SNAPSHOT'
type: string
build_and_deploy:
description: 'Build and deploy Docker image (false = build only)'
required: true
default: false
type: boolean
jobs:
build:
runs-on: self-hosted
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
cache: 'maven'
- name: Set up Maven
uses: stCarolas/setup-maven@v5
with:
maven-version: 3.9.9
- name: Build with Maven
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_ACTOR: ${{ github.actor }}
run: |
mvn clean test package deploy \
-s .mvn/settings.xml \
-Dproject.version=${{ inputs.version }}
- name: Upload JAR artifact
uses: actions/upload-artifact@v4
with:
name: hello-world-jar
path: target/hello-world-${{ inputs.version }}.jar
build-and-push-docker:
runs-on: ubuntu-latest
needs: build
if: ${{ inputs.build_and_deploy == true }}
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download JAR artifact
uses: actions/download-artifact@v4
with:
name: hello-world-jar
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
run: |
docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ inputs.version }} .
docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest .
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ inputs.version }}
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest