133 lines
3.9 KiB
YAML
133 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:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
# This matrix will be dynamically populated by the 'lanes' job
|
|
lane: []
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
# Fetch all history for accurate change detection
|
|
fetch-depth: 0
|
|
|
|
- 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
|
|
|
|
lanes:
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
matrix: ${{ steps.set-matrix.outputs.matrix }}
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- 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
|
|
run: |
|
|
all_lanes='${{ steps.get-lanes.outputs.lanes }}'
|
|
req_lane="${{ github.event.inputs.lane }}"
|
|
|
|
build_all="false"
|
|
|
|
# Handle workflow_dispatch input
|
|
if [[ -n "$req_lane" ]]; then
|
|
if [[ "$req_lane" == "all" ]]; then
|
|
build_all="true"
|
|
else
|
|
# Build only the requested lane
|
|
matrix="{\"lane\":[\"$req_lane\"]}"
|
|
echo "matrix=$matrix" >> $GITHUB_OUTPUT
|
|
exit 0
|
|
fi
|
|
fi
|
|
|
|
# Rebuild all if workflow or shared files changed
|
|
if [[ "${{ steps.changed-files.outputs.any_changed }}" == "true" ]]; then
|
|
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
|
|
if [[ "$file" == ".github/workflows/php-fpm.yml" || "$file" == shared/php-fpm/* ]]; then
|
|
build_all="true"
|
|
break
|
|
fi
|
|
done
|
|
fi
|
|
|
|
if [[ "$build_all" == "true" ]]; then
|
|
matrix="{\"lane\":$all_lanes}"
|
|
else
|
|
# Determine changed lanes from php-fpm directory
|
|
changed_lanes=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep '^php-fpm/' | cut -d'/' -f2 | sort -u | jq -R . | jq -s .)
|
|
matrix="{\"lane\":$changed_lanes}"
|
|
fi
|
|
|
|
echo "matrix=$matrix" >> $GITHUB_OUTPUT
|
|
shell: bash
|