-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (95 loc) · 3.51 KB
/
Copy pathdocker.yml
File metadata and controls
107 lines (95 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: Docker Build
on:
push:
tags:
- "v*"
- "redisctl-v*"
workflow_dispatch:
env:
REGISTRY: docker.io
IMAGE_NAME: joshrotenberg/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 Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- 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: |
${{ env.IMAGE_NAME }}:latest
${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
${{ env.IMAGE_NAME }}:${{ steps.version.outputs.minor }}
${{ env.IMAGE_NAME }}:${{ steps.version.outputs.major }}
ghcr.io/${{ env.IMAGE_NAME }}:latest
ghcr.io/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Update Docker Hub README
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: joshrotenberg/redisctl
readme-filepath: ./README.md
short-description: "Unified CLI for Redis Cloud and Redis Enterprise management"