Skip to content

Commit dbdf1ca

Browse files
committed
Add dev / latest/version split in automated builds for releases
1 parent f5480cf commit dbdf1ca

2 files changed

Lines changed: 114 additions & 26 deletions

File tree

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Almost entirely written by ChatGPT
22

3-
name: Build and publish container
3+
name: Build and publish dev container
44

55
on:
66
push:
@@ -64,18 +64,7 @@ jobs:
6464
fi
6565
6666
jar_file="$(printf '%s\n' "${candidates[@]}" | awk -F/ '{print length($NF), $0}' | sort -n | head -n1 | cut -d' ' -f2-)"
67-
jar_basename="$(basename "$jar_file")"
68-
69-
if [[ "$jar_basename" =~ ^fetcharr-(.+)\.jar$ ]]; then
70-
version="${BASH_REMATCH[1]}"
71-
else
72-
echo "Could not determine version from JAR name: $jar_basename" >&2
73-
exit 1
74-
fi
75-
7667
echo "jar_file=$jar_file" >> "$GITHUB_OUTPUT"
77-
echo "jar_basename=$jar_basename" >> "$GITHUB_OUTPUT"
78-
echo "version=$version" >> "$GITHUB_OUTPUT"
7968
8069
- name: Set up QEMU
8170
uses: docker/setup-qemu-action@v3
@@ -96,18 +85,7 @@ jobs:
9685
username: ${{ github.actor }}
9786
password: ${{ secrets.GITHUB_TOKEN }}
9887

99-
- name: Extract container metadata
100-
id: meta
101-
uses: docker/metadata-action@v5
102-
with:
103-
images: |
104-
docker.io/egg82/fetcharr
105-
ghcr.io/${{ github.repository_owner }}/fetcharr
106-
tags: |
107-
type=raw,value=latest
108-
type=raw,value=${{ steps.jar.outputs.version }}
109-
110-
- name: Build and push multi-arch image
88+
- name: Build and push multi-arch dev image
11189
uses: docker/build-push-action@v6
11290
with:
11391
context: .
@@ -116,7 +94,8 @@ jobs:
11694
platforms: linux/amd64,linux/arm64,linux/ppc64le
11795
build-args: |
11896
JAR_FILE=${{ steps.jar.outputs.jar_file }}
119-
tags: ${{ steps.meta.outputs.tags }}
120-
labels: ${{ steps.meta.outputs.labels }}
97+
tags: |
98+
docker.io/egg82/fetcharr:dev
99+
ghcr.io/${{ github.repository_owner }}/fetcharr:dev
121100
cache-from: type=gha
122101
cache-to: type=gha,mode=max
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Entirely written by ChatGPT
2+
3+
name: Build and publish release container
4+
5+
on:
6+
release:
7+
types:
8+
- published
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: read
13+
packages: write
14+
15+
env:
16+
IMAGE_NAME: fetcharr
17+
18+
jobs:
19+
docker:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- name: Check out repo at release tag
24+
uses: actions/checkout@v4
25+
with:
26+
ref: ${{ github.event.release.tag_name }}
27+
28+
- name: Set up Java
29+
uses: actions/setup-java@v4
30+
with:
31+
distribution: temurin
32+
java-version: '21'
33+
cache: maven
34+
35+
- name: Build project
36+
run: mvn -B clean package
37+
38+
- name: Find main JAR
39+
id: jar
40+
shell: bash
41+
run: |
42+
set -Eeuo pipefail
43+
shopt -s nullglob
44+
45+
candidates=()
46+
for f in ./App/target/*.jar; do
47+
name="$(basename "$f")"
48+
case "$name" in
49+
*-sources.jar|*-javadoc.jar|*-javadoc-resources.jar|*-test-javadoc-resources.jar|original-*.jar)
50+
continue
51+
;;
52+
*)
53+
candidates+=("$f")
54+
;;
55+
esac
56+
done
57+
58+
if (( ${#candidates[@]} == 0 )); then
59+
echo "No usable JAR found in ./App/target" >&2
60+
exit 1
61+
fi
62+
63+
jar_file="$(printf '%s\n' "${candidates[@]}" | awk -F/ '{print length($NF), $0}' | sort -n | head -n1 | cut -d' ' -f2-)"
64+
echo "jar_file=$jar_file" >> "$GITHUB_OUTPUT"
65+
66+
- name: Derive release version
67+
id: version
68+
shell: bash
69+
run: |
70+
set -Eeuo pipefail
71+
version="${{ github.event.release.tag_name }}"
72+
version="${version#v}"
73+
echo "version=$version" >> "$GITHUB_OUTPUT"
74+
75+
- name: Set up QEMU
76+
uses: docker/setup-qemu-action@v3
77+
78+
- name: Set up Buildx
79+
uses: docker/setup-buildx-action@v3
80+
81+
- name: Log in to Docker Hub
82+
uses: docker/login-action@v3
83+
with:
84+
username: ${{ vars.DOCKERHUB_USERNAME }}
85+
password: ${{ secrets.DOCKERHUB_TOKEN }}
86+
87+
- name: Log in to GHCR
88+
uses: docker/login-action@v3
89+
with:
90+
registry: ghcr.io
91+
username: ${{ github.actor }}
92+
password: ${{ secrets.GITHUB_TOKEN }}
93+
94+
- name: Build and push multi-arch release image
95+
uses: docker/build-push-action@v6
96+
with:
97+
context: .
98+
file: ./Containerfile
99+
push: true
100+
platforms: linux/amd64,linux/arm64,linux/ppc64le
101+
build-args: |
102+
JAR_FILE=${{ steps.jar.outputs.jar_file }}
103+
tags: |
104+
docker.io/egg82/fetcharr:${{ steps.version.outputs.version }}
105+
docker.io/egg82/fetcharr:latest
106+
ghcr.io/${{ github.repository_owner }}/fetcharr:${{ steps.version.outputs.version }}
107+
ghcr.io/${{ github.repository_owner }}/fetcharr:latest
108+
cache-from: type=gha
109+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)