1+ name : Docker Auto Bump
2+
3+ on :
4+ push :
5+ branches :
6+ - gh-pages
7+
8+ permissions :
9+ contents : read
10+ packages : write
11+ id-token : write
12+
13+ jobs :
14+ build :
15+ runs-on : ubuntu-latest
16+
17+ if : startsWith(github.event.head_commit.message, 'bump(docker):')
18+
19+ steps :
20+ - name : Checkout
21+ uses : actions/checkout@v4
22+
23+ # --------------------------------------------
24+ # Extract target directory from commit message
25+ # --------------------------------------------
26+ - name : Parse commit message
27+ id : parse
28+ run : |
29+ MSG="${{ github.event.head_commit.message }}"
30+ DIR=$(echo "$MSG" | sed -E 's/^bump\(docker\):[[:space:]]*//')
31+ IMAGE_NAME=$(basename "$DIR")
32+
33+ echo "dir=$DIR" >> $GITHUB_OUTPUT
34+ echo "image_name=$IMAGE_NAME" >> $GITHUB_OUTPUT
35+
36+ # --------------------------------------------
37+ # Login to GHCR
38+ # --------------------------------------------
39+ - name : Login to GHCR
40+ run : |
41+ echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
42+
43+ # --------------------------------------------
44+ # Get latest version from GHCR
45+ # --------------------------------------------
46+ - name : Determine next version
47+ id : version
48+ run : |
49+ IMAGE="ghcr.io/openprojectx/${{ steps.parse.outputs.image_name }}"
50+
51+ echo "Checking existing tags for $IMAGE"
52+
53+ TAGS=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
54+ https://ghcr.io/v2/openprojectx/${{ steps.parse.outputs.image_name }}/tags/list \
55+ | jq -r '.tags[]?' | sort -V)
56+
57+ if [ -z "$TAGS" ]; then
58+ VERSION="0.1.0"
59+ else
60+ LATEST=$(echo "$TAGS" | tail -n1)
61+ IFS='.' read -r MAJOR MINOR PATCH <<< "$LATEST"
62+ PATCH=$((PATCH + 1))
63+ VERSION="$MAJOR.$MINOR.$PATCH"
64+ fi
65+
66+ echo "version=$VERSION" >> $GITHUB_OUTPUT
67+
68+ # --------------------------------------------
69+ # Setup Docker Buildx
70+ # --------------------------------------------
71+ - name : Setup Buildx
72+ uses : docker/setup-buildx-action@v3
73+
74+ # --------------------------------------------
75+ # Build & Push with registry cache
76+ # --------------------------------------------
77+ - name : Build and push
78+ uses : docker/build-push-action@v6
79+ with :
80+ context : ${{ steps.parse.outputs.dir }}
81+ push : true
82+ tags : |
83+ ghcr.io/openprojectx/${{ steps.parse.outputs.image_name }}:${{ steps.version.outputs.version }}
84+ ghcr.io/openprojectx/${{ steps.parse.outputs.image_name }}:latest
85+ cache-from : type=registry,ref=ghcr.io/openprojectx/${{ steps.parse.outputs.image_name }}:buildcache
86+ cache-to : type=registry,ref=ghcr.io/openprojectx/${{ steps.parse.outputs.image_name }}:buildcache,mode=max
0 commit comments