From 64bc7dcf7c0a8e006ab6eb6e8b4a52ad5e7e6528 Mon Sep 17 00:00:00 2001 From: Adam Cooke Date: Tue, 19 Mar 2024 16:42:21 +0000 Subject: [PATCH] chore(github-actions): include a version string on branch-*/latest images --- .github/workflows/ci.yml | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 736137e..17e6bff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,21 +73,33 @@ jobs: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - id: tag + - id: info run: | - TAG="${GITHUB_REF#refs/heads/}" - if [ -z "$TAG" ]; then exit 1; fi - if [[ $TAG == "main" ]]; then TAG="latest"; else TAG="branch-${TAG}"; fi - echo "tag=${TAG}" >> $GITHUB_OUTPUT + IMAGE=ghcr.io/postalserver/postal + + REF="${GITHUB_REF#refs/heads/}" + if [ -z "$REF" ]; then exit 1; fi + + VER="$(git describe --tags 2>/dev/null)" + echo "version=${VER}" >> "$GITHUB_OUTPUT" + + echo 'tags<> "$GITHUB_OUTPUT" + if [[ "$REF" == "main" ]]; then + echo "${IMAGE}:latest" >> "$GITHUB_OUTPUT" + else + echo "${IMAGE}:branch-${REF}" >> "$GITHUB_OUTPUT" + fi + echo 'EOF' >> "$GITHUB_OUTPUT" - uses: docker/build-push-action@v4 with: push: true - tags: | - ghcr.io/postalserver/postal:${{ steps.tag.outputs.tag }} + tags: ${{ steps.info.outputs.tags }} cache-from: type=gha cache-to: type=gha,mode=max target: full platforms: linux/amd64 + build-args: | + VERSION=${{ steps.info.outputs.version }} publish-image: name: Publish Image