1- name : Docker Build and Test
1+ name : Docker Build and Push
22
33on :
44 push :
1010jobs :
1111 docker-build :
1212 runs-on : ubuntu-latest
13+ permissions :
14+ contents : read
15+ packages : write
1316
1417 steps :
1518 - name : Checkout repository
@@ -20,18 +23,35 @@ jobs:
2023 - name : Set up Docker Buildx
2124 uses : docker/setup-buildx-action@v2
2225
23- - name : Verify Dockerfile exists
24- run : |
25- ls -la
26- if [ ! -f Dockerfile ]; then
27- echo "ERROR: Dockerfile not found!"
28- exit 1
29- fi
26+ - name : Log in to GitHub Container Registry
27+ uses : docker/login-action@v2
28+ with :
29+ registry : ghcr.io
30+ username : ${{ github.actor }}
31+ password : ${{ secrets.GITHUB_TOKEN }}
3032
31- - name : Build Docker image
32- run : |
33- docker build -t psi-ae:test .
33+ - name : Extract metadata for Docker
34+ id : meta
35+ uses : docker/metadata-action@v4
36+ with :
37+ images : ghcr.io/${{ github.repository }}
38+ tags : |
39+ type=ref,event=branch
40+ type=ref,event=pr
41+ type=sha,prefix={{branch}}-
42+ type=raw,value=latest,enable={{is_default_branch}}
43+
44+ - name : Build and push Docker image
45+ uses : docker/build-push-action@v4
46+ with :
47+ context : .
48+ push : ${{ github.event_name != 'pull_request' }}
49+ tags : ${{ steps.meta.outputs.tags }}
50+ labels : ${{ steps.meta.outputs.labels }}
51+ cache-from : type=gha
52+ cache-to : type=gha,mode=max
3453
3554 - name : Run example tests
55+ if : github.event_name == 'pull_request'
3656 run : |
37- docker run --rm psi-ae:test ./example/run_examples.sh
57+ docker run --rm ghcr.io/${{ github.repository }}:pr-${{ github.event.pull_request.number }} ./example/run_examples.sh
0 commit comments