@@ -3,10 +3,47 @@ name: Publish Template
33on :
44 push :
55 branches : [ main ]
6+ pull_request :
7+ branches : [ main ]
68 workflow_dispatch :
79
810jobs :
11+ publish-staging :
12+ if : github.event_name == 'pull_request'
13+ runs-on : ubuntu-latest
14+ permissions :
15+ contents : read
16+ packages : write
17+
18+ steps :
19+ - uses : actions/checkout@v4
20+
21+ - name : Set up QEMU
22+ uses : docker/setup-qemu-action@v3
23+
24+ - name : Set up Docker Buildx
25+ uses : docker/setup-buildx-action@v3
26+
27+ - name : Log in to GitHub Container Registry
28+ uses : docker/login-action@v3
29+ with :
30+ registry : ghcr.io
31+ username : ${{ github.actor }}
32+ password : ${{ secrets.GITHUB_TOKEN }}
33+
34+ - name : Build and push staging template
35+ uses : docker/build-push-action@v5
36+ with :
37+ context : .
38+ file : ./src/dbt-fusion/.devcontainer/Dockerfile
39+ platforms : linux/amd64,linux/arm64
40+ push : true
41+ tags : |
42+ ghcr.io/${{ github.repository }}/dbt-fusion:pr-${{ github.event.pull_request.number }}
43+ ghcr.io/${{ github.repository }}/dbt-fusion:staging
44+
945 publish :
46+ if : github.event_name == 'push'
1047 runs-on : ubuntu-latest
1148 permissions :
1249 contents : read
3572 file : ./src/dbt-fusion/.devcontainer/Dockerfile
3673 platforms : linux/amd64,linux/arm64
3774 push : true
38- tags : ghcr.io/${{ github.repository }}/dbt-fusion:latest
75+ tags : ghcr.io/${{ github.repository }}/dbt-fusion:latest
76+
77+ cleanup-pr-images :
78+ if : github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
79+ needs : publish
80+ runs-on : ubuntu-latest
81+ permissions :
82+ packages : write
83+
84+ steps :
85+ - name : Log in to GitHub Container Registry
86+ uses : docker/login-action@v3
87+ with :
88+ registry : ghcr.io
89+ username : ${{ github.actor }}
90+ password : ${{ secrets.GITHUB_TOKEN }}
91+
92+ - name : Delete PR-specific image
93+ run : |
94+ # Delete PR-specific tag
95+ docker run --rm \
96+ -e GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} \
97+ -e PACKAGE_NAME=dbt-fusion \
98+ -e PACKAGE_TYPE=container \
99+ -e PACKAGE_OWNER=${{ github.repository_owner }} \
100+ -e PACKAGE_VERSION=pr-${{ github.event.pull_request.number }} \
101+ ghcr.io/actions/github-script@v6
102+
103+ # Delete staging tag
104+ docker run --rm \
105+ -e GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} \
106+ -e PACKAGE_NAME=dbt-fusion \
107+ -e PACKAGE_TYPE=container \
108+ -e PACKAGE_OWNER=${{ github.repository_owner }} \
109+ -e PACKAGE_VERSION=staging \
110+ ghcr.io/actions/github-script@v6
111+ env :
112+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments