11name : Publish to Docker Hub
22
33on :
4+ # Triggers minor version ( vX.Y.Z-ShortHash )
45 push :
56 branches :
67 - master
8+ # Triggers major version ( vX.Y.Z )
9+ release :
10+ types : [created]
11+
12+ workflow_dispatch :
713
814jobs :
9- build-and-push-webui :
15+ build-and-push :
1016 runs-on : ubuntu-latest
1117
18+ strategy :
19+ matrix :
20+ name : [whisper-webui, whisper-webui-backend]
21+
1222 steps :
1323 - name : Clean up space for action
1424 run : rm -rf /opt/hostedtoolcache
1525
16- - name : Log in to Docker Hub
17- uses : docker/login-action@v2
18- with :
19- username : ${{ secrets.DOCKER_USERNAME }}
20- password : ${{ secrets.DOCKER_PASSWORD }}
21-
2226 - name : Checkout repository
2327 uses : actions/checkout@v3
2428
@@ -28,46 +32,61 @@ jobs:
2832 - name : Set up QEMU
2933 uses : docker/setup-qemu-action@v3
3034
31- - name : Build and push Docker image
32- uses : docker/build-push-action@v5
33- with :
34- context : .
35- file : ./Dockerfile
36- push : true
37- tags : ${{ secrets.DOCKER_USERNAME }}/whisper-webui:latest
38-
39- - name : Log out of Docker Hub
40- run : docker logout
41-
42- build-and-push-backend :
43- runs-on : ubuntu-latest
44-
45- steps :
46- - name : Clean up space for action
47- run : rm -rf /opt/hostedtoolcache
35+ - name : Extract metadata
36+ id : meta
37+ run : |
38+ SHORT_SHA=$(git rev-parse --short HEAD)
39+ echo "SHORT_SHA=$SHORT_SHA" >> $GITHUB_ENV
40+
41+ # Triggered by a release event — versioning as major ( vX.Y.Z )
42+ if [[ "${GITHUB_EVENT_NAME}" == "release" ]]; then
43+ TAG_NAME="${{ github.event.release.tag_name }}"
44+ echo "GIT_TAG=$TAG_NAME" >> $GITHUB_ENV
45+ echo "IS_RELEASE=true" >> $GITHUB_ENV
46+
47+ # Triggered by a general push event — versioning as minor ( vX.Y.Z-ShortHash )
48+ else
49+ git fetch --tags
50+ LATEST_TAG=$(git tag --list 'v*.*.*' | sort -V | tail -n1)
51+ FALLBACK_TAG="${LATEST_TAG:-v0.0.0}"
52+ echo "GIT_TAG=${FALLBACK_TAG}-${SHORT_SHA}" >> $GITHUB_ENV
53+ echo "IS_RELEASE=false" >> $GITHUB_ENV
54+ fi
55+
56+ - name : Set Dockerfile path
57+ id : dockerfile
58+ run : |
59+ if [ "${{ matrix.name }}" = "whisper-webui" ]; then
60+ echo "DOCKERFILE=./Dockerfile" >> $GITHUB_ENV
61+ elif [ "${{ matrix.name }}" = "whisper-webui-backend" ]; then
62+ echo "DOCKERFILE=./backend/Dockerfile" >> $GITHUB_ENV
63+ else
64+ echo "Unknown component: ${{ matrix.name }}"
65+ exit 1
66+ fi
4867
4968 - name : Log in to Docker Hub
5069 uses : docker/login-action@v2
5170 with :
5271 username : ${{ secrets.DOCKER_USERNAME }}
5372 password : ${{ secrets.DOCKER_PASSWORD }}
5473
55- - name : Checkout repository
56- uses : actions/checkout@v3
57-
58- - name : Set up Docker Buildx
59- uses : docker/setup-buildx-action@v3
60-
61- - name : Set up QEMU
62- uses : docker/setup-qemu-action@v3
63-
64- - name : Build and push Docker image
74+ - name : Build and push Docker image (version tag)
6575 uses : docker/build-push-action@v5
6676 with :
6777 context : .
68- file : ./backend/Dockerfile
78+ file : ${{ env.DOCKERFILE }}
6979 push : true
70- tags : ${{ secrets.DOCKER_USERNAME }}/whisper-webui-backend:latest
80+ tags : |
81+ ${{ secrets.DOCKER_USERNAME }}/${{ matrix.name }}:${{ env.GIT_TAG }}
82+
83+ - name : Tag and push as latest (if release)
84+ if : env.IS_RELEASE == 'true'
85+ run : |
86+ docker pull ${{ secrets.DOCKER_USERNAME }}/${{ matrix.name }}:${{ env.GIT_TAG }}
87+ docker tag ${{ secrets.DOCKER_USERNAME }}/${{ matrix.name }}:${{ env.GIT_TAG }} \
88+ ${{ secrets.DOCKER_USERNAME }}/${{ matrix.name }}:latest
89+ docker push ${{ secrets.DOCKER_USERNAME }}/${{ matrix.name }}:latest
7190
7291 - name : Log out of Docker Hub
7392 run : docker logout
0 commit comments