132 lines
4.1 KiB
YAML
132 lines
4.1 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.result }}
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- 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: Get all PHP lanes
|
|
id: get-lanes
|
|
run: |
|
|
echo "lanes=$(find php-fpm -mindepth 1 -maxdepth 1 -type d -exec basename {} \; | jq -c -R . | jq -c -s .)" >> $GITHUB_OUTPUT
|
|
shell: bash
|
|
|
|
- name: Get changed PHP lanes
|
|
id: changed-lanes
|
|
run: |
|
|
changed_lanes=$(echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep '^php-fpm/' || true | cut -d'/' -f2 | sort -u | jq -c -R . | jq -c -s .)
|
|
echo "lanes=${changed_lanes:-[]}" >> $GITHUB_OUTPUT
|
|
shell: bash
|
|
|
|
- name: Check for changes requiring all lanes to be built
|
|
id: build-all-check
|
|
run: |
|
|
if echo "${{ steps.changed-files.outputs.all_changed_files }}" | tr ' ' '\n' | grep -q -e '^\.github/workflows/' -e '^shared/php-fpm/'; then
|
|
echo "build_all=true"
|
|
else
|
|
echo "build_all=false"
|
|
fi >> $GITHUB_OUTPUT
|
|
shell: bash
|
|
|
|
- name: Generate matrix for build job
|
|
id: set-matrix
|
|
uses: actions/github-script@v7
|
|
with:
|
|
result-encoding: json
|
|
script: |
|
|
const req_lane = "${{ github.event.inputs.lane }}";
|
|
const build_all = ${{ steps.build-all-check.outputs.build_all == 'true' }};
|
|
const all_lanes = JSON.parse('${{ steps.get-lanes.outputs.lanes }}' || '[]');
|
|
const changed_lanes = JSON.parse('${{ steps.changed-lanes.outputs.lanes }}' || '[]');
|
|
|
|
let lanes_to_build = [];
|
|
|
|
if (req_lane) {
|
|
if (req_lane === "all") {
|
|
lanes_to_build = all_lanes;
|
|
} else {
|
|
lanes_to_build = [req_lane];
|
|
}
|
|
} else if (build_all) {
|
|
lanes_to_build = all_lanes;
|
|
} else {
|
|
lanes_to_build = changed_lanes;
|
|
}
|
|
|
|
return { lane: lanes_to_build };
|
|
|
|
build:
|
|
needs: lanes
|
|
if: ${{ needs.lanes.outputs.matrix != '' && needs.lanes.outputs.matrix.lane[0] }}
|
|
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
|