-
Notifications
You must be signed in to change notification settings - Fork 0
215 lines (180 loc) · 6.51 KB
/
build.yml
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
name: build
on:
push:
branches:
- main
env:
IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/php
PHP81_VERSION: 8.1.29
PHP82_VERSION: 8.2.20
PHP83_VERSION: 8.3.8
IPE_VERSION: 2.2.15
COMPOSER_VERSION: 2.7.6
XDEBUG_VERSION: 3.3.2
PHPSTAN_VERSION: 1.11.4
APCU_VERSION: 5.1.23
AMQP_VERSION: 2.1.2
RELAY_VERSION: 0.8.0
jobs:
build-matrix:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set-matrix.outputs.version }}
variant: ${{ steps.set-matrix.outputs.variant }}
env: ${{ steps.set-matrix.outputs.env }}
steps:
- name: Set matrix
id: set-matrix
run: |
echo "version=[\"${PHP81_VERSION}\",\"${PHP82_VERSION}\",\"${PHP83_VERSION}\"]" >> $GITHUB_OUTPUT
echo "variant=[\"cli\",\"fpm\"]" >> $GITHUB_OUTPUT
echo "env=[\"prod\",\"dev\"]" >> $GITHUB_OUTPUT
build-image:
needs: build-matrix
runs-on: ubuntu-latest
strategy:
matrix:
version: ${{ fromJSON(needs.build-matrix.outputs.version) }}
variant: ${{ fromJSON(needs.build-matrix.outputs.variant) }}
env: ${{ fromJSON(needs.build-matrix.outputs.env) }}
steps:
- name: Set tag
id: set-tag
run: |
if [[ ${{ matrix.version }} =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
MAJOR=${BASH_REMATCH[1]}
MINOR=${BASH_REMATCH[2]}
PATCH=${BASH_REMATCH[3]}
else
exit 1
fi
case ${{ matrix.env }} in
dev)
ENV_MARK="-dev"
;;
prod)
ENV_MARK=""
;;
esac
TAG="${MAJOR}.${MINOR}-${{ matrix.variant }}${ENV_MARK}"
mkdir tag
touch "tag/${TAG}"
echo "base=${{ env.IMAGE }}:${TAG}" >> $GITHUB_OUTPUT
- name: Save tag
uses: actions/upload-artifact@v4
with:
name: tag-${{ matrix.version }}-${{ matrix.variant }}-${{ matrix.env }}
path: tag/*
- name: Checkout
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: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: "${{ runner.os }}-buildx-${{ matrix.version }}-${{ matrix.variant }}-${{ matrix.env }}-${{ github.sha }}"
restore-keys: |
${{ runner.os }}-buildx-${{ matrix.version }}-${{ matrix.variant }}-${{ matrix.env }}-
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build base image
uses: docker/build-push-action@v5
with:
context: .
push: true
file: ./docker/template.dockerfile
platforms: linux/amd64,linux/arm64
build-args: |
"PHP_VERSION=${{ matrix.version }}"
"PHP_VARIANT=${{ matrix.variant }}"
"PHP_ENV=${{ matrix.env }}"
"IPE_VERSION=${{ env.IPE_VERSION }}"
"COMPOSER_VERSION=${{ env.COMPOSER_VERSION }}"
"XDEBUG_VERSION=${{ env.XDEBUG_VERSION }}"
"PHPSTAN_VERSION=${{ env.PHPSTAN_VERSION }}"
"APCU_VERSION=${{ env.APCU_VERSION }}"
"AMQP_VERSION=${{ env.AMQP_VERSION }}"
"RELAY_VERSION=${{ env.RELAY_VERSION }}"
target: ${{ matrix.variant }}
tags: ${{ steps.set-tag.outputs.base }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
readme:
needs: [ build-image, build-matrix ]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Load tags
uses: actions/download-artifact@v4
with:
path: tags
pattern: tag-*
merge-multiple: true
- name: Update README.md
run: |
VERSION_BADGES=""
for VERSION in ${{ join(fromJSON(needs.build-matrix.outputs.version), ' ') }}; do
VERSION_BADGES="![](https://img.shields.io/badge/-${VERSION}-informational) "$VERSION_BADGES
LATEST_VERSION="${VERSION}"
done
TAGS=(
$(find tags -type f -print0 | while read -rd $'\0' file; do echo ${file##*/}; done | sort -r)
)
LATEST_VERSION=$(echo "$LATEST_VERSION" | sed -E 's/\.[0-9]+$//')
function generate_tags_table () {
TAGS=("$@")
PROD_BUILDS=()
DEV_BUILDS=()
for TAG in "${TAGS[@]}"; do
if [[ $TAG =~ \-dev ]]; then
DEV_BUILDS+=("$TAG")
else
PROD_BUILDS+=("$TAG")
fi
done
string="| prod | dev |"
string+=$'\n'
string+="| --- | --- |"
string+=$'\n'
for i in "${!PROD_BUILDS[@]}"; do
string+="| ${PROD_BUILDS[$i]} | ${DEV_BUILDS[$i]} |"
string+=$'\n'
done
TAGS_TABLE="$string"
}
IMAGE="${{ env.IMAGE }}"
README=$(<README.template.md)
README="${README//%%IMAGE%%/$IMAGE}"
README="${README//%%VERSION_BADGES%%/$VERSION_BADGES}"
README="${README//%%LATEST_VERSION%%/$LATEST_VERSION}"
README="${README//%%COMPOSER_VERSION%%/$COMPOSER_VERSION}"
README="${README//%%XDEBUG_VERSION%%/$XDEBUG_VERSION}"
README="${README//%%PHPSTAN_VERSION%%/$PHPSTAN_VERSION}"
README="${README//%%APCU_VERSION%%/$APCU_VERSION}"
README="${README//%%AMQP_VERSION%%/$AMQP_VERSION}"
README="${README//%%RELAY_VERSION%%/$RELAY_VERSION}"
generate_tags_table "${TAGS[@]}"
README="${README//%%TAGS_TABLE%%/$TAGS_TABLE}"
echo "$README" > README.md
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: ${{ env.IMAGE }}
- name: Git Auto Commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Automated Change
file_pattern: '*.md'