-
Notifications
You must be signed in to change notification settings - Fork 0
123 lines (105 loc) · 4.1 KB
/
Copy pathci.yml
File metadata and controls
123 lines (105 loc) · 4.1 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# .github/workflows/ci.yml
name: CI (Auto-tag + Push Docker)
on:
push:
branches: [ "main" ]
workflow_dispatch: {}
env:
REGISTRY: docker.io
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/gabs-redis-langcache
DOCKERFILE: ./Dockerfile
# Needed so GITHUB_TOKEN can create tags
permissions:
contents: write
jobs:
build-and-push:
runs-on: ubuntu-latest
outputs:
new_tag: ${{ steps.bump.outputs.new_tag }}
steps:
- name: Checkout (full history)
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine version bump from commit message
id: bump
shell: bash
run: |
set -e
# Get the last tag
LAST=$(git tag -l 'v*.*.*' --sort=-v:refname | head -n1)
[ -z "$LAST" ] && LAST="v0.0.0"
# Parse version
VER=${LAST#v}
IFS='.' read -r MAJOR MINOR PATCH <<<"$VER"
# Get commit message
COMMIT_MSG="${{ github.event.head_commit.message }}"
echo "Commit message: $COMMIT_MSG"
# Determine bump type from conventional commit
if echo "$COMMIT_MSG" | grep -qiE '^(feat|feature)(\(.*\))?!:|^BREAKING CHANGE:'; then
# Breaking change -> major bump
MAJOR=$((MAJOR+1))
MINOR=0
PATCH=0
BUMP_TYPE="major"
elif echo "$COMMIT_MSG" | grep -qiE '^(feat|feature)(\(.*\))?:'; then
# Feature -> minor bump
MINOR=$((MINOR+1))
PATCH=0
BUMP_TYPE="minor"
else
# Everything else (fix, chore, docs, etc.) -> patch bump
PATCH=$((PATCH+1))
BUMP_TYPE="patch"
fi
NEW_TAG="v$MAJOR.$MINOR.$PATCH"
echo "Last tag: $LAST"
echo "Bump type: $BUMP_TYPE"
echo "New tag: $NEW_TAG"
# Export for next steps
echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT
echo "version=$MAJOR.$MINOR.$PATCH" >> $GITHUB_OUTPUT
echo "bump_type=$BUMP_TYPE" >> $GITHUB_OUTPUT
- name: Create and push tag
shell: bash
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "${{ steps.bump.outputs.new_tag }}" -m "release ${{ steps.bump.outputs.new_tag }} (${{ steps.bump.outputs.bump_type }} bump)"
git push origin "${{ steps.bump.outputs.new_tag }}"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build & Push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ${{ env.DOCKERFILE }}
push: true
platforms: linux/amd64,linux/arm64
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.bump.outputs.version }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
labels: |
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.source=${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ steps.bump.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
- name: Summary
run: |
echo "## 🚀 Release Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Version**: ${{ steps.bump.outputs.new_tag }}" >> $GITHUB_STEP_SUMMARY
echo "- **Bump Type**: ${{ steps.bump.outputs.bump_type }}" >> $GITHUB_STEP_SUMMARY
echo "- **Docker Image**: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.bump.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Commit**: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY