|
8 | 8 | version:
|
9 | 9 | description: 'Version tag for the Docker image'
|
10 | 10 | required: true
|
11 |
| - default: 'latest' # You can set a default version if desired |
| 11 | + default: 'latest' |
12 | 12 |
|
13 | 13 | jobs:
|
14 | 14 | build-and-push:
|
@@ -37,12 +37,19 @@ jobs:
|
37 | 37 | username: ${{ secrets.DOCKERHUB_USER }}
|
38 | 38 | password: ${{ secrets.DOCKERHUB_AT }}
|
39 | 39 |
|
40 |
| - - name: Use version input |
| 40 | + - name: Determine version |
41 | 41 | id: use_version
|
42 | 42 | run: |
|
43 |
| - VERSION="${{ github.event.inputs.version }}" |
| 43 | + # If the workflow is triggered by a release, use the release tag |
| 44 | + if [ "${GITHUB_EVENT_NAME}" == "release" ]; then |
| 45 | + VERSION="${GITHUB_REF#refs/tags/}" |
| 46 | + else |
| 47 | + VERSION="${{ github.event.inputs.version }}" |
| 48 | + fi |
44 | 49 | VERSION_LOWER=$(echo $VERSION | tr '[:upper:]' '[:lower:]')
|
| 50 | + REPO_NAME=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') |
45 | 51 | echo "VERSION=$VERSION_LOWER" >> $GITHUB_ENV
|
| 52 | + echo "REPO_NAME=$REPO_NAME" >> $GITHUB_ENV |
46 | 53 |
|
47 | 54 | - name: Retrieve previous release version
|
48 | 55 | id: previous_version
|
|
61 | 68 | - name: Build and Push Docker Image (GitHub Packages)
|
62 | 69 | run: |
|
63 | 70 | docker buildx build --platform linux/amd64,linux/arm64 \
|
64 |
| - --tag ghcr.io/${{ github.repository }}:${{ env.VERSION }} \ |
65 |
| - --tag ghcr.io/${{ github.repository }}:latest \ |
| 71 | + --tag ghcr.io/${{ env.REPO_NAME }}:${{ env.VERSION }} \ |
| 72 | + --tag ghcr.io/${{ env.REPO_NAME }}:latest \ |
66 | 73 | --push .
|
67 | 74 |
|
68 | 75 | - name: Build and Push Docker Image (DockerHub)
|
|
0 commit comments