File tree Expand file tree Collapse file tree 1 file changed +36
-4
lines changed
Expand file tree Collapse file tree 1 file changed +36
-4
lines changed Original file line number Diff line number Diff line change 1- name : Build & Push Docker image (latest)
1+ name : Build & Push Docker image
22
33on :
44 push :
5- branches : [ "main" ]
5+ branches : ["main"]
66 workflow_dispatch :
7+ inputs :
8+ tag :
9+ description : " Optional tag override (leave empty to use branch name)"
10+ required : false
11+ default : " "
712
813permissions :
914 contents : read
@@ -25,12 +30,39 @@ jobs:
2530 username : ${{ secrets.DOCKERHUB_USERNAME }}
2631 password : ${{ secrets.DOCKERHUB_TOKEN }}
2732
28- - name : Build and push (latest)
33+
34+ - name : Compute image tag
35+ id : meta
36+ shell : bash
37+ run : |
38+ set -euo pipefail
39+
40+ if [[ "${GITHUB_EVENT_NAME}" == "push" && "${GITHUB_REF_NAME}" == "main" ]]; then
41+ TAG="latest"
42+ else
43+ # If user provided an override tag, use it; otherwise use the branch name
44+ TAG_INPUT="${{ github.event.inputs.tag }}"
45+ if [[ -n "${TAG_INPUT}" ]]; then
46+ TAG="${TAG_INPUT}"
47+ else
48+ TAG="${GITHUB_REF_NAME}"
49+ fi
50+ fi
51+
52+ TAG="$(echo "${TAG}" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9._-]+/-/g; s/^-+//; s/-+$//')"
53+
54+ # Docker tags <= 128 chars
55+ TAG="${TAG:0:128}"
56+
57+ echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
58+ echo "Using tag: ${TAG}"
59+
60+ - name : Build and push
2961 uses : docker/build-push-action@v6
3062 with :
3163 context : .
3264 file : ./Dockerfile
3365 push : true
34- tags : oceanenterprise/market:latest
66+ tags : oceanenterprise/market:${{ steps.meta.outputs.tag }}
3567 cache-from : type=gha
3668 cache-to : type=gha,mode=max
You can’t perform that action at this time.
0 commit comments