26
26
- name : Compute version number
27
27
id : version-string
28
28
run : |
29
- DATE="$(date +%Y%m%d)"
30
- COMMIT="$(git rev-parse --short HEAD)"
31
- echo "tag=0.$DATE.$GITHUB_RUN_NUMBER+ref.$COMMIT" >> "$GITHUB_OUTPUT"
29
+ if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
30
+ # For main branch, use semver with -dev suffix
31
+ echo "tag=0.0.1-dev.$GITHUB_RUN_NUMBER+$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
32
+ elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
33
+ # For tags, use the tag as is (assuming it's semver)
34
+ TAG="${{ github.ref_name }}"
35
+ echo "tag=$TAG" >> "$GITHUB_OUTPUT"
36
+ else
37
+ # For other branches, use branch name and run number
38
+ BRANCH="${{ github.ref_name }}"
39
+ echo "tag=0.0.1-$BRANCH.$GITHUB_RUN_NUMBER+$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
40
+ fi
32
41
33
42
- name : Login to GitHub Container Registry
34
43
uses : docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # pin@v3.4.0
46
55
- name : Build and Push Image to GHCR
47
56
run : |
48
57
TAG=$(echo "${{ steps.version-string.outputs.tag }}" | sed 's/+/_/g')
49
- KO_DOCKER_REPO=$BASE_REPO ko build --platform=linux/amd64,linux/arm64 --bare -t $TAG ./cmd/thv \
58
+ TAGS="-t $TAG"
59
+
60
+ # Add latest tag only if building from a tag
61
+ if [[ "${{ github.ref }}" == refs/tags/* ]]; then
62
+ TAGS="$TAGS -t latest"
63
+ fi
64
+
65
+ KO_DOCKER_REPO=$BASE_REPO ko build --platform=linux/amd64,linux/arm64 --bare $TAGS ./cmd/thv \
50
66
--image-label=org.opencontainers.image.source=https://github.com/StacklokLabs/toolhive,org.opencontainers.image.title="toolhive",org.opencontainers.image.vendor=Stacklok
51
67
52
68
- name : Sign Image with Cosign
56
72
TAG=$(echo "${{ steps.version-string.outputs.tag }}" | sed 's/+/_/g')
57
73
# Sign the ko image
58
74
cosign sign -y $BASE_REPO:$TAG
75
+
76
+ # Sign the latest tag if building from a tag
77
+ if [[ "${{ github.ref }}" == refs/tags/* ]]; then
78
+ cosign sign -y $BASE_REPO:latest
79
+ fi
59
80
60
81
operator-image-build-and-publish :
61
82
runs-on : ubuntu-latest
@@ -117,7 +138,14 @@ jobs:
117
138
- name : Build and Push Image to GHCR
118
139
run : |
119
140
TAG=$(echo "${{ steps.version-string.outputs.tag }}" | sed 's/+/_/g')
120
- KO_DOCKER_REPO=$BASE_REPO ko build --platform=linux/amd64,linux/arm64 --bare -t $TAG ./cmd/thv-operator \
141
+ TAGS="-t $TAG"
142
+
143
+ # Add latest tag only if building from a tag
144
+ if [[ "${{ github.ref }}" == refs/tags/* ]]; then
145
+ TAGS="$TAGS -t latest"
146
+ fi
147
+
148
+ KO_DOCKER_REPO=$BASE_REPO ko build --platform=linux/amd64,linux/arm64 --bare $TAGS ./cmd/thv-operator \
121
149
--image-label=org.opencontainers.image.source=https://github.com/StacklokLabs/toolhive,org.opencontainers.image.title="toolhive-operator",org.opencontainers.image.vendor=Stacklok
122
150
123
151
- name : Sign Image with Cosign
@@ -127,3 +155,8 @@ jobs:
127
155
TAG=$(echo "${{ steps.version-string.outputs.tag }}" | sed 's/+/_/g')
128
156
# Sign the ko image
129
157
cosign sign -y $BASE_REPO:$TAG
158
+
159
+ # Sign the latest tag if building from a tag
160
+ if [[ "${{ github.ref }}" == refs/tags/* ]]; then
161
+ cosign sign -y $BASE_REPO:latest
162
+ fi
0 commit comments