Skip to content

wip

wip #84

Workflow file for this run

name: build
on:
push:
branches:
- main
env:
IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/php
PHP81_VERSION: 8.1.28
PHP82_VERSION: 8.2.19
PHP83_VERSION: 8.3.7
IPE_VERSION: 2.2.14
COMPOSER_VERSION: 2.7.6
XDEBUG_VERSION: 3.3.2
PHPSTAN_VERSION: 1.11.3
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'