44 push :
55 branches :
66 - main
7+ tags :
8+ - ' *'
79 paths-ignore :
810 - ' !**.md'
911 - ' docs/**'
1315 paths-ignore :
1416 - ' !**.md'
1517 - ' docs/**'
16- release :
17- types :
18- - released
1918
2019permissions :
2120 contents : read
@@ -52,10 +51,11 @@ jobs:
5251 run : poetry run mypy .
5352 - name : Run tests
5453 run : poetry run pytest -v --cov=src
54+
5555 build-and-publish :
5656 runs-on : ubuntu-24.04
57- needs : test # Ensures tests pass before publishing
58- if : github.event_name != 'pull_request '
57+ needs : test
58+ if : startsWith( github.ref, 'refs/tags/') || github.ref == 'refs/heads/main '
5959 steps :
6060 - name : Checkout repository
6161 uses : actions/checkout@v4
@@ -67,19 +67,25 @@ jobs:
6767 username : ${{ github.actor }}
6868 password : ${{ secrets.GITHUB_TOKEN }}
6969
70- - name : Set image tag
70+ - name : Extract tag or sha
7171 id : vars
72- run : echo "tag=ghcr.io/${{ github.repository }}:${{ github.sha }}" >> $GITHUB_OUTPUT
72+ run : |
73+ if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
74+ VERSION="${GITHUB_REF#refs/tags/}"
75+ else
76+ VERSION="${GITHUB_SHA}"
77+ fi
78+ IMAGE="ghcr.io/${GITHUB_REPOSITORY,,}:${VERSION}"
79+ echo "tag=${IMAGE}" >> $GITHUB_OUTPUT
7380
7481 - name : Build and tag Docker image
7582 run : docker build -t ${{ steps.vars.outputs.tag }} .
7683
7784 - name : Push Docker image
78- if : startsWith(github.ref, 'refs/tags/')
7985 run : docker push ${{ steps.vars.outputs.tag }}
8086
81- - name : Tag and push latest ( on main only)
87+ - name : Also tag and push : latest on main
8288 if : github.ref == 'refs/heads/main'
8389 run : |
84- docker tag ${{ steps.vars.outputs.tag }} ghcr.io/${{ github.repository } }:latest
85- docker push ghcr.io/${{ github.repository } }:latest
90+ docker tag ${{ steps.vars.outputs.tag }} ghcr.io/${GITHUB_REPOSITORY,, }:latest
91+ docker push ghcr.io/${GITHUB_REPOSITORY,, }:latest
0 commit comments