-
Notifications
You must be signed in to change notification settings - Fork 6
118 lines (101 loc) · 3.06 KB
/
Copy pathbuild-test-container.yml
File metadata and controls
118 lines (101 loc) · 3.06 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: Build, Test and Publish Container
on:
pull_request:
branches:
- main
push:
branches:
- main
workflow_dispatch:
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: erhardtconsulting/database-development-app
jobs:
maven:
name: Maven build and root tests
runs-on: ubuntu-24.04
outputs:
app-version: ${{ steps.project-version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Java 24
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "24"
cache: maven
- name: Read project version
id: project-version
run: echo "version=$(./mvnw -q -DforceStdout help:evaluate -Dexpression=project.version)" >> "$GITHUB_OUTPUT"
- name: Run fast tests
run: ./mvnw -B test
- name: Run Testcontainers integration tests
run: ./mvnw -B -Ptestcontainers test
- name: Build application package
run: ./mvnw -B package -DskipTests
checkpoint-states:
name: Checkpoint state / ${{ matrix.state }}
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
state:
- block-2-start
- block-2-complete
- block-3-start
- block-3-complete
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Java 24
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "24"
cache: maven
- name: Test checkpoint state
run: ./course-state test "${{ matrix.state }}"
container:
name: Container build and publish
runs-on: ubuntu-24.04
needs:
- maven
- checkpoint-states
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare image tags
id: image-tags
run: |
SHORT_SHA="${GITHUB_SHA::7}"
VERSION="${{ needs.maven.outputs.app-version }}"
IMAGE="${REGISTRY}/${IMAGE_NAME}"
{
echo "tags<<EOF"
echo "${IMAGE}:${VERSION}-${SHORT_SHA}"
if [ "${GITHUB_EVENT_NAME}" = "push" ] && [ "${GITHUB_REF}" = "refs/heads/main" ]; then
echo "${IMAGE}:latest"
fi
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Build container image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
platforms: linux/amd64
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
tags: ${{ steps.image-tags.outputs.tags }}