Skip to content

Commit e5c8042

Browse files
committed
Build preview image on push to tags
Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
1 parent 46ae185 commit e5c8042

1 file changed

Lines changed: 24 additions & 7 deletions

File tree

.github/workflows/preview.yaml

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ on:
33
push:
44
branches:
55
- main
6+
tags:
7+
- 'v*'
68
paths-ignore:
79
- 'docs/**'
810
- 'config/**'
@@ -40,11 +42,25 @@ jobs:
4042
id: prep
4143
run: |
4244
TIMESTAMP=$(git log -1 --pretty=%ct)
43-
TAG="${GITHUB_REF_NAME//\//-}-${GITHUB_SHA::8}-${TIMESTAMP}"
44-
LATEST_TAG="${GITHUB_REF_NAME//\//-}-latest"
4545
echo "TIMESTAMP=${TIMESTAMP}" >> $GITHUB_OUTPUT
46-
echo "TAG=${TAG}" >> $GITHUB_OUTPUT
47-
echo "LATEST_TAG=${LATEST_TAG}" >> $GITHUB_OUTPUT
46+
47+
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
48+
VERSION="${GITHUB_REF_NAME}-1"
49+
TAG="${GITHUB_REF_NAME}"
50+
BRANCH_BUILD=false
51+
else
52+
TAG="${GITHUB_REF_NAME//\//-}-${GITHUB_SHA::8}-${TIMESTAMP}"
53+
LATEST_TAG="${GITHUB_REF_NAME//\//-}-latest"
54+
VERSION="0.0.0-${TAG}"
55+
BRANCH_BUILD=true
56+
fi
57+
58+
{
59+
echo "VERSION=${VERSION}"
60+
echo "TAG=${TAG}"
61+
echo "LATEST_TAG=${LATEST_TAG}"
62+
echo "BRANCH_BUILD=${BRANCH_BUILD}"
63+
} >> $GITHUB_OUTPUT
4864
- name: Setup QEMU
4965
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0
5066
- name: Setup Docker Buildx
@@ -64,7 +80,7 @@ jobs:
6480
${{ env.IMAGE }}
6581
tags: |
6682
type=raw,value=${{ steps.prep.outputs.TAG }}
67-
type=raw,value=${{ steps.prep.outputs.LATEST_TAG }}
83+
type=raw,value=${{ steps.prep.outputs.LATEST_TAG }},enable=${{ steps.prep.outputs.BRANCH_BUILD == 'true' }}
6884
annotations:
6985
org.opencontainers.image.description=Flux Operator preview build
7086
- name: Push image
@@ -83,10 +99,11 @@ jobs:
8399
tags: ${{ steps.meta.outputs.tags }}
84100
labels: ${{ steps.meta.outputs.labels }}
85101
annotations: ${{ steps.meta.outputs.annotations }}
86-
build-args: "VERSION=0.0.0-${{ steps.prep.outputs.TAG }}"
102+
build-args: "VERSION=${{ steps.prep.outputs.VERSION }}"
87103
- uses: sigstore/cosign-installer@ba7bc0a3fef59531c69a25acd34668d6d3fe6f22 # v4.1.0
88104
- name: Sign image
89105
env:
90106
COSIGN_EXPERIMENTAL: 1
107+
IMAGE_DIGEST: ${{ steps.build-push.outputs.digest }}
91108
run: |
92-
cosign sign --yes ${{ env.IMAGE }}@${{ steps.build-push.outputs.digest }}
109+
cosign sign --yes "${IMAGE}@${IMAGE_DIGEST}"

0 commit comments

Comments
 (0)