Skip to content

Commit cc6ce7f

Browse files
committed
build: improve build config
1 parent 349ee80 commit cc6ce7f

File tree

16 files changed

+450
-281
lines changed

16 files changed

+450
-281
lines changed

.dockerignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
*.md
22
*.txt
3+
.actrc
4+
.dockerignore
5+
.editorconfig
6+
.gitattributes
7+
.gitignore
38
.github/
49
.shared/.*
510
.shared/*.md
611
.shared/*.txt
7-
example
12+
example
13+
image/Dockerfile

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ end_of_line = lf
99
insert_final_newline = true
1010
trim_trailing_whitespace = true
1111
indent_style = space
12-
indent_size = 3
12+
indent_size = 2
1313

1414
[*.{bat,cmd}]
1515
end_of_line = crlf

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
*.php text
6161
*.python text
6262
*.sql text
63+
**/Dockerfile text eol=lf
64+
**/*.Dockerfile text eol=lf
6365

6466

6567
# Archives

.github/dependabot.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
1+
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/dependabot-options-reference
22
version: 2
33
updates:
4-
- package-ecosystem: github-actions
5-
directory: /
6-
schedule:
7-
interval: weekly
8-
day: monday
9-
time: "09:00"
10-
commit-message:
11-
prefix: fix
12-
prefix-development: chore
13-
include: scope
14-
labels:
15-
- pinned
16-
- dependencies
17-
- gha
4+
- package-ecosystem: github-actions
5+
directory: /
6+
schedule:
7+
interval: weekly
8+
day: monday
9+
time: "14:00"
10+
commit-message:
11+
prefix: ci
12+
prefix-development: ci
13+
include: scope
14+
labels:
15+
- dependencies
16+
- gha
17+
- pinned

.github/workflows/build.yml

Lines changed: 119 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,33 @@
33
# SPDX-License-Identifier: Apache-2.0
44
# SPDX-ArtifactOfProjectHomePage: https://github.com/vegardit/docker-graalvm-maven
55
#
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
77
name: Build
88

99
on:
1010
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
1414
- '**'
1515
paths-ignore:
16-
- '**/*.adoc'
1716
- '**/*.md'
1817
- '.editorconfig'
1918
- '.git*'
2019
- '.github/*.yml'
2120
- '.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
2521
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'
2631
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
2833
inputs:
2934
GRAALVM_VERSION:
3035
description: 'GraalVM Version'
@@ -36,14 +41,21 @@ defaults:
3641
shell: bash
3742

3843
env:
39-
DOCKER_IMAGE_REPO: vegardit/graalvm-maven
44+
DOCKER_REPO_NAME: graalvm-maven
4045
TRIVY_CACHE_DIR: ~/.trivy/cache
4146

4247
jobs:
48+
49+
###########################################################
4350
build:
44-
runs-on: ubuntu-latest
51+
###########################################################
52+
runs-on: ubuntu-latest # https://github.com/actions/runner-images#available-images
53+
timeout-minutes: 20
4554
continue-on-error: ${{ matrix.experimental }}
4655

56+
permissions:
57+
packages: write
58+
4759
strategy:
4860
fail-fast: false
4961
matrix:
@@ -67,22 +79,47 @@ jobs:
6779
experimental: true
6880

6981
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"
7189
run: env | sort
7290

91+
7392
- 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+
uses: hadolint/[email protected]
109+
with:
110+
dockerfile: image/Dockerfile
111+
75112

76113
- name: Cache trivy cache
77114
uses: actions/cache@v4
78-
if: env.ACT != 'true' # https://github.com/nektos/act#skipping-steps
79115
with:
80116
path: ${{ env.TRIVY_CACHE_DIR }}
81117
# https://github.com/actions/cache/issues/342#issuecomment-673371329
82118
key: ${{ runner.os }}-trivy-${{ github.run_id }}
83119
restore-keys: |
84120
${{ runner.os }}-trivy-
85121
122+
86123
- name: Cache local Maven repository
87124
uses: actions/cache@v4
88125
if: env.ACT != 'true' # https://github.com/nektos/act#skipping-steps
@@ -92,32 +129,60 @@ jobs:
92129
restore-keys: |
93130
${{ runner.os }}-mvnrepo-
94131
132+
95133
- name: Configure fast APT repository mirror
96134
uses: vegardit/fast-apt-mirror.sh@v1
97135

136+
98137
- name: Install dos2unix
99138
run: sudo apt-get install --no-install-recommends -y dos2unix
100139

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 }}
102173
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 }}
107177
GRAALVM_VERSION: ${{ matrix.GRAALVM_VERSION }}
108178
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+
117182

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 }}
119184
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 "
121186
cd /tmp
122187
echo 'class HelloWorld { public static void main(String[] args) { System.out.println(\"HelloWorld!\"); }}' > HelloWorld.java
123188
javac HelloWorld.java
@@ -131,42 +196,40 @@ jobs:
131196
./helloworld
132197
"
133198
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
135200
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 }}
138202
run: |
139203
set -eux
140204
bash example/tools/run-in-docker.sh mvn clean package
141205
bash example/tools/run-in-docker.sh bash -c target/example
142206
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 }}
149209

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
153210

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
156216
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+
157226
steps:
158227
- 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
161229
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

.github/workflows/stale.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
# SPDX-FileCopyrightText: © Sebastian Thomschke and contributors
2-
# SPDX-License-Identifier: AGPL-3.0-or-later
3-
# SPDX-ArtifactOfProjectHomePage: https://github.com/Second-Hand-Friends/kleinanzeigen-bot/
4-
#
5-
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
1+
# https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions
62
name: Stale issues
73

84
on:
95
schedule:
10-
- cron: '0 16 * * *'
6+
- cron: '0 16 * * 1'
117
workflow_dispatch:
128
# https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
139

1410
permissions:
15-
contents: write # only for delete-branch option
1611
issues: write
1712
pull-requests: write
1813

@@ -42,7 +37,7 @@ jobs:
4237
pinned
4338
security
4439
45-
- name: Run stale action
40+
- name: Run stale action (for enhancements)
4641
uses: actions/stale@v9 # https://github.com/actions/stale
4742
with:
4843
repo-token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ bin/
1414
**/.*.md.html
1515

1616
# IntelliJ
17-
.idea
18-
*.iml
19-
*.ipr
20-
*.iws
17+
/.idea
18+
/*.iml
19+
/*.ipr
20+
/*.iws
2121

2222
# NetBeans
2323
nb-configuration.xml
2424

2525
# Visual Studio Code
26-
.vscode
26+
/.vscode
2727

2828
# OSX
2929
.DS_Store
@@ -35,3 +35,6 @@ nb-configuration.xml
3535
# patch
3636
*.orig
3737
*.rej
38+
39+
# nektos/act
40+
.actrc

.trivyignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)