|
1 | | -name: Build and Publish Demo Image |
| 1 | +name: Build and Push Docker Image (Branch-Aware Tags) |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
@@ -30,28 +30,36 @@ jobs: |
30 | 30 | username: ${{ github.actor }} |
31 | 31 | password: ${{ secrets.GITHUB_TOKEN }} |
32 | 32 |
|
33 | | - - name: Extract version info |
| 33 | + - name: Extract version info (tag or branch fallback) |
34 | 34 | id: version |
35 | 35 | run: | |
36 | 36 | if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then |
37 | 37 | git fetch --tags |
38 | | - TAG_NAME=$(git describe --tags "$(git rev-list --tags --max-count=1)") |
| 38 | + BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) |
| 39 | + |
| 40 | + TAG_NAME=$(git describe --tags --abbrev=0 "$(git rev-list --tags --no-walk --branches=$BRANCH_NAME | head -n 1)" 2>/dev/null || true) |
| 41 | + |
| 42 | + if [[ -z "$TAG_NAME" ]]; then |
| 43 | + TAG_NAME="${BRANCH_NAME//\//-}" # sanitize: replace slashes with dashes |
| 44 | + fi |
39 | 45 | else |
40 | 46 | TAG_NAME="${GITHUB_REF#refs/tags/}" |
41 | 47 | fi |
42 | 48 | |
43 | 49 | MAJOR_MINOR=$(echo "$TAG_NAME" | cut -d. -f1,2) |
44 | 50 | |
45 | | - echo "Using tag: $TAG_NAME" |
46 | 51 | echo "TAG=$TAG_NAME" >> $GITHUB_ENV |
47 | 52 | echo "MAJOR_MINOR=$MAJOR_MINOR" >> $GITHUB_ENV |
48 | 53 |
|
| 54 | + - name: Normalize repository name (lowercase) |
| 55 | + run: | |
| 56 | + echo "REPO_LOWER=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV |
| 57 | +
|
49 | 58 | - name: Build and push Docker image |
50 | 59 | uses: docker/build-push-action@v2 |
51 | 60 | with: |
52 | 61 | context: . |
53 | 62 | push: true |
54 | 63 | tags: | |
55 | | - ghcr.io/${{ github.repository_owner }}/$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]'):${{ env.TAG }} |
56 | | - ghcr.io/${{ github.repository_owner }}/$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]'):${{ env.MAJOR_MINOR }} |
57 | | - |
| 64 | + ghcr.io/${{ env.REPO_LOWER }}:${{ env.TAG }} |
| 65 | + ghcr.io/${{ env.REPO_LOWER }}:${{ env.MAJOR_MINOR }} |
0 commit comments