From 8b28353b79f95b5e1bdea3cd2a5f8d9041594178 Mon Sep 17 00:00:00 2001 From: Matti Nannt Date: Tue, 16 Sep 2025 19:33:32 +0200 Subject: [PATCH] fix: release tag extraction in release action (#6554) --- .../actions/build-and-push-docker/action.yml | 63 ++++++++++++------- .github/workflows/release-docker-github.yml | 32 +++++++--- 2 files changed, 62 insertions(+), 33 deletions(-) diff --git a/.github/actions/build-and-push-docker/action.yml b/.github/actions/build-and-push-docker/action.yml index 3d038123de..547a1b894e 100644 --- a/.github/actions/build-and-push-docker/action.yml +++ b/.github/actions/build-and-push-docker/action.yml @@ -160,28 +160,23 @@ runs: # Start with the base image tag TAGS="${ECR_REGISTRY}/${ECR_REPOSITORY}:${IMAGE_TAG}" - # Handle automatic tagging for workflow_call (releases) - if [[ "${{ github.event_name }}" == "workflow_call" ]]; then - if [[ "${IS_PRERELEASE}" == "true" ]]; then - TAGS="${TAGS}\n${ECR_REGISTRY}/${ECR_REPOSITORY}:staging" - echo "Adding staging tag for prerelease" - else - TAGS="${TAGS}\n${ECR_REGISTRY}/${ECR_REPOSITORY}:production" - echo "Adding production tag for stable release" - fi + # Handle automatic tagging based on release type + if [[ "${IS_PRERELEASE}" == "true" ]]; then + TAGS="${TAGS}\n${ECR_REGISTRY}/${ECR_REPOSITORY}:staging" + echo "Adding staging tag for prerelease" + elif [[ "${IS_PRERELEASE}" == "false" ]]; then + TAGS="${TAGS}\n${ECR_REGISTRY}/${ECR_REPOSITORY}:production" + echo "Adding production tag for stable release" fi - # Handle manual tagging for workflow_dispatch - if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then - if [[ "${DEPLOY_PRODUCTION}" == "true" ]]; then - TAGS="${TAGS}\n${ECR_REGISTRY}/${ECR_REPOSITORY}:production" - echo "Adding production tag (manual)" - fi - - if [[ "${DEPLOY_STAGING}" == "true" ]]; then - TAGS="${TAGS}\n${ECR_REGISTRY}/${ECR_REPOSITORY}:staging" - echo "Adding staging tag (manual)" - fi + # Handle manual deployment overrides + if [[ "${DEPLOY_PRODUCTION}" == "true" ]]; then + TAGS="${TAGS}\n${ECR_REGISTRY}/${ECR_REPOSITORY}:production" + echo "Adding production tag (manual override)" + fi + if [[ "${DEPLOY_STAGING}" == "true" ]]; then + TAGS="${TAGS}\n${ECR_REGISTRY}/${ECR_REPOSITORY}:staging" + echo "Adding staging tag (manual override)" fi echo "ECR tags generated:" @@ -194,7 +189,7 @@ runs: } >> "${GITHUB_OUTPUT}" - name: Generate additional GHCR tags for releases - if: ${{ inputs.registry_type == 'ghcr' && inputs.experimental_mode == 'false' && github.event_name == 'workflow_call' }} + if: ${{ inputs.registry_type == 'ghcr' && inputs.experimental_mode == 'false' && (github.event_name == 'workflow_call' || github.event_name == 'release' || github.event_name == 'workflow_dispatch') }} id: ghcr-extra-tags shell: bash env: @@ -228,6 +223,10 @@ runs: echo "Generated GHCR tags:" echo -e "${TAGS}" + # Debug: Show what will be passed to Docker build + echo "DEBUG: Tags for Docker build step:" + echo -e "${TAGS}" + { echo "tags< 1.2.3) - TAG="$GITHUB_REF" - TAG=${TAG#refs/tags/} - # Strip leading 'v' or 'V' if present for backward compatibility + # Extract tag name with fallback logic for different trigger contexts + if [[ -n "${RELEASE_TAG:-}" ]]; then + TAG="$RELEASE_TAG" + echo "Using RELEASE_TAG override: $TAG" + elif [[ "$GITHUB_REF_NAME" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?$ ]] || [[ "$GITHUB_REF_NAME" =~ ^v[0-9] ]]; then + TAG="$GITHUB_REF_NAME" + echo "Using GITHUB_REF_NAME (looks like tag): $TAG" + else + # Fallback: extract from GITHUB_REF for direct tag triggers + TAG="${GITHUB_REF#refs/tags/}" + if [[ -z "$TAG" || "$TAG" == "$GITHUB_REF" ]]; then + TAG="$GITHUB_REF_NAME" + echo "Using GITHUB_REF_NAME as final fallback: $TAG" + else + echo "Extracted from GITHUB_REF: $TAG" + fi + fi + + # Strip v-prefix if present (normalize to clean SemVer) TAG=${TAG#[vV]} - # Validate the extracted tag format (clean SemVer expected) + # Validate SemVer format (supports prereleases like 4.0.0-rc.1) if [[ ! "$TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?$ ]]; then - echo "ERROR: Invalid release tag format. Must be clean semver (e.g., 1.2.3, 1.2.3-alpha)" - echo "Original ref: $GITHUB_REF" - echo "Extracted tag: $TAG" - echo "Expected: Clean SemVer (v-prefix is automatically stripped for backward compatibility)" + echo "ERROR: Invalid tag format '$TAG'. Expected SemVer (e.g., 1.2.3, 4.0.0-rc.1)" exit 1 fi echo "VERSION=$TAG" >> $GITHUB_OUTPUT - echo "Using clean SemVer version: $TAG" + echo "Using version: $TAG" - name: Build and push community release image id: build