-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (90 loc) · 3.12 KB
/
Copy pathdocker-image.yml
File metadata and controls
100 lines (90 loc) · 3.12 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
name: Build and publish container
on:
pull_request:
push:
branches: [main]
release:
types: [published]
workflow_dispatch:
permissions:
contents: read
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Java
uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5
with:
distribution: temurin
java-version: '25'
cache: gradle
- name: Run tests
run: sh ./gradlew --no-daemon check
image:
needs: test
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
artifact-metadata: write
id-token: write
steps:
- name: Check out the repo
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- name: Log in to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract image metadata
id: meta
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
with:
images: ghcr.io/nextinfinity/infinitybot
flavor: latest=false
tags: |
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
type=sha
type=raw,value=latest,enable=${{ github.event_name == 'release' && !github.event.release.prerelease }}
- name: Determine application version
id: version
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
version=0.0.0-SNAPSHOT
if [[ "$GITHUB_EVENT_NAME" == "release" ]]; then
version="${RELEASE_TAG#v}"
fi
if [[ ! "$version" =~ ^[0-9A-Za-z][0-9A-Za-z.+_-]*$ ]]; then
echo "Invalid application version in release tag" >&2
exit 1
fi
printf 'app_version=%s\n' "$version" >> "$GITHUB_OUTPUT"
- name: Build and optionally push image
id: push
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
context: .
build-args: |
APP_VERSION=${{ steps.version.outputs.app_version }}
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Attest published image
if: github.event_name != 'pull_request'
uses: actions/attest-build-provenance@4d101475d8b20a2381f78447822ac1eab6504dd8 # v4.2.2
with:
subject-name: ghcr.io/nextinfinity/infinitybot
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true