1
- # Copyright 2020-2021 by Vegard IT GmbH, Germany, https://vegardit.com
1
+ # SPDX-FileCopyrightText: © Vegard IT GmbH (https://vegardit.com)
2
+ # SPDX-FileContributor: Sebastian Thomschke
2
3
# SPDX-License-Identifier: Apache-2.0
4
+ # SPDX-ArtifactOfProjectHomePage: https://github.com/vegardit/docker-graalvm-maven
3
5
#
4
- # Author: Sebastian Thomschke, Vegard IT GmbH
5
- #
6
- # https://github.com/vegardit/docker-graalvm-maven
7
- #
8
- # https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions
6
+ # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
9
7
name : Build
10
8
11
9
on :
12
10
push :
13
- branches :
11
+ branches : # build all branches
14
12
- ' **'
15
- tags-ignore :
13
+ tags-ignore : # but don't build tags
16
14
- ' **'
17
15
paths-ignore :
16
+ - ' **/*.adoc'
18
17
- ' **/*.md'
18
+ - ' .editorconfig'
19
+ - ' .git*'
20
+ - ' .github/*.yml'
21
+ - ' .github/workflows/stale.yml'
19
22
schedule :
20
23
# https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
21
- - cron : ' 0 0 * * *'
24
+ - cron : ' 0 4 * * */3' # At 04:00 on every 3rd day-of-week
25
+ pull_request :
22
26
workflow_dispatch :
23
27
# https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
28
+ inputs :
29
+ GRAALVM_VERSION :
30
+ description : ' GraalVM Version'
31
+ required : true
32
+ default : ' latest'
33
+
34
+ defaults :
35
+ run :
36
+ shell : bash
24
37
25
38
env :
26
39
DOCKER_IMAGE_REPO : vegardit/graalvm-maven
27
40
TRIVY_CACHE_DIR : ~/.trivy/cache
28
-
41
+
29
42
jobs :
30
43
build :
31
44
runs-on : ubuntu-latest
@@ -35,17 +48,34 @@ jobs:
35
48
fail-fast : false
36
49
matrix :
37
50
include :
38
- - GRAALVM_VERSION : release
51
+ # https://github.com/graalvm/graalvm-ce-builds/releases
52
+ - GRAALVM_VERSION : ${{ github.event.inputs.GRAALVM_VERSION || 'latest' }}
53
+ GRAALVM_JAVA_VERSION : 11
54
+ experimental : false
55
+ - GRAALVM_VERSION : ${{ github.event.inputs.GRAALVM_VERSION || 'latest' }}
56
+ GRAALVM_JAVA_VERSION : 17
39
57
experimental : false
40
- - GRAALVM_VERSION : latest
58
+ - GRAALVM_VERSION : ${{ github.event.inputs.GRAALVM_VERSION || 'latest' }}
59
+ GRAALVM_JAVA_VERSION : 21
60
+ experimental : false
61
+ - GRAALVM_VERSION : ${{ github.event.inputs.GRAALVM_VERSION || 'latest' }}
62
+ GRAALVM_JAVA_VERSION : 24
63
+ experimental : false
64
+ # https://github.com/graalvm/graalvm-ce-dev-builds/releases
65
+ - GRAALVM_VERSION : dev
66
+ GRAALVM_JAVA_VERSION : 25
41
67
experimental : true
42
68
43
69
steps :
70
+ - name : Show environment variables
71
+ run : env | sort
72
+
44
73
- name : Git Checkout
45
- uses : actions/checkout@v3 # https://github.com/actions/checkout
74
+ uses : actions/checkout@v4 # https://github.com/actions/checkout
46
75
47
76
- name : Cache trivy cache
48
- uses : actions/cache@v3
77
+ uses : actions/cache@v4
78
+ if : env.ACT != 'true' # https://github.com/nektos/act#skipping-steps
49
79
with :
50
80
path : ${{ env.TRIVY_CACHE_DIR }}
51
81
# https://github.com/actions/cache/issues/342#issuecomment-673371329
@@ -54,39 +84,40 @@ jobs:
54
84
${{ runner.os }}-trivy-
55
85
56
86
- name : Cache local Maven repository
57
- uses : actions/cache@v3
87
+ uses : actions/cache@v4
88
+ if : env.ACT != 'true' # https://github.com/nektos/act#skipping-steps
58
89
with :
59
90
path : /tmp/maven-repo
60
91
key : ${{ runner.os }}-mvnrepo-${{ hashFiles('example/pom.xml') }}
61
92
restore-keys : |
62
93
${{ runner.os }}-mvnrepo-
63
94
95
+ - name : Configure fast APT repository mirror
96
+ uses : vegardit/fast-apt-mirror.sh@v1
97
+
64
98
- name : Install dos2unix
65
- # using '-o Acquire::Retries=3' to workaround sporadic connectivity issues "Could not connect to azure.archive.ubuntu.com:80"
66
- # see https://github.com/actions/virtual-environments/issues/675
67
- run : sudo apt-get install -o Acquire::Retries=3 --no-install-recommends -y dos2unix
99
+ run : sudo apt-get install --no-install-recommends -y dos2unix
68
100
69
- - name : Build ${{ env.DOCKER_IMAGE_REPO }}:${{ matrix.GRAALVM_VERSION }}
70
- shell : bash
101
+ - name : Build ${{ env.DOCKER_IMAGE_REPO }}:${{ matrix.GRAALVM_VERSION }}-java${{ matrix.GRAALVM_JAVA_VERSION }}
71
102
env :
72
103
DOCKER_REGISTRY : docker.io
73
104
DOCKER_REGISTRY_USERNAME : ${{ secrets.DOCKER_HUB_USERNAME }}
74
105
DOCKER_REGISTRY_TOKEN : ${{ secrets.DOCKER_HUB_TOKEN }}
106
+ GITHUB_TOKEN : ${{ github.token }}
75
107
GRAALVM_VERSION : ${{ matrix.GRAALVM_VERSION }}
108
+ GRAALVM_JAVA_VERSION : ${{ matrix.GRAALVM_JAVA_VERSION }}
76
109
TRIVY_GITHUB_TOKEN : ${{ github.token }}
77
110
run : |
78
- if [ "$GITHUB_REF" == "refs/heads/main" ]; then
111
+ set -eu
112
+ if [[ $GITHUB_REF_NAME == "main" && $GITHUB_EVENT_NAME != "pull_request" && ${ACT:-} != "true" ]]; then
79
113
export DOCKER_PUSH=1
114
+ echo "$DOCKER_REGISTRY_TOKEN" | docker login -u="$DOCKER_REGISTRY_USERNAME" "$DOCKER_REGISTRY" --password-stdin
80
115
fi
81
- echo "$DOCKER_REGISTRY_TOKEN" | docker login -u="$DOCKER_REGISTRY_USERNAME" "$DOCKER_REGISTRY" --password-stdin
82
116
bash build-image.sh
83
117
84
- - name : Test ${{ env.DOCKER_IMAGE_REPO }}:${{ matrix.GRAALVM_VERSION }}
85
- shell : bash
86
- env :
87
- DOCKER_IMAGE : ${{ env.DOCKER_IMAGE_REPO }}:${{ matrix.GRAALVM_VERSION }}
118
+ - name : Test ${{ env.DOCKER_IMAGE_REPO }}:${{ matrix.GRAALVM_VERSION }}-java${{ matrix.GRAALVM_JAVA_VERSION }}
88
119
run : |
89
- docker run --rm -t vegardit/graalvm-maven:release /bin/bash -c "
120
+ docker run --rm -t ${{ env.DOCKER_IMAGE_REPO }}:${{ matrix.GRAALVM_VERSION }}-java${{ matrix.GRAALVM_JAVA_VERSION }} /bin/bash -c "
90
121
cd /tmp
91
122
echo 'class HelloWorld { public static void main(String[] args) { System.out.println(\"HelloWorld!\"); }}' > HelloWorld.java
92
123
javac HelloWorld.java
@@ -96,15 +127,46 @@ jobs:
96
127
./helloworld
97
128
98
129
# test static executable
99
- native-image --static HelloWorld
130
+ native-image HelloWorld
100
131
./helloworld
101
132
"
102
133
103
- - name : Test ${{ env.DOCKER_IMAGE_REPO }}:${{ matrix.GRAALVM_VERSION }} via Maven
104
- shell : bash
134
+ - name : Test ${{ env.DOCKER_IMAGE_REPO }}:${{ matrix.GRAALVM_VERSION }}-java${{ matrix.GRAALVM_JAVA_VERSION }} via Maven
105
135
env :
106
- DOCKER_IMAGE : ${{ env.DOCKER_IMAGE_REPO }}:${{ matrix.GRAALVM_VERSION }}
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
107
138
run : |
139
+ set -eux
108
140
bash example/tools/run-in-docker.sh mvn clean package
109
141
bash example/tools/run-in-docker.sh bash -c target/example
110
-
142
+
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
149
+
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
+
154
+ purge-untagged-images :
155
+ runs-on : ubuntu-latest
156
+ needs : [build]
157
+ steps :
158
+ - 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
161
+ 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
+ }
0 commit comments