Build #2590
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.1', '8.2', '8.3'] | |
outputs: | |
push: ${{ steps.version.outputs.push }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Determine the version | |
id: version | |
run: | | |
DOCKER_IMAGE=jakzal/phpqa | |
VERSION=master | |
LATEST_PHP_VERSION="8.3" | |
LATEST_FLAVOUR="debian" | |
# jakzal/phpqa:phpX.X-debian, jakzal/phpqa:phpX.X | |
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-phpX.X, jakzal/phpqa:1.55-phpX.X | |
# jakzal/phpqa:1.55.1-alpine, jakzal/phpqa:1.55-alpine | |
# jakzal/phpqa:1.55.1-phpX.X-alpine, jakzal/phpqa:1.55-phpX.X-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@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to DockerHub | |
if: steps.version.outputs.push == 'true' | |
uses: docker/login-action@v3 | |
with: | |
username: jakzal | |
password: ${{ secrets.DOCKER_HUB_TOKEN }} | |
- name: Build | |
uses: docker/build-push-action@v5 | |
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@v5 | |
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@v5 | |
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.1', '8.2', '8.3'] | |
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@v3 | |
- 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 }} |