3
3
# SPDX-License-Identifier: Apache-2.0
4
4
# SPDX-ArtifactOfProjectHomePage: https://github.com/vegardit/docker-graalvm-maven
5
5
#
6
- # https://docs.github.com/en/actions/using -workflows/workflow-syntax-for-github-actions
6
+ # https://docs.github.com/en/actions/writing -workflows/workflow-syntax-for-github-actions
7
7
name : Build
8
8
9
9
on :
10
10
push :
11
- branches : # build all branches
12
- - ' **'
13
- tags-ignore : # but don't build tags
11
+ branches-ignore : # build all branches except:
12
+ - ' dependabot/ **' # prevent GHA triggered twice (once for commit to the branch and once for opening/syncing the PR)
13
+ tags-ignore : # don't build tags
14
14
- ' **'
15
15
paths-ignore :
16
- - ' **/*.adoc'
17
16
- ' **/*.md'
18
17
- ' .editorconfig'
19
18
- ' .git*'
20
19
- ' .github/*.yml'
21
20
- ' .github/workflows/stale.yml'
22
- schedule :
23
- # https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
24
- - cron : ' 0 4 * * */3' # At 04:00 on every 3rd day-of-week
25
21
pull_request :
22
+ paths-ignore :
23
+ - ' **/*.md'
24
+ - ' .editorconfig'
25
+ - ' .git*'
26
+ - ' .github/*.yml'
27
+ - ' .github/workflows/stale.yml'
28
+ schedule :
29
+ # https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows
30
+ - cron : ' 0 17 * * 3'
26
31
workflow_dispatch :
27
- # https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with- workflow_dispatch/
32
+ # https://docs. github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows# workflow_dispatch
28
33
inputs :
29
34
GRAALVM_VERSION :
30
35
description : ' GraalVM Version'
@@ -36,14 +41,21 @@ defaults:
36
41
shell : bash
37
42
38
43
env :
39
- DOCKER_IMAGE_REPO : vegardit/ graalvm-maven
44
+ DOCKER_REPO_NAME : graalvm-maven
40
45
TRIVY_CACHE_DIR : ~/.trivy/cache
41
46
42
47
jobs :
48
+
49
+ # ##########################################################
43
50
build :
44
- runs-on : ubuntu-latest
51
+ # ##########################################################
52
+ runs-on : ubuntu-latest # https://github.com/actions/runner-images#available-images
53
+ timeout-minutes : 20
45
54
continue-on-error : ${{ matrix.experimental }}
46
55
56
+ permissions :
57
+ packages : write
58
+
47
59
strategy :
48
60
fail-fast : false
49
61
matrix :
@@ -67,22 +79,47 @@ jobs:
67
79
experimental : true
68
80
69
81
steps :
70
- - name : Show environment variables
82
+ - name : " Show: GitHub context"
83
+ env :
84
+ GITHUB_CONTEXT : ${{ toJSON(github) }}
85
+ run : echo $GITHUB_CONTEXT
86
+
87
+
88
+ - name : " Show: environment variables"
71
89
run : env | sort
72
90
91
+
73
92
- name : Git Checkout
74
- uses : actions/checkout@v4 # https://github.com/actions/checkout
93
+ uses : actions/checkout@v4 # https://github.com/actions/checkout
94
+
95
+
96
+ - name : Run the sh-checker
97
+ uses : luizm/action-sh-checker@master # https://github.com/marketplace/actions/sh-checker
98
+ env :
99
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
100
+ SHFMT_OPTS : --simplify --keep-padding
101
+ with :
102
+ sh_checker_comment : true
103
+ sh_checker_checkbashisms_enable : true
104
+ sh_checker_shfmt_disable : true
105
+
106
+
107
+ - name : Check Dockerfile
108
+
109
+ with :
110
+ dockerfile : image/Dockerfile
111
+
75
112
76
113
- name : Cache trivy cache
77
114
uses : actions/cache@v4
78
- if : env.ACT != 'true' # https://github.com/nektos/act#skipping-steps
79
115
with :
80
116
path : ${{ env.TRIVY_CACHE_DIR }}
81
117
# https://github.com/actions/cache/issues/342#issuecomment-673371329
82
118
key : ${{ runner.os }}-trivy-${{ github.run_id }}
83
119
restore-keys : |
84
120
${{ runner.os }}-trivy-
85
121
122
+
86
123
- name : Cache local Maven repository
87
124
uses : actions/cache@v4
88
125
if : env.ACT != 'true' # https://github.com/nektos/act#skipping-steps
@@ -92,32 +129,60 @@ jobs:
92
129
restore-keys : |
93
130
${{ runner.os }}-mvnrepo-
94
131
132
+
95
133
- name : Configure fast APT repository mirror
96
134
uses : vegardit/fast-apt-mirror.sh@v1
97
135
136
+
98
137
- name : Install dos2unix
99
138
run : sudo apt-get install --no-install-recommends -y dos2unix
100
139
101
- - name : Build ${{ env.DOCKER_IMAGE_REPO }}:${{ matrix.GRAALVM_VERSION }}-java${{ matrix.GRAALVM_JAVA_VERSION }}
140
+
141
+ - name : " Determine if docker images shall be published"
142
+ id : docker_push_actions
143
+ run : |
144
+ # ACT -> https://nektosact.com/usage/index.html#skipping-steps
145
+ set -x
146
+ if [[ $GITHUB_REF_NAME == 'main' && $GITHUB_EVENT_NAME != 'pull_request' && -z "$ACT" ]]; then
147
+ echo "DOCKER_PUSH_GHCR=true" >> "$GITHUB_ENV"
148
+ echo "DOCKER_PUSH_GHCR=true" >> $GITHUB_OUTPUT
149
+ if [[ -n "${{ secrets.DOCKER_HUB_USERNAME }}" ]]; then
150
+ echo "DOCKER_PUSH=true" >> "$GITHUB_ENV"
151
+ fi
152
+ fi
153
+
154
+
155
+ - name : Login to docker.io
156
+ if : ${{ env.DOCKER_PUSH }}
157
+ uses : docker/login-action@v3
158
+ with :
159
+ username : ${{ secrets.DOCKER_HUB_USERNAME }}
160
+ password : ${{ secrets.DOCKER_HUB_TOKEN }}
161
+
162
+
163
+ - name : Login to ghcr.io
164
+ if : ${{ env.DOCKER_PUSH_GHCR }}
165
+ uses : docker/login-action@v3
166
+ with :
167
+ registry : ghcr.io
168
+ username : ${{ github.actor }}
169
+ password : ${{ secrets.GITHUB_TOKEN }}
170
+
171
+
172
+ - name : Build ${{ env.DOCKER_REPO_NAME }}:${{ matrix.GRAALVM_VERSION }}-java${{ matrix.GRAALVM_JAVA_VERSION }}
102
173
env :
103
- DOCKER_REGISTRY : docker.io
104
- DOCKER_REGISTRY_USERNAME : ${{ secrets.DOCKER_HUB_USERNAME }}
105
- DOCKER_REGISTRY_TOKEN : ${{ secrets.DOCKER_HUB_TOKEN }}
106
- GITHUB_TOKEN : ${{ github.token }}
174
+ DOCKER_BASE_IMAGE : ghcr.io/dockerhub-mirror/debian:stable-slim
175
+ DOCKER_IMAGE_REPO : ${{ github.repository_owner }}/${{ env.DOCKER_REPO_NAME }}
176
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
107
177
GRAALVM_VERSION : ${{ matrix.GRAALVM_VERSION }}
108
178
GRAALVM_JAVA_VERSION : ${{ matrix.GRAALVM_JAVA_VERSION }}
109
- TRIVY_GITHUB_TOKEN : ${{ github.token }}
110
- run : |
111
- set -eu
112
- if [[ $GITHUB_REF_NAME == "main" && $GITHUB_EVENT_NAME != "pull_request" && ${ACT:-} != "true" ]]; then
113
- export DOCKER_PUSH=1
114
- echo "$DOCKER_REGISTRY_TOKEN" | docker login -u="$DOCKER_REGISTRY_USERNAME" "$DOCKER_REGISTRY" --password-stdin
115
- fi
116
- bash build-image.sh
179
+ TRIVY_GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
180
+ run : bash build-image.sh
181
+
117
182
118
- - name : Test ${{ env.DOCKER_IMAGE_REPO }}:${{ matrix.GRAALVM_VERSION }}-java${{ matrix.GRAALVM_JAVA_VERSION }}
183
+ - name : Test ${{ env.DOCKER_REPO_NAME }}:${{ matrix.GRAALVM_VERSION }}-java${{ matrix.GRAALVM_JAVA_VERSION }}
119
184
run : |
120
- docker run --rm -t ${{ env.DOCKER_IMAGE_REPO }}:${{ matrix.GRAALVM_VERSION }}-java${{ matrix.GRAALVM_JAVA_VERSION }} /bin/bash -c "
185
+ docker run --rm -t ${{ github.repository_owner }}/${{ env.DOCKER_REPO_NAME }}:${{ matrix.GRAALVM_VERSION }}-java${{ matrix.GRAALVM_JAVA_VERSION }} /bin/bash -c "
121
186
cd /tmp
122
187
echo 'class HelloWorld { public static void main(String[] args) { System.out.println(\"HelloWorld!\"); }}' > HelloWorld.java
123
188
javac HelloWorld.java
@@ -131,42 +196,40 @@ jobs:
131
196
./helloworld
132
197
"
133
198
134
- - name : Test ${{ env.DOCKER_IMAGE_REPO }}:${{ matrix.GRAALVM_VERSION }}-java${{ matrix.GRAALVM_JAVA_VERSION }} via Maven
199
+ - name : Test ${{ env.DOCKER_REPO_NAME }}:${{ matrix.GRAALVM_VERSION }}-java${{ matrix.GRAALVM_JAVA_VERSION }} via Maven
135
200
env :
136
- RUN_IN_DOCKER_IMAGE : ${{ env.DOCKER_IMAGE_REPO }}:${{ matrix.GRAALVM_VERSION }}-java${{ matrix.GRAALVM_JAVA_VERSION }}
137
- if : ${{ !env.ACT }} # https://github.com/nektos/act#skipping-steps
201
+ RUN_IN_DOCKER_IMAGE : ${{ github.repository_owner }}/${{ env.DOCKER_REPO_NAME }}:${{ matrix.GRAALVM_VERSION }}-java${{ matrix.GRAALVM_JAVA_VERSION }}
138
202
run : |
139
203
set -eux
140
204
bash example/tools/run-in-docker.sh mvn clean package
141
205
bash example/tools/run-in-docker.sh bash -c target/example
142
206
143
- - name : Publish Docker image to GH registry
144
- if : ${{ github.ref_name == 'main' && github.event_name != 'pull_request' && !env.ACT }} # https://github.com/nektos/act#skipping-steps
145
- run : |
146
- set -eux
147
-
148
- echo "${{ github.token }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin
207
+ outputs :
208
+ DOCKER_PUSH_GHCR : ${{ steps.docker_push_actions.outputs.DOCKER_PUSH_GHCR }}
149
209
150
- image_name="$DOCKER_IMAGE_REPO:${{ matrix.GRAALVM_VERSION }}-java${{ matrix.GRAALVM_JAVA_VERSION }}"
151
- docker image tag $image_name ghcr.io/$image_name
152
- docker push ghcr.io/$image_name
153
210
154
- purge-untagged-images :
155
- runs-on : ubuntu-latest
211
+ # ##########################################################
212
+ delete-untagged-images :
213
+ # ##########################################################
214
+ runs-on : ubuntu-latest # https://github.com/actions/runner-images#available-images
215
+ timeout-minutes : 5
156
216
needs : [build]
217
+ if : ${{ needs.build.outputs.DOCKER_PUSH_GHCR }}
218
+
219
+ concurrency :
220
+ group : ${{ github.workflow }}
221
+ cancel-in-progress : false
222
+
223
+ permissions :
224
+ packages : write
225
+
157
226
steps :
158
227
- name : Delete untagged images
159
- uses : actions/github-script@v7
160
- if : ${{ github.ref_name == 'main' && github.event_name != 'pull_request' && !env.ACT }} # https://github.com/nektos/act#skipping-steps
228
+ uses : dataaxiom/ghcr-cleanup-action@v1
161
229
with :
162
- github-token : ${{ secrets.GHA_DELETE_PACKAGES }}
163
- script : |
164
- const imageName = /[^/]*$/.exec(process.env.DOCKER_IMAGE_REPO)[0]
165
- const basePath = `/orgs/${{ github.repository_owner }}/packages/container/${imageName}/versions`
166
- for (version of (await github.request(`GET ${basePath}`, { per_page: 100 })).data) {
167
- if (version.metadata.container.tags.length == 0) {
168
- console.log(`deleting ${version.name}...`)
169
- const delResponse = await github.request(`DELETE ${basePath}/${version.id}`)
170
- console.log(`status: ${delResponse.status}`)
171
- }
172
- }
230
+ package : ${{ env.DOCKER_REPO_NAME }}
231
+ delete-untagged : true
232
+ delete-partial-images : true
233
+ delete-ghost-images : true
234
+ delete-orphaned-images : true
235
+ validate : true
0 commit comments