-
-
Notifications
You must be signed in to change notification settings - Fork 67
190 lines (169 loc) · 8.49 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
name: Build
on:
push:
branches: [master]
pull_request:
release:
types: [created]
schedule:
- cron: '0 0 * * *'
jobs:
build:
runs-on: ubuntu-latest
name: Build
strategy:
fail-fast: false
matrix:
flavour: [debian, alpine]
php: ['8.0', '8.1', '8.2']
outputs:
push: ${{ steps.version.outputs.push }}
steps:
- uses: actions/checkout@v3
- name: Determine the version
id: version
run: |
DOCKER_IMAGE=jakzal/phpqa
VERSION=master
LATEST_PHP_VERSION="8.2"
LATEST_FLAVOUR="debian"
# jakzal/phpqa:php8.2-debian, jakzal/phpqa:php8.2
TAGS="${DOCKER_IMAGE}:php${PHP_VERSION}-${IMAGE_FLAVOUR}"
if [[ $IMAGE_FLAVOUR == "$LATEST_FLAVOUR" ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:php${PHP_VERSION}"
fi
# jakzal/phpqa:alpine, jakzal/phpqa:debian, jakzal/phpqa:latest
if [[ $PHP_VERSION == "$LATEST_PHP_VERSION" ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:${IMAGE_FLAVOUR}"
if [[ $IMAGE_FLAVOUR == "$LATEST_FLAVOUR" ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:latest"
fi
fi
# jakzal/phpqa:1.55.1, jakzal/phpqa:1.55
# jakzal/phpqa:1.55.1-php8.2, jakzal/phpqa:1.55-php8.2
# jakzal/phpqa:1.55.1-alpine, jakzal/phpqa:1.55-alpine
# jakzal/phpqa:1.55.1-php8.2-alpine, jakzal/phpqa:1.55-php8.2-alpine
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
MINOR_VERSION=${VERSION%.*}
TAGS="$TAGS,${DOCKER_IMAGE}:${VERSION}-php${PHP_VERSION}-${IMAGE_FLAVOUR},${DOCKER_IMAGE}:${MINOR_VERSION}-php${PHP_VERSION}-${IMAGE_FLAVOUR}"
if [[ $IMAGE_FLAVOUR == "$LATEST_FLAVOUR" ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:${VERSION}-php${PHP_VERSION},${DOCKER_IMAGE}:${MINOR_VERSION}-php${PHP_VERSION}"
fi
if [[ $PHP_VERSION == "$LATEST_PHP_VERSION" ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:${VERSION}-${IMAGE_FLAVOUR},${DOCKER_IMAGE}:${MINOR_VERSION}-${IMAGE_FLAVOUR}"
if [[ $IMAGE_FLAVOUR == "$LATEST_FLAVOUR" ]]; then
TAGS="$TAGS,${DOCKER_IMAGE}:${VERSION},${DOCKER_IMAGE}:${MINOR_VERSION}"
fi
fi
fi
echo "Version: $VERSION"
echo "Docker tags: $TAGS"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
echo "date=$(date -u +'%Y-%m-%d')" >> $GITHUB_OUTPUT
echo "push=${{ (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master') && github.repository_owner == 'jakzal' }}" >> $GITHUB_OUTPUT
env:
PHP_VERSION: ${{ matrix.php }}
IMAGE_FLAVOUR: ${{ matrix.flavour }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
if: steps.version.outputs.push == 'true'
uses: docker/login-action@v2
with:
username: jakzal
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Build
uses: docker/build-push-action@v3
with:
platforms: linux/amd64,linux/arm64
tags: ${{ steps.version.outputs.tags }}
build-args: |
PHP_VERSION=${{ matrix.php }}
INSTALLATION_DATE=${{ steps.version.outputs.date }}
FLAVOUR=${{ matrix.flavour }}
secrets: |
"composer.auth={""github-oauth"":{""github.com"":""${{ secrets.GITHUB_TOKEN }}""} }"
"phive.auth=<auth xmlns=""https://phar.io/auth""><domain host=""api.github.com"" type=""token"" credentials=""${{ secrets.GITHUB_TOKEN }}"" /></auth>"
labels: |
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.created=${{ steps.version.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
cache-from: type=gha,scope=${{ github.workflow }}-${{ matrix.php }}-${{ matrix.flavour }}
cache-to: type=gha,scope=${{ github.workflow }}-${{ matrix.php }}-${{ matrix.flavour }},mode=max
- name: Load
uses: docker/build-push-action@v3
with:
load: true
platforms: linux/amd64
tags: ${{ steps.version.outputs.tags }}
build-args: |
PHP_VERSION=${{ matrix.php }}
INSTALLATION_DATE=${{ steps.version.outputs.date }}
FLAVOUR=${{ matrix.flavour }}
cache-from: type=gha,scope=${{ github.workflow }}-${{ matrix.php }}-${{ matrix.flavour }}
- name: Test
run: |
echo "::group::Images"
docker images
echo "::endgroup::"
echo "::group::$BUILD_TAG"
docker inspect $BUILD_TAG
echo "::endgroup::"
echo "::group::PHP Version $PHP_VERSION"
docker run --rm --pull never $BUILD_TAG php -v | grep 'PHP '$PHP_VERSION
echo "::endgroup::"
echo "::group::Tests"
docker run --rm --pull never $BUILD_TAG php /tools/toolbox test
echo "::endgroup::"
echo "::group::Tools"
docker run --rm --pull never $BUILD_TAG
echo "::endgroup::"
env:
PHP_VERSION: ${{ matrix.php }}
BUILD_TAG: jakzal/phpqa:php${{ matrix.php }}-${{ matrix.flavour }}
- name: Push
uses: docker/build-push-action@v3
if: steps.version.outputs.push == 'true'
with:
push: ${{ steps.version.outputs.push }}
platforms: linux/amd64,linux/arm64
tags: ${{ steps.version.outputs.tags }}
build-args: |
PHP_VERSION=${{ matrix.php }}
INSTALLATION_DATE=${{ steps.version.outputs.date }}
FLAVOUR=${{ matrix.flavour }}
labels: |
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.created=${{ steps.version.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
cache-from: type=gha,scope=${{ github.workflow }}-${{ matrix.php }}-${{ matrix.flavour }}
verify:
runs-on: ubuntu-latest
name: Verify
needs: build
if: needs.build.outputs.push == 'true'
strategy:
fail-fast: false
matrix:
flavour: [debian, alpine]
php: ['8.0', '8.1', '8.2']
platform: ['linux/arm64','linux/amd64']
include:
- platform: 'linux/arm64'
needs-qemu: true
steps:
- name: Set up QEMU
if: ${{ matrix.needs-qemu == true }}
uses: docker/setup-qemu-action@v2
- name: Test if pushed
run: |
echo "::group::Tests"
docker run --rm --platform=${{ matrix.platform }} $BUILD_TAG php /tools/toolbox test
echo "::endgroup::"
env:
BUILD_TAG: jakzal/phpqa:php${{ matrix.php }}-${{ matrix.flavour }}