Skip to content

Commit 25c2871

Browse files
Merge branch 'main' into public-workflow
2 parents 7471b9c + 8cb07a7 commit 25c2871

File tree

3 files changed

+70
-9
lines changed

3 files changed

+70
-9
lines changed

.github/actions/determine-tags/action.yml

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@ inputs:
66
required: false
77
default: ""
88
version:
9-
description: "Version of the image"
9+
description: "Version of the image (e.g., 0.0.1, without the 'v')"
1010
required: true
1111
base_image:
1212
description: "Base image name for the Docker tags (e.g., 'roboflow/roboflow-inference-server-gpu')"
1313
required: true
14+
token:
15+
description: "GitHub token for accessing repository data"
16+
required: true
17+
force_push:
18+
description: "Force push the release tag (only outputs the version tag)"
19+
required: false
20+
default: "false"
1421
outputs:
1522
image_tags:
1623
description: "Comma-separated list of Docker image tags"
@@ -26,23 +33,73 @@ runs:
2633
CUSTOM_TAG="${{ inputs.custom_tag }}"
2734
VERSION="${{ inputs.version }}"
2835
BASE_IMAGE="${{ inputs.base_image }}"
36+
TOKEN="${{ inputs.token }}"
37+
FORCE_PUSH="${{ inputs.force_push }}"
2938
BRANCH="${{ github.ref_name }}"
39+
EVENT_NAME="${{ github.event_name }}"
40+
TARGET_BRANCH="${{ github.event.release.target_commitish }}"
41+
42+
# Initialize the tags
43+
IMAGE_TAGS=""
44+
45+
# Workflow Dispatch Logic
46+
if [ "$EVENT_NAME" == "workflow_dispatch" ]; then
47+
echo "Triggered manually via workflow_dispatch"
48+
if [ -n "$CUSTOM_TAG" ]; then
49+
echo "Custom tag set, force push ignored."
50+
CUSTOM_TAG="$VERSION-$CUSTOM_TAG"
51+
IMAGE_TAGS="$BASE_IMAGE:$CUSTOM_TAG"
52+
else
53+
echo "Force push set or defaulting to version tag."
54+
IMAGE_TAGS="$BASE_IMAGE:$VERSION"
55+
fi
3056
31-
# Determine the tags
32-
if [ -n "$CUSTOM_TAG" ]; then
33-
IMAGE_TAGS="$BASE_IMAGE:$CUSTOM_TAG"
57+
# Automatic Trigger Logic
3458
else
35-
VERSION_TAG="$BASE_IMAGE:$VERSION"
36-
if [ "$BRANCH" == "main" ]; then
37-
LATEST_TAG="$BASE_IMAGE:latest"
38-
IMAGE_TAGS="$VERSION_TAG,$LATEST_TAG"
59+
echo "Triggered automatically via $EVENT_NAME"
60+
# Fetch the latest release tag for release events
61+
if [ "$EVENT_NAME" == "release" ]; then
62+
RELEASE=$BRANCH
63+
NORMALIZED_RELEASE=$(if echo "$RELEASE" | grep -Eq '^v?[0-9]+\.[0-9]+\.[0-9]$'; then echo "$RELEASE" | sed 's/^v//'; else echo "$RELEASE"; fi)
64+
echo "Normalized release: $NORMALIZED_RELEASE"
65+
66+
LATEST_RELEASE=$(curl -s -H "Authorization: Bearer $TOKEN" \
67+
"https://api.github.com/repos/${{ github.repository }}/releases/latest" | jq -r '.tag_name')
68+
echo "Fetched latest release: $LATEST_RELEASE"
69+
70+
# Normalize versions: remove 'v' from the latest release tag
71+
NORMALIZED_LATEST_RELEASE=$(echo "$LATEST_RELEASE" | sed 's/^v//')
72+
echo "Normalized latest release: $NORMALIZED_LATEST_RELEASE"
3973
else
40-
IMAGE_TAGS="$VERSION_TAG"
74+
LATEST_RELEASE=""
75+
NORMALIZED_RELEASE=""
76+
NORMALIZED_LATEST_RELEASE=""
77+
fi
78+
79+
# Logic for push events to main
80+
if [ "$EVENT_NAME" == "push" ] && [ "$BRANCH" == "main" ]; then
81+
IMAGE_TAGS="$BASE_IMAGE:main"
82+
fi
83+
84+
# Logic for release events
85+
if [ "$EVENT_NAME" == "release" ]; then
86+
IMAGE_TAGS="$BASE_IMAGE:$NORMALIZED_RELEASE"
87+
if [ "$VERSION" == "$NORMALIZED_RELEASE" ] && [ "$NORMALIZED_RELEASE" == "$NORMALIZED_LATEST_RELEASE" ]; then
88+
IMAGE_TAGS="$IMAGE_TAGS,$BASE_IMAGE:latest"
89+
fi
4190
fi
4291
fi
4392
93+
# Clean up leading/trailing commas
94+
IMAGE_TAGS=$(echo "$IMAGE_TAGS" | sed 's/^,//;s/,$//')
95+
4496
# Echo the computed tags
4597
echo "Computed image tags: $IMAGE_TAGS"
4698
99+
if [ -z $IMAGE_TAGS ]; then
100+
echo "No valid image tags found."
101+
exit 1
102+
fi
103+
47104
# Export the tags to outputs
48105
echo "image_tags=$IMAGE_TAGS" >> $GITHUB_OUTPUT

.github/workflows/docker.cpu.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ jobs:
4646
custom_tag: ${{ github.event.inputs.custom_tag }}
4747
version: ${{ env.VERSION }}
4848
base_image: ${{ env.BASE_IMAGE }}
49+
force_push: ${{ github.event.inputs.force_push }}
50+
token: ${{ secrets.GITHUB_TOKEN }}
4951
- name: Set up Depot CLI
5052
uses: depot/setup-action@v1
5153
- name: Build and Push

.github/workflows/docker.gpu.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ jobs:
4646
custom_tag: ${{ github.event.inputs.custom_tag }}
4747
version: ${{ env.VERSION }}
4848
base_image: ${{ env.BASE_IMAGE }}
49+
force_push: ${{ github.event.inputs.force_push }}
50+
token: ${{ secrets.GITHUB_TOKEN }}
4951
- name: Set up Depot CLI
5052
uses: depot/setup-action@v1
5153
- name: Build and Push

0 commit comments

Comments
 (0)