-
Notifications
You must be signed in to change notification settings - Fork 0
127 lines (112 loc) · 3.79 KB
/
Copy pathbuild-php.yml
File metadata and controls
127 lines (112 loc) · 3.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
name: Build PHP Docker Image
on:
push:
branches:
- main
paths:
- php/**
- .github/workflows/build-php.yml
pull_request:
branches:
- main
paths:
- php/**
- .github/workflows/build-php.yml
env:
REGISTRY: ghcr.io
IMAGE_NAME: yieldstudio/php
jobs:
matrix:
runs-on: ubuntu-latest
outputs:
php_versions: ${{ steps.set.outputs.php_versions }}
type: ${{ steps.set.outputs.type }}
steps:
- name: Set PHP versions
id: set
run: |
echo 'php_versions=["8.2","8.3","8.4"]' >> $GITHUB_OUTPUT
echo 'type=["unit","frankenphp","cli"]' >> $GITHUB_OUTPUT
build:
needs: matrix
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
env:
NODE_VERSION: '22'
strategy:
matrix:
php_version: ${{ fromJSON(needs.matrix.outputs.php_versions) }}
type: ${{ fromJSON(needs.matrix.outputs.type) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch,prefix=${{ matrix.php_version }}-${{ matrix.type }}-
type=ref,event=tag,prefix=${{ matrix.php_version }}-${{ matrix.type }}-v
type=sha,prefix=${{ matrix.php_version }}-${{ matrix.type }}-
type=raw,${{ matrix.php_version }}-${{ matrix.type }}
- name: Build docker image
uses: docker/build-push-action@v6
with:
context: ./php
file: ./php/variation/${{ matrix.type }}/Dockerfile
build-args: |
PHP_VERSION=${{ matrix.php_version }}
NODE_VERSION=${{ env.NODE_VERSION }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha,scope=php-${{ matrix.php_version }}-${{ matrix.type }}
cache-to: type=gha,scope=php-${{ matrix.php_version }}-${{ matrix.type }},mode=max
push: ${{ github.event_name != 'pull_request' }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.php_version }}-${{ matrix.type }}
${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
scan:
if: github.event_name != 'pull_request'
needs:
- matrix
- build
runs-on: ubuntu-latest
strategy:
matrix:
php_version: ${{ fromJSON(needs.matrix.outputs.php_versions) }}
type: ${{ fromJSON(needs.matrix.outputs.type) }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Get Short SHA
id: get_short_sha
run: echo "SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_ENV
- name: Run Trivy Vulnerability Scan
uses: aquasecurity/trivy-action@0.31.0
with:
image-ref: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.php_version }}-${{ matrix.type }}-${{ env.SHORT_SHA }}
format: 'sarif'
output: 'trivy-results.sarif'
ignore-unfixed: true
severity: 'CRITICAL,HIGH,MEDIUM'
vuln-type: 'os,library'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: 'trivy-results.sarif'