Skip to content

refactoring

refactoring #23

Workflow file for this run

name: build
on:
push:
branches:
- main
env:
IMAGE: ${{ secrets.DOCKERHUB_USERNAME }}/php
PHP80_VERSION: 8.0.30
PHP81_VERSION: 8.1.24
PHP82_VERSION: 8.2.11
IPE_VERSION: 2.1.58
COMPOSER_VERSION: 2.6.5
XDEBUG_VERSION: 3.2.2
PHPSTAN_VERSION: 1.10.39
REDIS_VERSION: 6.0.1
CAVIF_VERSION: 1.5.4
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=[\"${PHP80_VERSION}\",\"${PHP81_VERSION}\",\"${PHP82_VERSION}\"]" >> $GITHUB_OUTPUT
echo "env=[\"prod\",\"dev\"]" >> $GITHUB_OUTPUT
echo "mode=[\"cli\",\"zts\",\"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}"
TAG_GRAPHIC="${MAJOR}.${MINOR}-graphic-${{ matrix.mode }}${ENV_MARK}"
mkdir tag
touch "tag/${TAG}"
mkdir tag_graphic
touch "tag_graphic/${TAG_GRAPHIC}"
echo "base=${{ env.IMAGE }}:${TAG}" >> $GITHUB_OUTPUT
echo "graphic=${{ env.IMAGE }}:${TAG_GRAPHIC}" >> $GITHUB_OUTPUT
- name: Save tag
uses: actions/upload-artifact@v3
with:
name: tags
path: tag/*
- name: Save graphic tag
uses: actions/upload-artifact@v3
with:
name: graphic_tags
path: tag_graphic/*
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build base image
uses: docker/build-push-action@v3
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 }}"
"IPE_VERSION=${{ env.IPE_VERSION }}"
"COMPOSER_VERSION=${{ env.COMPOSER_VERSION }}"
"XDEBUG_VERSION=${{ env.XDEBUG_VERSION }}"
"PHPSTAN_VERSION=${{ env.PHPSTAN_VERSION }}"
"MEMCACHED_VERSION=${{ env.MEMCACHED_VERSION }}"
tags: ${{ steps.set-tag.outputs.base }}
- name: Build graphic image
uses: docker/build-push-action@v3
with:
context: .
push: true
file: ./docker/template-graphic.dockerfile
platforms: linux/amd64,linux/arm64
build-args: |
"IMAGE_TAG=${{ steps.set-tag.outputs.base }}"
"CAVIF_VERSION=${{ env.CAVIF_VERSION }}"
tags: ${{ steps.set-tag.outputs.graphic }}
readme:
needs: [ build-image, build-matrix ]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Load tags
uses: actions/download-artifact@v3
with:
name: tags
path: tags
- name: Load graphic tags
uses: actions/download-artifact@v3
with:
name: graphic_tags
path: graphic_tags
- 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)
)
GRAPHIC_TAGS=(
$(find graphic_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]+$//')
LATEST_TAG="${TAGS[0]/-dev/}"
LATEST_GRAPHIC_TAG="${GRAPHIC_TAGS[0]/-dev/}"
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//%%LATEST_TAG%%/$LATEST_TAG}"
README="${README//%%LATEST_GRAPHIC_TAG%%/$LATEST_GRAPHIC_TAG}"
README="${README//%%COMPOSER_VERSION%%/$COMPOSER_VERSION}"
README="${README//%%XDEBUG_VERSION%%/$XDEBUG_VERSION}"
README="${README//%%PHPSTAN_VERSION%%/$PHPSTAN_VERSION}"
README="${README//%%MEMCACHED_VERSION%%/$MEMCACHED_VERSION}"
README="${README//%%REDIS_VERSION%%/$REDIS_VERSION}"
generate_tags_table "${TAGS[@]}"
README="${README//%%TAGS_TABLE%%/$TAGS_TABLE}"
generate_tags_table "${GRAPHIC_TAGS[@]}"
README="${README//%%GRAPHIC_TAGS_TABLE%%/$TAGS_TABLE}"
echo "$README" > README.md
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: ${{ env.IMAGE }}
- name: Git Auto Commit
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Automated Change
file_pattern: '*.md'