Files
docker-php-with-imagick-multi/.github/workflows/pr-build.yml
renovate[bot] 90133bc884 chore(deps): update docker/metadata-action action (v5.8.0 → v5.9.0) (#58)
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-11-24 20:58:01 +00:00

192 lines
6.2 KiB
YAML

---
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: PR Build and Report
on:
pull_request:
types: [opened, synchronize, reopened]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
permissions: read-all
jobs:
pr-build:
name: PR Build
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
issues: write
pull-requests: write
statuses: write
strategy:
fail-fast: false
matrix:
php: [php74, php80, php81, php82, php83, php84]
arch: ["linux/amd64", "linux/arm64"]
steps:
- uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5.0.1
- name: Set result filename
id: resultfile
run: |
TAG_ARCH="${{ matrix.arch }}"
TAG_ARCH="${TAG_ARCH//\//-}"
FILENAME="result-${{ matrix.php }}-${TAG_ARCH}.json"
echo "filename=$FILENAME" >> "$GITHUB_OUTPUT"
echo "tag_arch=$TAG_ARCH" >> "$GITHUB_OUTPUT"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
- name: Log in to the Container registry
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker metadata
id: meta
uses: docker/metadata-action@318604b99e75e41977312d83839a89be02ca4893 # v5.9.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.php }}
tags: |
type=raw,value=${{ matrix.php }}-${{ matrix.arch }}
- name: Extract base image
id: baseimage
run: |
BASE_IMAGE="$(grep -m1 '^FROM ' ${{ env.DOCKERFILE_PATH }} | awk '{print $2}')"
echo "base_image=$BASE_IMAGE" >> "$GITHUB_OUTPUT"
- name: Build Docker image (capture cache usage)
id: build
shell: bash
run: |
TAG_ARCH="${{ steps.resultfile.outputs.tag_arch }}"
IMAGE_TAG="${{ env.IMAGE_NAME }}:${{ matrix.php }}-${TAG_ARCH}"
START="$(date +%s)"
docker buildx build \
--platform ${{ matrix.arch }} \
--tag "$IMAGE_TAG" \
--progress plain \
--load ./${{ matrix.php }}/ | tee build.log
END="$(date +%s)"
echo "duration=$((END-START))" >> "$GITHUB_OUTPUT"
if grep -q 'CACHED' build.log; then
echo "cache_used=true" >> "$GITHUB_OUTPUT"
else
echo "cache_used=false" >> "$GITHUB_OUTPUT"
fi
- name: Get image size
id: image_info
shell: bash
run: |
TAG_ARCH="${{ steps.resultfile.outputs.tag_arch }}"
IMAGE="${{ env.IMAGE_NAME }}:${{ matrix.php }}-${TAG_ARCH}"
SIZE="$(docker image inspect "$IMAGE" --format='{{.Size}}')"
SIZE_MB="$((SIZE/1024/1024))"
echo "size_mb=$SIZE_MB" >> "$GITHUB_OUTPUT"
- name: Save build result
shell: bash
run: |
jq -n \
--arg php "${{ matrix.php }}" \
--arg arch "${{ matrix.arch }}" \
--arg status "success" \
--arg duration "${{ steps.build.outputs.duration }}" \
--arg size_mb "${{ steps.image_info.outputs.size_mb }}" \
--arg base_image "${{ steps.baseimage.outputs.base_image }}" \
--arg cache_used "${{ steps.build.outputs.cache_used }}" \
'{
php: $php,
arch: $arch,
status: $status,
duration: $duration,
size_mb: $size_mb,
base_image: $base_image,
cache_used: $cache_used
}' > ${{ steps.resultfile.outputs.filename }}
- name: Move result file to output directory
shell: bash
run: |
mkdir -p results
mv ${{ steps.resultfile.outputs.filename }} results/
- name: Upload build result
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: build-results-${{ steps.resultfile.outputs.filename }}
path: results/
overwrite: true
if-no-files-found: warn
aggregate-results:
name: Aggregate Results and Comment
runs-on: ubuntu-latest
needs: pr-build
permissions:
contents: read
issues: write
pull-requests: write
statuses: write
if: github.event_name == 'pull_request'
steps:
- name: Download all build results
id: dl
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
with:
path: results
- name: Summarize results
id: summarize
shell: bash
run: |
set -x
{
echo "## Build Matrix Results"
echo ""
echo "| PHP Version | Architecture | Status | Duration (s) | Image Size (MB) | Base Image | Cache Used |"
echo "|-------------|--------------|---------|--------------|-----------------|------------|------------|"
} > comment.md
for f in ${{ steps.dl.outputs.download-path }}/**/*.json; do
echo "debug"
cat "$f"
echo "/debug"
php=$(jq -r .php "$f")
arch=$(jq -r .arch "$f")
status=$(jq -r .status "$f")
duration=$(jq -r .duration "$f")
size_mb=$(jq -r .size_mb "$f")
base_image=$(jq -r .base_image "$f")
cache_used=$(jq -r .cache_used "$f")
echo "| $php | $arch | $status | $duration | $size_mb | $base_image | $cache_used |" >> comment.md
done
- name: Create or update PR comment
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body-file: comment.md