Skip to content

Commit d9a5000

Browse files
committed
feat(build): enhance versioning and publishing logic in Docker action and GitHub workflow
- Updated docker-action.sh to determine version based on branch and commit hash. - Added conditional logic to publish to Maven only on the main branch. - Modified build.yml to set version dynamically based on the branch, supporting feature and bugfix branches.
1 parent 85da6a1 commit d9a5000

3 files changed

Lines changed: 113 additions & 21 deletions

File tree

.github/workflows/build.yml

Lines changed: 68 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
push:
55
branches:
66
- main
7+
- 'feature/**'
8+
- 'bugfix/**'
79

810
jobs:
911
build:
@@ -13,6 +15,21 @@ jobs:
1315
- uses: actions/checkout@v4
1416
with:
1517
fetch-depth: 2
18+
- name: Set version based on branch
19+
id: version
20+
run: |
21+
BASE_VERSION=$(grep version gradle.properties | cut -d= -f2)
22+
COMMIT_HASH=$(git rev-parse --short HEAD)
23+
24+
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
25+
VERSION="$BASE_VERSION"
26+
else
27+
VERSION="$BASE_VERSION-$COMMIT_HASH"
28+
fi
29+
30+
echo "VERSION=$VERSION" >> $GITHUB_ENV
31+
echo "version=$VERSION" >> $GITHUB_OUTPUT
32+
echo "Building version: $VERSION"
1633
- uses: actions/setup-java@v4
1734
with:
1835
java-version: '17'
@@ -27,6 +44,8 @@ jobs:
2744
- name: Build and push images
2845
run: bash docker-action.sh
2946
env:
47+
VERSION: ${{ env.VERSION }}
48+
GITHUB_REF: ${{ github.ref }}
3049
PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }}
3150
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
3251
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
@@ -58,7 +77,18 @@ jobs:
5877
with:
5978
fetch-depth: 2
6079
- name: Set version
61-
run: echo "APP_VERSION=$(grep version gradle.properties | cut -d= -f2)" >> $GITHUB_ENV
80+
run: |
81+
BASE_VERSION=$(grep version gradle.properties | cut -d= -f2)
82+
COMMIT_HASH=$(git rev-parse --short HEAD)
83+
84+
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
85+
APP_VERSION="$BASE_VERSION"
86+
else
87+
APP_VERSION="$BASE_VERSION-$COMMIT_HASH"
88+
fi
89+
90+
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV
91+
echo "Building version: $APP_VERSION"
6292
- uses: actions/setup-java@v4
6393
with:
6494
java-version: '21'
@@ -90,7 +120,18 @@ jobs:
90120
with:
91121
fetch-depth: 2
92122
- name: Set version
93-
run: echo "APP_VERSION=$(grep version gradle.properties | cut -d= -f2)" >> $env:GITHUB_ENV
123+
run: |
124+
$BASE_VERSION = (Get-Content gradle.properties | Select-String '^version=' | ForEach-Object { $_ -replace 'version=','' }).Trim()
125+
$COMMIT_HASH = git rev-parse --short HEAD
126+
127+
if ("${{ github.ref }}" -eq "refs/heads/main") {
128+
$APP_VERSION = $BASE_VERSION
129+
} else {
130+
$APP_VERSION = "$BASE_VERSION-$COMMIT_HASH"
131+
}
132+
133+
echo "APP_VERSION=$APP_VERSION" >> $env:GITHUB_ENV
134+
Write-Output "Building version: $APP_VERSION"
94135
- uses: actions/setup-java@v4
95136
with:
96137
java-version: '21'
@@ -115,23 +156,25 @@ jobs:
115156

116157
linux-amd64:
117158
needs: build
118-
strategy:
119-
matrix:
120-
include:
121-
- runner: ubuntu-latest
122-
arch: x64
123-
arch_name: amd64
124-
- runner: ubuntu-latest
125-
arch: aarch64
126-
arch_name: arm64
127-
runs-on: ${{ matrix.runner }}
159+
runs-on: [ubuntu-latest]
128160

