Files
wordpress-docker/.github/workflows/php-fpm.yml
Elijah Duffy cc2a467c17
Some checks failed
php-fpm-build / lanes (push) Failing after 46s
php-fpm-build / build (push) Has been skipped
php-fpm: supposedly fixed the matrix output haha
2025-12-07 23:52:56 -08:00

131 lines
3.9 KiB
YAML

name: php-fpm-build
on:
push:
branches: [main]
paths:
- "php-fpm/**"
- "shared/php-fpm/**"
- ".github/workflows/php-fpm.yml"
pull_request:
branches: [main]
paths:
- "php-fpm/**"
- "shared/php-fpm/**"
- ".github/workflows/php-fpm.yml"
workflow_dispatch:
inputs:
lane:
description: 'Lane to build (e.g. 7.4). Use "all" to build all lanes. Leave blank to build based on changes.'
required: false
default: ""
jobs:
lanes:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for accurate change detection
- name: Get all PHP lanes
id: get-lanes
run: |
lanes=$(find php-fpm -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | jq -R . | jq -s .)
echo "lanes=$lanes" >> $GITHUB_OUTPUT
shell: bash
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v44
with:
files: |
php-fpm/**
shared/php-fpm/**
.github/workflows/php-fpm.yml
- name: Determine lanes to build
id: set-matrix
shell: bash
run: |
all_lanes='${{ steps.get-lanes.outputs.lanes }}'
req_lane="${{ github.event.inputs.lane }}"
changed_files="${{ steps.changed-files.outputs.all_changed_files }}"
lanes_to_build="[]"
build_all=false
# 1. Handle workflow_dispatch input
if [[ -n "$req_lane" ]]; then
if [[ "$req_lane" == "all" ]]; then
build_all=true
else
lanes_to_build="[\"$req_lane\"]"
fi
else
# 2. Check for changes that trigger a full rebuild
for file in $changed_files; do
if [[ "$file" == ".github/workflows/php-fpm.yml" || "$file" == shared/php-fpm/* ]]; then
build_all=true
break
fi
done
fi
# 3. Build matrix based on flags
if [[ "$build_all" == true ]]; then
lanes_to_build="$all_lanes"
elif [[ -n "$changed_files" && "$lanes_to_build" == "[]" ]]; then
# 4. If not a full build, determine changed lanes
lanes=$(echo "$changed_files" | tr ' ' '\n' | grep '^php-fpm/' | cut -d'/' -f2 | sort -u | jq -R . | jq -s .)
if [[ -n "$lanes" && "$lanes" != "[]" ]]; then
lanes_to_build="$lanes"
fi
fi
matrix="{\"lane\":$lanes_to_build}"
echo "matrix=$matrix" >> $GITHUB_OUTPUT
build:
needs: lanes
if: ${{ needs.lanes.outputs.matrix != '{"lane":[]}' }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.lanes.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container Registry
uses: docker/login-action@v3
with:
registry: gitea.auvem.com
username: ${{ vars.REGISTRY_USER || github.actor }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: gitea.auvem.com/auvem/wordpress-docker/php-fpm
tags: |
type=raw,value={{matrix.lane}}-stable
type=raw,value={{matrix.lane}}-{{sha}}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
file: ./php-fpm/${{ matrix.lane }}/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64