-
Notifications
You must be signed in to change notification settings - Fork 7
172 lines (152 loc) · 6.51 KB
/
build.yml
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
# SPDX-FileCopyrightText: © Vegard IT GmbH (https://vegardit.com)
# SPDX-FileContributor: Sebastian Thomschke
# SPDX-License-Identifier: Apache-2.0
# SPDX-ArtifactOfProjectHomePage: https://github.com/vegardit/docker-graalvm-maven
#
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
name: Build
on:
push:
branches: # build all branches
- '**'
tags-ignore: # but don't build tags
- '**'
paths-ignore:
- '**/*.adoc'
- '**/*.md'
- '.editorconfig'
- '.git*'
- '.github/*.yml'
- '.github/workflows/stale.yml'
schedule:
# https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows
- cron: '0 4 * * */3' # At 04:00 on every 3rd day-of-week
pull_request:
workflow_dispatch:
# https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
inputs:
GRAALVM_VERSION:
description: 'GraalVM Version'
required: true
default: 'latest'
defaults:
run:
shell: bash
env:
DOCKER_IMAGE_REPO: vegardit/graalvm-maven
TRIVY_CACHE_DIR: ~/.trivy/cache
jobs:
build:
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
include:
# https://github.com/graalvm/graalvm-ce-builds/releases
- GRAALVM_VERSION: ${{ github.event.inputs.GRAALVM_VERSION || 'latest' }}
GRAALVM_JAVA_VERSION: 11
experimental: false
- GRAALVM_VERSION: ${{ github.event.inputs.GRAALVM_VERSION || 'latest' }}
GRAALVM_JAVA_VERSION: 17
experimental: false
- GRAALVM_VERSION: ${{ github.event.inputs.GRAALVM_VERSION || 'latest' }}
GRAALVM_JAVA_VERSION: 21
experimental: false
- GRAALVM_VERSION: ${{ github.event.inputs.GRAALVM_VERSION || 'latest' }}
GRAALVM_JAVA_VERSION: 22
experimental: false
# https://github.com/graalvm/graalvm-ce-dev-builds/releases
- GRAALVM_VERSION: dev
GRAALVM_JAVA_VERSION: 23
experimental: true
steps:
- name: Show environment variables
run: env | sort
- name: Git Checkout
uses: actions/checkout@v4 #https://github.com/actions/checkout
- name: Cache trivy cache
uses: actions/cache@v4
if: env.ACT != 'true' # https://github.com/nektos/act#skipping-steps
with:
path: ${{ env.TRIVY_CACHE_DIR }}
# https://github.com/actions/cache/issues/342#issuecomment-673371329
key: ${{ runner.os }}-trivy-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-trivy-
- name: Cache local Maven repository
uses: actions/cache@v4
if: env.ACT != 'true' # https://github.com/nektos/act#skipping-steps
with:
path: /tmp/maven-repo
key: ${{ runner.os }}-mvnrepo-${{ hashFiles('example/pom.xml') }}
restore-keys: |
${{ runner.os }}-mvnrepo-
- name: Configure fast APT repository mirror
uses: vegardit/fast-apt-mirror.sh@v1
- name: Install dos2unix
run: sudo apt-get install --no-install-recommends -y dos2unix
- name: Build ${{ env.DOCKER_IMAGE_REPO }}:${{ matrix.GRAALVM_VERSION }}-java${{ matrix.GRAALVM_JAVA_VERSION }}
env:
DOCKER_REGISTRY: docker.io
DOCKER_REGISTRY_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_REGISTRY_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
GITHUB_TOKEN: ${{ github.token }}
GRAALVM_VERSION: ${{ matrix.GRAALVM_VERSION }}
GRAALVM_JAVA_VERSION: ${{ matrix.GRAALVM_JAVA_VERSION }}
TRIVY_GITHUB_TOKEN: ${{ github.token }}
run: |
set -eu
if [[ $GITHUB_REF_NAME == "main" && $GITHUB_EVENT_NAME != "pull_request" && ${ACT:-} != "true" ]]; then
export DOCKER_PUSH=1
echo "$DOCKER_REGISTRY_TOKEN" | docker login -u="$DOCKER_REGISTRY_USERNAME" "$DOCKER_REGISTRY" --password-stdin
fi
bash build-image.sh
- name: Test ${{ env.DOCKER_IMAGE_REPO }}:${{ matrix.GRAALVM_VERSION }}-java${{ matrix.GRAALVM_JAVA_VERSION }}
run: |
docker run --rm -t ${{ env.DOCKER_IMAGE_REPO }}:${{ matrix.GRAALVM_VERSION }}-java${{ matrix.GRAALVM_JAVA_VERSION }} /bin/bash -c "
cd /tmp
echo 'class HelloWorld { public static void main(String[] args) { System.out.println(\"HelloWorld!\"); }}' > HelloWorld.java
javac HelloWorld.java
# test dynamic executable
native-image HelloWorld
./helloworld
# test static executable
native-image HelloWorld
./helloworld
"
- name: Test ${{ env.DOCKER_IMAGE_REPO }}:${{ matrix.GRAALVM_VERSION }}-java${{ matrix.GRAALVM_JAVA_VERSION }} via Maven
env:
RUN_IN_DOCKER_IMAGE: ${{ env.DOCKER_IMAGE_REPO }}:${{ matrix.GRAALVM_VERSION }}-java${{ matrix.GRAALVM_JAVA_VERSION }}
if: ${{ !env.ACT }} # https://github.com/nektos/act#skipping-steps
run: |
set -eux
bash example/tools/run-in-docker.sh mvn clean package
bash example/tools/run-in-docker.sh bash -c target/example
- name: Publish Docker image to GH registry
if: ${{ github.ref_name == 'main' && github.event_name != 'pull_request' && !env.ACT }} # https://github.com/nektos/act#skipping-steps
run: |
set -eux
echo "${{ github.token }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin
image_name="$DOCKER_IMAGE_REPO:${{ matrix.GRAALVM_VERSION }}-java${{ matrix.GRAALVM_JAVA_VERSION }}"
docker image tag $image_name ghcr.io/$image_name
docker push ghcr.io/$image_name
purge-untagged-images:
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Delete untagged images
uses: actions/github-script@v7
if: ${{ github.ref_name == 'main' && github.event_name != 'pull_request' && !env.ACT }} # https://github.com/nektos/act#skipping-steps
with:
github-token: ${{ secrets.GHA_DELETE_PACKAGES }}
script: |
const imageName = /[^/]*$/.exec(process.env.DOCKER_IMAGE_REPO)[0]
const basePath = `/orgs/${{ github.repository_owner }}/packages/container/${imageName}/versions`
for (version of (await github.request(`GET ${basePath}`, { per_page: 100 })).data) {
if (version.metadata.container.tags.length == 0) {
console.log(`deleting ${version.name}...`)
const delResponse = await github.request(`DELETE ${basePath}/${version.id}`)
console.log(`status: ${delResponse.status}`)
}
}