--- # 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 / 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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - 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@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0 - 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@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.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@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 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@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.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