Skip to content

Commit b2c982d

Browse files
committed
feat: build on pull request as well as release
This change: - adds "pull_request" as an event that will trigger the workflow. - marks the "docker login" step as conditional, only to run if the "container_username" secret is present. - alters the original "Build and push" step such that it only runs on a release - adds two new "build and push" steps - one runs on pull_request if a container_username secret is present, and caches layers - one runs on pull_request if a container_username secret is NOT present, and DOES NOT cache layers Signed-off-by: Matthew Weier O'Phinney <[email protected]>
1 parent e0e8146 commit b2c982d

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

.github/workflows/build-and-push-containers.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Build and push containers
33
on:
44
release:
55
types: [published]
6+
pull_request:
67

78
jobs:
89
release-container:
@@ -28,13 +29,15 @@ jobs:
2829
uses: docker/setup-buildx-action@v1
2930

3031
- name: Login to GitHub Container Registry
32+
if: ${{ secrets.CONTAINER_USERNAME }}
3133
uses: docker/login-action@v1
3234
with:
3335
registry: ghcr.io
3436
username: ${{ secrets.CONTAINER_USERNAME }}
3537
password: ${{ secrets.CONTAINER_PAT }}
3638

37-
- name: Build and push
39+
- name: Build and push for release
40+
if: ${{ github.event_name == 'release' }}
3841
uses: docker/build-push-action@v2
3942
with:
4043
context: .
@@ -45,3 +48,26 @@ jobs:
4548
tags: ${{ join(fromJSON(steps.tags.outputs.tags), ',') }}
4649
cache-from: type=registry,ref=ghcr.io/laminas/laminas-continuous-integration-action:build-cache
4750
cache-to: type=registry,ref=ghcr.io/laminas/laminas-continuous-integration-action:build-cache,mode=max
51+
52+
- name: Build for local pull request
53+
if: ${{ github.event_name == 'pull_request' && secrets.CONTAINER_USERNAME }}
54+
uses: docker/build-push-action@v2
55+
with:
56+
context: .
57+
file: ./Dockerfile
58+
platforms: linux/amd64
59+
pull: true
60+
push: false
61+
cache-from: type=registry,ref=ghcr.io/laminas/laminas-continuous-integration-action:build-cache
62+
cache-to: type=registry,ref=ghcr.io/laminas/laminas-continuous-integration-action:build-cache,mode=max
63+
64+
- name: Build for fork pull request
65+
if: ${{ github.event_name == 'pull_request' && ! secrets.CONTAINER_USERNAME }}
66+
uses: docker/build-push-action@v2
67+
with:
68+
context: .
69+
file: ./Dockerfile
70+
platforms: linux/amd64
71+
pull: true
72+
push: false
73+
cache-from: type=registry,ref=ghcr.io/laminas/laminas-continuous-integration-action:build-cache

0 commit comments

Comments
 (0)