@@ -2,6 +2,9 @@ name: Build images, test, and then push
22
33on : push
44
5+ env :
6+ DOCKER_TAG : ${{ github.sha }}
7+
58jobs :
69 build_publish :
710 name : ' Build'
@@ -25,16 +28,31 @@ jobs:
2528 helm lint infra/helm/zippy
2629
2730 - name : Login to Docker Hub
28- if : github.ref == 'refs/heads/main'
29- uses : docker/login-action@v1
31+ if : env.DOCKERHUB_USERNAME != null && ( github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
32+ uses : docker/login-action@v3
3033 with :
3134 username : ${{ secrets.DOCKERHUB_USERNAME }}
3235 password : ${{ secrets.DOCKERHUB_TOKEN }}
3336
3437 - name : Push images
35- if : github.ref == 'refs/heads/main'
38+ if : env.DOCKERHUB_USERNAME != null && ( github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/'))
3639 run : |
37- docker compose push
40+ docker image ls | grep ${{ env.DOCKER_TAG }} | awk '{ print $1 }' | xargs -I {} echo docker tag {}:${{ env.DOCKER_TAG }} {}:${{ github.ref_name }} | bash
41+ REGISTRY_NAMESPACE=alchemyfr/ps- DOCKER_TAG=${{ github.ref_name }} docker compose push
42+
43+ - name : Push latest
44+ if : env.DOCKERHUB_USERNAME != null && startsWith(github.ref, 'refs/tags/')
45+ run : |
46+ LATEST_TAG=$(curl \
47+ -H "Accept: application/vnd.github+json" \
48+ -H "Authorization: Bearer ${{ github.token }}" \
49+ -H "X-GitHub-Api-Version: 2022-11-28" \
50+ https://api.github.com/repos/${{ github.repository }}/releases/latest | jq --raw-output '.tag_name')
51+
52+ if [ "${LATEST_TAG}" == "${{ github.ref_name }}" ]; then
53+ docker image ls | grep ${{ env.DOCKER_TAG }} | awk '{ print $1 }' | xargs -I {} echo docker tag {}:${{ env.DOCKER_TAG }} {}:latest | bash
54+ REGISTRY_NAMESPACE=alchemyfr/ps- DOCKER_TAG=latest docker compose push
55+ fi
3856
3957 - name : Publish Helm charts
4058 if : github.ref == 'refs/heads/main'
0 commit comments