Skip to content

Commit e9d2d43

Browse files
committed
Only run jobs on master branch
1 parent 23be629 commit e9d2d43

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

.github/workflows/build.yaml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ name: Test & build Docker image
22

33
on:
44
push:
5-
branches: [ master ]
6-
tags: ['*']
5+
branches: [master]
6+
tags: ["*"]
77
pull_request:
88

99
env:
1010
IMAGE_NAME: trafex/wordpress
1111
IMAGE_TAG: ${{ github.sha }}
1212
DOCKER_BUILDKIT: 1
1313

14-
1514
jobs:
1615
build:
1716
runs-on: ubuntu-latest
@@ -39,24 +38,26 @@ jobs:
3938
- name: Run Trivy vulnerability scanner
4039
uses: aquasecurity/trivy-action@master
4140
with:
42-
image-ref: '${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}'
43-
format: 'template'
44-
template: '@/contrib/sarif.tpl'
45-
output: 'trivy-results.sarif'
41+
image-ref: "${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}"
42+
format: "template"
43+
template: "@/contrib/sarif.tpl"
44+
output: "trivy-results.sarif"
4645

4746
- name: Upload Trivy scan results to GitHub Security tab
47+
if: github.ref == 'refs/heads/master' && (github.event_name == 'push' || github.event_name == 'schedule')
4848
uses: github/codeql-action/upload-sarif@v1
4949
with:
50-
sarif_file: 'trivy-results.sarif'
50+
sarif_file: "trivy-results.sarif"
5151

5252
- name: Login to Docker Hub
53+
if: (github.ref == 'refs/heads/master' && (github.event_name == 'push' || github.event_name == 'schedule' )) || contains(github.ref, 'refs/tags/')
5354
uses: docker/login-action@v1
5455
with:
5556
username: ${{ secrets.DOCKERHUB_USERNAME }}
5657
password: ${{ secrets.DOCKERHUB_TOKEN }}
5758

5859
- name: Build multi-arch image and push latest tag
59-
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
60+
if: github.ref == 'refs/heads/master' && (github.event_name == 'push' || github.event_name == 'schedule')
6061
run: |-
6162
docker buildx build \
6263
--cache-from=$IMAGE_NAME:latest \

0 commit comments

Comments
 (0)