129161
steps:
130162
- uses: actions/checkout@v4
131163
with:
132164
fetch-depth: 2
133165
- name: Set version
134-
run: echo "APP_VERSION=$(grep version gradle.properties | cut -d= -f2)" >> $GITHUB_ENV
166+
run: |
167+
BASE_VERSION=$(grep version gradle.properties | cut -d= -f2)
168+
COMMIT_HASH=$(git rev-parse --short HEAD)
169+
170+
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
171+
APP_VERSION="$BASE_VERSION"
172+
else
173+
APP_VERSION="$BASE_VERSION-$COMMIT_HASH"
174+
fi
175+
176+
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV
177+
echo "Building version: $APP_VERSION"
135178
- uses: actions/setup-java@v4
136179
with:
137180
java-version: '21'
@@ -173,7 +216,18 @@ jobs:
173216
with:
174217
fetch-depth: 2
175218
- name: Set version
176-
run: echo "APP_VERSION=$(grep version gradle.properties | cut -d= -f2)" >> $GITHUB_ENV
219+
run: |
220+
BASE_VERSION=$(grep version gradle.properties | cut -d= -f2)
221+
COMMIT_HASH=$(git rev-parse --short HEAD)
222+
223+
if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
224+
APP_VERSION="$BASE_VERSION"
225+
else
226+
APP_VERSION="$BASE_VERSION-$COMMIT_HASH"
227+
fi
228+
229+
echo "APP_VERSION=$APP_VERSION" >> $GITHUB_ENV
230+
echo "Building version: $APP_VERSION"
177231
- name: Set up QEMU
178232
uses: docker/setup-qemu-action@v3
179233
with:

docker-action.sh

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,38 @@
11
#!/usr/bin/env bash
22

3-
version=$(grep version gradle.properties | cut -d= -f2)
3+
# Determine version: use env var if set, otherwise get from gradle.properties with commit hash
4+
if [ -n "$VERSION" ]; then
5+
version="$VERSION"
6+
else
7+
base_version=$(grep version gradle.properties | cut -d= -f2)
8+
commit_hash=$(git rev-parse --short HEAD)
9+
10+
# Check if on main branch
11+
if [[ "$GITHUB_REF" == "refs/heads/main" ]]; then
12+
version="$base_version"
13+
else
14+
version="$base_version-$commit_hash"
15+
fi
16+
fi
17+
418
platforms="linux/amd64,linux/arm64"
519

6-
echo "Creating API jars and publishing, version=$version"
7-
./gradlew clean :api:javadocJar :api:sourcesJar :api:shadowJar publishToSonatype closeAndReleaseSonatypeStagingRepository
8-
publish_res=$?
9-
if [[ "$publish_res" -ne 0 ]] ; then
10-
echo "Publish API jar failed, exiting"
11-
# exit 1
20+
echo "Building version: $version"
21+
echo "Branch/Ref: ${GITHUB_REF:-local}"
22+
23+
# Only publish to Maven on main branch
24+
if [[ "$GITHUB_REF" == "refs/heads/main" ]]; then
25+
echo "Creating API jars and publishing to Maven, version=$version"
26+
./gradlew clean :api:javadocJar :api:sourcesJar :api:shadowJar publishToSonatype closeAndReleaseSonatypeStagingRepository
27+
publish_res=$?
28+
if [[ "$publish_res" -ne 0 ]] ; then
29+
echo "Publish API jar failed, exiting"
30+
# exit 1
31+
fi
32+
else
33+
echo "Feature branch detected - skipping Maven publish"
34+
echo "Creating API jars locally, version=$version"
35+
./gradlew clean :api:javadocJar :api:sourcesJar :api:shadowJar
1236
fi
1337

1438
echo "Creating data caterer fat jars, version=$version"
@@ -23,5 +47,16 @@ docker run --privileged --rm tonistiigi/binfmt --install all
2347
docker buildx create --use --name builder
2448
docker buildx inspect --bootstrap builder
2549

50+
# Build and tag Docker images
51+
echo "Building and pushing Docker image with tag: $version"
2652
docker buildx build --platform $platforms \
2753
-t datacatering/data-caterer:$version --push .
54+
55+
# Also tag as 'latest' only for main branch
56+
if [[ "$GITHUB_REF" == "refs/heads/main" ]]; then
57+
echo "Main branch - also tagging as 'latest'"
58+
docker buildx build --platform $platforms \
59+
-t datacatering/data-caterer:latest --push .
60+
else
61+
echo "Feature branch - skipping 'latest' tag"
62+
fi

docs/use-case/changelog/0.17.3.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ Latest features and fixes for Data Caterer include fixing the connection details
1616
- Build for macOS x86_64, linux arm64
1717
- Fix the nightly links to downloads by pushing when main branch is updated instead of tag push.
1818
- Fix the hostname resolution for the UI when running on a different machine than the API.
19+
- Updated docker-action.sh to determine version based on branch and commit hash.
20+
- Added conditional logic to publish to Maven only on the main branch.
21+
- Modified build.yml to set version dynamically based on the branch, supporting feature and bugfix branches.

0 commit comments

Comments
 (0)