Skip to content

Commit c1e4237

Browse files
authored
Merge pull request #167 from jumpstarter-dev/build-prs
ci: build expirable images for pull-requests
2 parents b3e3eae + f6fa7a0 commit c1e4237

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

.github/workflows/build-images.yaml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,21 @@ on:
88
branches:
99
- main
1010
- 'release-*'
11+
pull_request:
12+
types: [opened, synchronize, reopened, labeled]
13+
branches:
14+
- main
15+
- 'release-*'
1116
merge_group:
1217

1318
env:
14-
PUSH: ${{ github.repository_owner == 'jumpstarter-dev' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/heads/release-')) }}
19+
PUSH: ${{ github.repository_owner == 'jumpstarter-dev' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') || startsWith(github.ref, 'refs/heads/release-') || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)) }}
1520
REGISTRY: quay.io
1621
QUAY_ORG: quay.io/jumpstarter-dev
1722

1823
jobs:
1924
build-and-push-image:
25+
if: github.event_name != 'pull_request' || contains(github.event.pull_request.labels.*.name, 'build-pr-images')
2026
runs-on: ubuntu-latest
2127
permissions:
2228
contents: read
@@ -119,6 +125,10 @@ jobs:
119125
uses: docker/metadata-action@v5
120126
with:
121127
images: ${{ env.REGISTRY }}/${{ matrix.image_name }}
128+
tags: |
129+
type=ref,event=pr,prefix=pr-
130+
labels: |
131+
quay.expires-after=${{ github.event_name == 'pull_request' && '7d' || '' }}
122132
123133
- name: Build and push Docker image
124134
id: push
@@ -127,7 +137,7 @@ jobs:
127137
context: ${{ matrix.context }}
128138
file: ${{ matrix.dockerfile }}
129139
push: ${{ env.PUSH }}
130-
tags: ${{ steps.set-tags.outputs.tags }}
140+
tags: ${{ github.event_name == 'pull_request' && steps.meta.outputs.tags || steps.set-tags.outputs.tags }}
131141
labels: ${{ steps.meta.outputs.labels }}
132142
platforms: linux/amd64,linux/arm64
133143
cache-from: type=gha

0 commit comments

Comments
 (0)