Skip to content

cleanup

cleanup #75

Workflow file for this run

name: build
on:
push:
branches:
- main
env:
IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/php
PHP81_VERSION: 8.1.27
PHP82_VERSION: 8.2.17
PHP83_VERSION: 8.3.4
IPE_VERSION: 2.2.5
COMPOSER_VERSION: 2.7.2
XDEBUG_VERSION: 3.3.1
PHPSTAN_VERSION: 1.10.66
AMQP_VERSION: 2.1.2
RELAY_VERSION: 0.7.0
jobs:
build-matrix:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.set-matrix.outputs.version }}
env: ${{ steps.set-matrix.outputs.env }}
mode: ${{ steps.set-matrix.outputs.mode }}
steps:
- name: Set matrix
id: set-matrix
run: |
echo "version=[\"${PHP81_VERSION}\",\"${PHP82_VERSION}\",\"${PHP83_VERSION}\"]" >> $GITHUB_OUTPUT
echo "env=[\"prod\",\"dev\"]" >> $GITHUB_OUTPUT
echo "mode=[\"cli\",\"fpm\"]" >> $GITHUB_OUTPUT
build-image:
needs: build-matrix
runs-on: ubuntu-latest
strategy:
matrix:
version: ${{ fromJSON(needs.build-matrix.outputs.version) }}
env: ${{ fromJSON(needs.build-matrix.outputs.env) }}
mode: ${{ fromJSON(needs.build-matrix.outputs.mode) }}
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.mode }}${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.mode }}-${{ 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.mode }}-${{ matrix.env }}-${{ github.sha }}"
restore-keys: |
${{ runner.os }}-buildx-${{ matrix.version }}-${{ matrix.mode }}-${{ 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_MODE=${{ matrix.mode }}"
"PHP_ENV=${{ matrix.env }}"
target: ${{ matrix.mode }}-mode
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//%%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'