-
Notifications
You must be signed in to change notification settings - Fork 0
176 lines (147 loc) · 4.51 KB
/
build.yaml
File metadata and controls
176 lines (147 loc) · 4.51 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
name: Build Cupcake
on:
push:
branches:
- main
tags-ignore:
- '**'
workflow_dispatch:
permissions:
contents: read
packages: write
jobs:
meta:
runs-on: ubuntu-latest
outputs:
short_sha_tag: ${{ steps.short_sha.outputs.short_sha_tag }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
steps:
- uses: actions/checkout@v6
- id: short_sha
name: Compute short-sha tag
run: echo "short_sha_tag=sha-${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
- id: meta
name: Docker metadata
uses: docker/metadata-action@v6
with:
images: ghcr.io/javabin/cupcake
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha,format=short
type=raw,value=latest,enable={{is_default_branch}}
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up JDK
uses: actions/setup-java@v5
with:
java-version: '22'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v6
- name: Test
run: ./gradlew clean check
- name: Upload reports if failed
if: failure()
uses: actions/upload-artifact@v7
with:
name: reports
path: |
**/build/reports/
**/build/test-results/
- name: Upload coverage if passed
if: success()
uses: actions/upload-artifact@v7
with:
name: coverage
path: |
**/build/reports/jacoco/
build-amd64:
runs-on: ubuntu-latest
needs: [meta, test]
env:
IMAGE_BASE: ghcr.io/javabin/cupcake
SHORT_SHA_TAG: ${{ needs.meta.outputs.short_sha_tag }}
steps:
- uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Login to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Build and push (amd64)
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/amd64
push: true
tags: ${{ env.IMAGE_BASE }}:${{ env.SHORT_SHA_TAG }}-amd64
cache-from: type=gha,scope=amd64
cache-to: type=gha,mode=max,scope=amd64
build-arm64:
runs-on: ubuntu-24.04-arm
needs: [meta, test]
env:
IMAGE_BASE: ghcr.io/javabin/cupcake
SHORT_SHA_TAG: ${{ needs.meta.outputs.short_sha_tag }}
steps:
- uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Login to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Build and push (arm64)
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/arm64
push: true
tags: ${{ env.IMAGE_BASE }}:${{ env.SHORT_SHA_TAG }}-arm64
cache-from: type=gha,scope=arm64
cache-to: type=gha,mode=max,scope=arm64
manifest:
runs-on: ubuntu-latest
needs: [meta, build-amd64, build-arm64]
env:
IMAGE_BASE: ghcr.io/javabin/cupcake
SHORT_SHA_TAG: ${{ needs.meta.outputs.short_sha_tag }}
TAGS: ${{ needs.meta.outputs.tags }}
LABELS: ${{ needs.meta.outputs.labels }}
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Login to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Create multi-arch manifests for all tags
run: |
while IFS= read -r tag; do
[ -z "$tag" ] && continue
docker buildx imagetools create \
-t "$tag" \
"${IMAGE_BASE}:${SHORT_SHA_TAG}-amd64" \
"${IMAGE_BASE}:${SHORT_SHA_TAG}-arm64"
done <<< "${TAGS}"
- name: Create staging
if: github.ref == 'refs/heads/main'
run: |
docker buildx imagetools create \
--tag "${IMAGE_BASE}:staging" \
"${IMAGE_BASE}:latest"
- name: Generate summary
run: |
echo "Short SHA Tag: ${SHORT_SHA_TAG}" >> "$GITHUB_STEP_SUMMARY"
echo "Image base: ${IMAGE_BASE}" >> "$GITHUB_STEP_SUMMARY"