diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index a31cac1d..2e16f987 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -34,6 +34,8 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + with: + fetch-depth: 0 # Install the cosign tool except on PR # https://github.com/sigstore/cosign-installer @@ -74,6 +76,42 @@ jobs: type=semver,pattern={{major}} type=raw,value=latest,enable={{is_default_branch}} + # Extract version from git tag or ref + # Uses git describe to get latest tag + commit hash in SemVer format: 1.2.3+abc1234 + - name: Extract version + id: version + run: | + if [[ "${{ github.ref_type }}" == "tag" ]]; then + VERSION="${{ github.ref_name }}" + # Remove 'v' prefix if present + VERSION="${VERSION#v}" + else + # Use git describe and simplify: v1.2.3-5-gabc1234 -> 1.2.3+abc1234 + GIT_DESCRIBE=$(git describe --tags --always --long 2>/dev/null || echo "") + if [[ -n "$GIT_DESCRIBE" ]]; then + # Match pattern: v1.2.3-5-gabc1234 (tag-commits-gcommit) + if [[ "$GIT_DESCRIBE" =~ ^v?([0-9]+\.[0-9]+\.[0-9]+)-[0-9]+-g([a-f0-9]+)$ ]]; then + # Format as tag+commit (SemVer build metadata) + TAG_VERSION="${BASH_REMATCH[1]}" + COMMIT_HASH="${BASH_REMATCH[2]}" + VERSION="${TAG_VERSION}+${COMMIT_HASH:0:7}" + elif [[ "$GIT_DESCRIBE" =~ ^v?([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then + # Exactly on a tag + VERSION="${BASH_REMATCH[1]}" + else + # Fallback: just commit hash + COMMIT_SHA="${{ github.sha }}" + VERSION="${COMMIT_SHA:0:7}" + fi + else + # No tags exist, use commit hash + COMMIT_SHA="${{ github.sha }}" + VERSION="${COMMIT_SHA:0:7}" + fi + fi + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "Version: $VERSION" + # Build and push Docker image with Buildx (don't push on PR) # https://github.com/docker/build-push-action - name: Build and push Docker image @@ -86,6 +124,8 @@ jobs: platforms: linux/amd64,linux/arm64 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + build-args: | + APP_VERSION=${{ steps.version.outputs.version }} cache-from: type=gha cache-to: type=gha,mode=max diff --git a/apps/web/Dockerfile b/apps/web/Dockerfile index 5a49c008..d925cfd0 100644 --- a/apps/web/Dockerfile +++ b/apps/web/Dockerfile @@ -37,9 +37,11 @@ RUN turbo prune --scope=${PROJECT} --scope=@kan/db --docker # 3. Build the project FROM base AS builder ARG PROJECT +ARG APP_VERSION # Environment to skip .env validation on build ENV CI=true +ENV NEXT_PUBLIC_APP_VERSION=${APP_VERSION} WORKDIR /app diff --git a/apps/web/src/components/UserMenu.tsx b/apps/web/src/components/UserMenu.tsx index 0a483385..1fec9f1c 100644 --- a/apps/web/src/components/UserMenu.tsx +++ b/apps/web/src/components/UserMenu.tsx @@ -9,6 +9,7 @@ import { twMerge } from "tailwind-merge"; import { authClient } from "@kan/auth/client"; +import { env } from "~/env"; import { useIsMobile } from "~/hooks/useMediaQuery"; import { useKeyboardShortcuts } from "~/providers/keyboard-shortcuts"; import { useModal } from "~/providers/modal"; @@ -225,6 +226,25 @@ export default function UserMenu({ + {env.NEXT_PUBLIC_APP_VERSION && ( +