Skip to content

chore: release (#505) #25

chore: release (#505)

chore: release (#505) #25

Workflow file for this run

name: Docker Build
on:
push:
tags:
- "v*"
- "redisctl-v*"
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: redis-developer/redisctl
jobs:
docker:
name: Build and Push Docker Images
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: true
- name: Extract version
id: version
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
# For manual dispatch, use the current ref name or extract from Cargo.toml
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
# Running from a tag
VERSION=${GITHUB_REF#refs/tags/v}
elif [[ "${{ github.ref }}" == refs/tags/redisctl-v* ]]; then
# Running from a redisctl-v tag
VERSION=${GITHUB_REF#refs/tags/redisctl-v}
else
# Running from a branch - extract version from Cargo.toml
VERSION=$(grep '^version = ' crates/redisctl/Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "Extracted version from Cargo.toml: $VERSION"
fi
else
# Tag push event
if [[ "${{ github.ref }}" == refs/tags/redisctl-v* ]]; then
VERSION=${GITHUB_REF#refs/tags/redisctl-v}
else
VERSION=${GITHUB_REF#refs/tags/v}
fi
fi
# Validate version format
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Warning: Invalid version format: $VERSION"
VERSION="0.0.0"
fi
echo "Final version: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "major=$(echo $VERSION | cut -d. -f1)" >> $GITHUB_OUTPUT
echo "minor=$(echo $VERSION | cut -d. -f1-2)" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/${{ env.IMAGE_NAME }}:latest
ghcr.io/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
ghcr.io/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.minor }}
ghcr.io/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.major }}
cache-from: type=gha
cache-to: type=gha,mode=max