Skip to content

Commit 7b8ad8d

Browse files
committed
use action run number for docker image tag
1 parent 5c60477 commit 7b8ad8d

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

.github/workflows/docker-publish.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ jobs:
2424
build-and-push:
2525
name: Build and Push truvera-api-mcp
2626
runs-on: ubuntu-latest
27+
env:
28+
SHOULD_PUSH: ${{ github.event_name != 'workflow_dispatch' || inputs.push }}
2729
permissions:
2830
contents: read
2931
packages: write
@@ -35,15 +37,21 @@ jobs:
3537
- name: Read build number
3638
id: build_number
3739
run: |
38-
BUILD_NUM=$(cat apps/truvera-api/.buildnumber)
40+
if [ -f apps/truvera-api/.buildnumber ]; then
41+
BUILD_NUM=$(cat apps/truvera-api/.buildnumber)
42+
echo "Using apps/truvera-api/.buildnumber"
43+
else
44+
BUILD_NUM="${{ github.run_number }}"
45+
echo "apps/truvera-api/.buildnumber not found; using GitHub run number"
46+
fi
3947
echo "build_number=$BUILD_NUM" >> $GITHUB_OUTPUT
4048
echo "Build number: $BUILD_NUM"
4149
4250
- name: Set up Docker Buildx
4351
uses: docker/setup-buildx-action@v3
4452

4553
- name: Log in to DockerHub
46-
if: github.event_name != 'pull_request'
54+
if: ${{ env.SHOULD_PUSH == 'true' }}
4755
uses: docker/login-action@v3
4856
with:
4957
username: ${{ secrets.DOCKER_HUB_USERNAME }}
@@ -63,11 +71,12 @@ jobs:
6371
type=sha,prefix={{branch}}-
6472
6573
- name: Build and push API Docker image
74+
id: docker_build
6675
uses: docker/build-push-action@v5
6776
with:
6877
context: .
6978
file: ./apps/truvera-api/Dockerfile
70-
push: ${{ github.event_name != 'pull_request' && (github.event.inputs.push == 'true' || github.event.inputs.push == null) }}
79+
push: ${{ env.SHOULD_PUSH == 'true' }}
7180
tags: ${{ steps.meta.outputs.tags }}
7281
labels: ${{ steps.meta.outputs.labels }}
7382
build-args: |
@@ -77,4 +86,9 @@ jobs:
7786
platforms: linux/amd64,linux/arm64
7887

7988
- name: Image digest
89+
if: ${{ env.SHOULD_PUSH == 'true' }}
8090
run: echo "Image pushed with digest ${{ steps.docker_build.outputs.digest }}"
91+
92+
- name: Image build only
93+
if: ${{ env.SHOULD_PUSH != 'true' }}
94+
run: echo "Image built without push because workflow_dispatch input 'push' was false"

0 commit comments

Comments
 (0)