Skip to content

Commit 22e9080

Browse files
authored
Add release tag gh action (#1169)
Signed-off-by: Fiachra Corcoran <[email protected]>
1 parent fb5dfad commit 22e9080

File tree

5 files changed

+108
-18
lines changed

5 files changed

+108
-18
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: "Extract Semver and Image Name from Tag"
2+
description: "Extracts semantic version and image name from a Git tag"
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Extract semver and image name
7+
id: extract # <--- must set id to reference outputs
8+
shell: bash
9+
run: |
10+
echo "Extracting tag info from ${GITHUB_REF}"
11+
REF="${GITHUB_REF}"
12+
TAG="${REF#refs/tags/}" # remove 'refs/tags/' prefix
13+
VERSION="${TAG##*/}" # get last part after last slash
14+
15+
# Remove 'functions/' or 'contrib/functions/' prefix
16+
PATH_WITHOUT_PREFIX="${TAG#functions/}"
17+
PATH_WITHOUT_PREFIX="${PATH_WITHOUT_PREFIX#contrib/functions/}"
18+
19+
# Remove 'go/' prefix if present
20+
IMAGE_NAME="${PATH_WITHOUT_PREFIX#go/}"
21+
IMAGE_NAME="${IMAGE_NAME%/*}" # remove version at end
22+
23+
# Validate semver with optional pre-release and build metadata
24+
if [[ "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
25+
echo "version=$VERSION" >> $GITHUB_OUTPUT
26+
echo "image_name=$IMAGE_NAME" >> $GITHUB_OUTPUT
27+
else
28+
echo "Error: Tag '$VERSION' is not a valid semver" >&2
29+
exit 1
30+
fi
31+
32+
outputs:
33+
version:
34+
description: "The extracted semantic version from the tag"
35+
value: ${{ steps.extract.outputs.version }} # reference step id
36+
image_name:
37+
description: "The extracted image name (without functions/, contrib/functions/, or go/ prefixes)"
38+
value: ${{ steps.extract.outputs.image_name }} # reference step id

.github/workflows/after-push-to-branch.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright 2022 Google LLC
22
# Modifications Copyright (C) 2025 OpenInfra Foundation Europe.
33
#
4+
#
45
# Licensed under the Apache License, Version 2.0 (the "License");
56
# you may not use this file except in compliance with the License.
67
# You may obtain a copy of the License at
@@ -13,7 +14,7 @@
1314
# See the License for the specific language governing permissions and
1415
# limitations under the License.
1516

16-
name: Build and push latest curated images
17+
name: Build and push latest dev images
1718
on:
1819
push:
1920
branches:
@@ -25,6 +26,7 @@ jobs:
2526
runs-on: ubuntu-latest
2627
permissions:
2728
packages: write
29+
contents: read
2830
steps:
2931
- uses: actions/checkout@v4
3032
- uses: actions/setup-go@v5
@@ -43,6 +45,7 @@ jobs:
4345
runs-on: ubuntu-latest
4446
permissions:
4547
packages: write
48+
contents: read
4649
steps:
4750
- uses: actions/checkout@v4
4851
- uses: actions/setup-go@v5

.github/workflows/after-tag-with-version.yaml

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,62 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
name: Run the CD script after tags that look like versions
16+
name: Build and push tagged image
17+
1718
on:
1819
push:
1920
tags:
20-
- "**/v[0-9]+.*"
21+
- "functions/*/*/v*"
22+
- "contrib/functions/*/*/v*"
2123

2224
jobs:
23-
build:
24-
name: after-tag-with-version
25+
build-push-release:
2526
runs-on: ubuntu-latest
2627
permissions:
2728
packages: write
29+
contents: read
2830
steps:
29-
- uses: actions/checkout@v4
30-
- uses: actions/setup-go@v5
31-
with:
32-
go-version: '1.24.3'
33-
- run: go version
34-
- name: dev/cd/after-tag-push
35-
run: GIT_REF=${GITHUB_REF} IMAGE_REPO=ghcr.io/${{ github.repository }} dev/cd/after-tag-with-version
36-
env:
37-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
34+
- name: Setup Go
35+
uses: actions/setup-go@v5
36+
with:
37+
go-version: '1.24.3'
38+
39+
- name: Setup QEMU
40+
uses: docker/setup-qemu-action@v3
41+
42+
- name: Setup Buildx
43+
uses: docker/setup-buildx-action@v3
44+
45+
- name: Log in to GHCR
46+
run: |
47+
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
48+
49+
- name: Extract semver and image name
50+
id: extract
51+
uses: ./.github/actions/extract-tag-info
52+
53+
- name: Show outputs
54+
run: |
55+
echo "Version = ${{ steps.extract.outputs.version }}"
56+
echo "Image name = ${{ steps.extract.outputs.image_name }}"
57+
58+
- name: Determine release type and push image
59+
run: |
60+
VERSION="${{ steps.extract.outputs.version }}"
61+
IMAGE_NAME="${{ steps.extract.outputs.image_name }}"
62+
63+
if [[ "${GITHUB_REF#refs/tags/}" == functions/* ]]; then
64+
echo "Detected curated functions release"
65+
cd functions/go
66+
make func-push TAG=$VERSION CURRENT_FUNCTION=$IMAGE_NAME DEFAULT_CR=ghcr.io/${GITHUB_REPOSITORY}
67+
elif [[ "${GITHUB_REF#refs/tags/}" == contrib/functions/* ]]; then
68+
echo "Detected contrib functions release"
69+
cd contrib/functions/go
70+
make func-push TAG=$VERSION CURRENT_FUNCTION=$IMAGE_NAME DEFAULT_CR=ghcr.io/${GITHUB_REPOSITORY}/krm-fn-contrib
71+
else
72+
echo "Tag does not match any known type, skipping."
73+
exit 0
74+
fi

contrib/functions/go/Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,14 @@ func-build: func-verify
131131
../../../scripts/go-function-release.sh build contrib
132132

133133
func-push:
134-
@echo Pushing image $(CURRENT_FUNCTION)...
135-
../../../scripts/go-function-release.sh push contrib
134+
@echo "Checking if $(CURRENT_FUNCTION) is a valid listed function..."
135+
@if echo "$(FUNCTIONS)" | grep -qw "$(CURRENT_FUNCTION)"; then \
136+
echo "Pushing image $(CURRENT_FUNCTION)..."; \
137+
../../../scripts/go-function-release.sh push contrib; \
138+
else \
139+
echo "Error: $(CURRENT_FUNCTION) is not a valid listed function!"; \
140+
exit 1; \
141+
fi
136142

137143
docs-generate:
138144
$(GOBIN)/mdtogo $(CURRENT_FUNCTION) $(CURRENT_FUNCTION)/generated --license=none --strategy=cmdDocs

functions/go/Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,14 @@ func-build: func-verify
154154
../../scripts/go-function-release.sh build curated
155155

156156
func-push:
157-
@echo Pushing image $(CURRENT_FUNCTION)...
158-
../../scripts/go-function-release.sh push curated
157+
@echo "Checking if $(CURRENT_FUNCTION) is a valid listed function..."
158+
@if echo "$(FUNCTIONS)" | grep -qw "$(CURRENT_FUNCTION)"; then \
159+
echo "Pushing image $(CURRENT_FUNCTION)..."; \
160+
../../scripts/go-function-release.sh push curated; \
161+
else \
162+
echo "Error: $(CURRENT_FUNCTION) is not a valid listed function!"; \
163+
exit 1; \
164+
fi
159165

160166
docs-generate:
161167
$(GOBIN)/mdtogo $(CURRENT_FUNCTION) $(CURRENT_FUNCTION)/generated --license=none --strategy=cmdDocs

0 commit comments

Comments
 (0)