5555 - name : Install dependencies
5656 run : npm ci
5757
58- - name : Run tests
59- run : npm run test
60-
6158 - name : Run tests with coverage
6259 run : npm run test:coverage
6360
@@ -69,14 +66,35 @@ jobs:
6966 path : coverage/
7067 retention-days : 7
7168
72- # Step 3:
69+ # Step 3: Build and Deploy (only on main branch)
70+ build-and-deploy :
71+ name : Build & Deploy to Docker Hub
72+ runs-on : ubuntu-latest
73+ needs : [lint, test]
74+ if : github.ref == 'refs/heads/main' && github.event_name == 'push'
75+
76+ steps :
77+ - name : Checkout code
78+ uses : actions/checkout@v4
79+
80+ - name : Set up QEMU
81+ uses : docker/setup-qemu-action@v3
82+
83+ - name : Set up Docker Buildx
84+ uses : docker/setup-buildx-action@v3
85+
86+ - name : Extract metadata
87+ id : meta
88+ run : |
89+ echo "short_sha=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
90+ echo "date=$(date +'%Y%m%d')" >> "$GITHUB_OUTPUT"
91+
7392 - name : Log in to Docker Hub
7493 uses : docker/login-action@v3
7594 with :
7695 username : ${{ secrets.DOCKER_USERNAME }}
7796 password : ${{ secrets.DOCKERHUB_TOKEN }}
7897
79- # Step 4. Build and push production Docker image
8098 - name : Build and push production image
8199 uses : docker/build-push-action@v6
82100 with :
85103 push : true
86104 platforms : linux/amd64,linux/arm64
87105 tags : |
88- ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKERHUB_PROJECT_NAME }}:latest
89- ${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKERHUB_PROJECT_NAME }}:${{ steps.meta.outputs.SHORT_SHA }}
90- cache-from : type=local,src=/tmp/.buildx-cache
106+ ${{ env.DOCKERHUB_REPO }}:latest
107+ ${{ env.DOCKERHUB_REPO }}:${{ steps.meta.outputs.short_sha }}
108+ ${{ env.DOCKERHUB_REPO }}:${{ steps.meta.outputs.date }}
109+ cache-from : type=gha
110+ cache-to : type=gha,mode=max
0 commit comments