Skip to content

Commit 1bb112d

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 1bb112d

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ name: Build and push containers
33
on:
44
release:
55
types: [published]
6+
pull_request:
67

78
jobs:
89
release-container:
910
runs-on: ubuntu-latest
11+
env:
12+
DOCKER_USER: ${{ secrets.CONTAINER_USERNAME }}
1013
steps:
1114
- name: Compile tag list
1215
id: tags
@@ -28,13 +31,15 @@ jobs:
2831
uses: docker/setup-buildx-action@v1
2932

3033
- name: Login to GitHub Container Registry
34+
if: ${{ secrets.CONTAINER_USERNAME }}
3135
uses: docker/login-action@v1
3236
with:
3337
registry: ghcr.io
34-
username: ${{ secrets.CONTAINER_USERNAME }}
38+
username: ${{ env.DOCKER_USER }}
3539
password: ${{ secrets.CONTAINER_PAT }}
3640

37-
- name: Build and push
41+
- name: Build and push for release
42+
if: ${{ github.event_name == 'release' }}
3843
uses: docker/build-push-action@v2
3944
with:
4045
context: .
@@ -45,3 +50,26 @@ jobs:
4550
tags: ${{ join(fromJSON(steps.tags.outputs.tags), ',') }}
4651
cache-from: type=registry,ref=ghcr.io/laminas/laminas-continuous-integration-action:build-cache
4752
cache-to: type=registry,ref=ghcr.io/laminas/laminas-continuous-integration-action:build-cache,mode=max
53+
54+
- name: Build for local pull request
55+
if: ${{ github.event_name == 'pull_request' && env.DOCKER_USER }}
56+
uses: docker/build-push-action@v2
57+
with:
58+
context: .
59+
file: ./Dockerfile
60+
platforms: linux/amd64
61+
pull: true
62+
push: false
63+
cache-from: type=registry,ref=ghcr.io/laminas/laminas-continuous-integration-action:build-cache
64+
cache-to: type=registry,ref=ghcr.io/laminas/laminas-continuous-integration-action:build-cache,mode=max
65+
66+
- name: Build for fork pull request
67+
if: ${{ github.event_name == 'pull_request' && ! env.DOCKER_USER }}
68+
uses: docker/build-push-action@v2
69+
with:
70+
context: .
71+
file: ./Dockerfile
72+
platforms: linux/amd64
73+
pull: true
74+
push: false
75+
cache-from: type=registry,ref=ghcr.io/laminas/laminas-continuous-integration-action:build-cache

0 commit comments

Comments
 (0)