Skip to content

CI & Build PHPQA

CI & Build PHPQA #64

Workflow file for this run

name: CI & Build PHPQA
on:
push:
branches: [main]
tags: ["*"]
workflow_dispatch:
schedule:
- cron: '19 2 * * 0'
env:
IMAGE_NAME_BASE: ghcr.io/${{ github.repository_owner }}/phpqa
DESCRIPTION: "PHPQA Docker image with tools for static analysis, code style checks, and testing"
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
is_tag: ${{ steps.tag.outputs.is_tag }}
version: ${{ steps.tag.outputs.version }}
major: ${{ steps.tag.outputs.major }}
minor: ${{ steps.tag.outputs.minor }}
short_sha: ${{ steps.sha.outputs.short }}
image_name: ${{ steps.normalize.outputs.name }}
is_scheduled: ${{ steps.scheduled.outputs.is_scheduled }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Extract short SHA
id: sha
run: echo "short=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
- name: Extract version from tag
id: tag
run: |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
version="${GITHUB_REF#refs/tags/}"
major=$(cut -d. -f1 <<< "$version")
minor=$(cut -d. -f2 <<< "$version")
echo "is_tag=true" >> "$GITHUB_OUTPUT"
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "major=$major" >> "$GITHUB_OUTPUT"
echo "minor=$minor" >> "$GITHUB_OUTPUT"
else
echo "is_tag=false" >> "$GITHUB_OUTPUT"
fi
- name: Normalize image name
id: normalize
run: echo "name=${IMAGE_NAME_BASE,,}" >> "$GITHUB_OUTPUT"
- name: Check if run is scheduled
id: scheduled
run: echo "is_scheduled=${{ github.event_name == 'schedule' }}" >> "$GITHUB_OUTPUT"
build-amd64:
needs: prepare
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [8.2, 8.3, 8.4, 8.5]
continue-on-error: ${{ matrix.php == '8.5' }}
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
with:
install: true
driver-opts: image=moby/buildkit:latest
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push AMD64
run: |
IMAGE=${{ needs.prepare.outputs.image_name }}:${{ matrix.php }}-amd64
docker buildx build \
--platform=linux/amd64 \
--build-arg PHP_VERSION=${{ matrix.php }} \
--label org.opencontainers.image.description="${{ env.DESCRIPTION }}" \
--cache-from=type=gha \
--cache-to=type=gha,mode=max \
--push \
-t $IMAGE .
build-arm64:
needs: prepare
runs-on: ubuntu-22.04-arm
strategy:
fail-fast: false
matrix:
php: [8.2, 8.3, 8.4, 8.5]
continue-on-error: ${{ matrix.php == '8.5' }}
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
with:
install: true
driver-opts: image=moby/buildkit:latest
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push ARM64
run: |
IMAGE=${{ needs.prepare.outputs.image_name }}:${{ matrix.php }}-arm64
docker buildx build \
--platform=linux/arm64 \
--build-arg PHP_VERSION=${{ matrix.php }} \
--label org.opencontainers.image.description="${{ env.DESCRIPTION }}" \
--cache-from=type=gha \
--cache-to=type=gha,mode=max \
--push \
-t $IMAGE .
manifest:
needs: [build-amd64, build-arm64, prepare]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [8.2, 8.3, 8.4, 8.5]
continue-on-error: ${{ matrix.php == '8.5' }}
steps:
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Merge and push Docker manifest
run: |
IMAGE=${{ needs.prepare.outputs.image_name }}
VERSION=${{ matrix.php }}
docker buildx imagetools create \
--tag $IMAGE:$VERSION \
--tag $IMAGE:$VERSION-${{ needs.prepare.outputs.short_sha }} \
$IMAGE:$VERSION-amd64 \
$IMAGE:$VERSION-arm64
# Tag :latest for the latest stable version (currently 8.4)
if [[ "$VERSION" == "8.4" ]]; then
docker buildx imagetools create \
--tag $IMAGE:latest \
$IMAGE:$VERSION-amd64 \
$IMAGE:$VERSION-arm64
fi
# Tag version if pushed
if [[ "${{ needs.prepare.outputs.is_tag }}" == "true" && "${{ needs.prepare.outputs.version }}" == "$VERSION" ]]; then
docker buildx imagetools create \
--tag $IMAGE:${{ needs.prepare.outputs.version }} \
--tag $IMAGE:${{ needs.prepare.outputs.major }} \
--tag $IMAGE:${{ needs.prepare.outputs.major }}.${{ needs.prepare.outputs.minor }} \
$IMAGE:$VERSION-amd64 \
$IMAGE:$VERSION-arm64
fi
# Weekly tag for scheduled builds
if [[ "${{ needs.prepare.outputs.is_scheduled }}" == "true" ]]; then
docker buildx imagetools create \
--tag $IMAGE:$VERSION-weekly \
$IMAGE:$VERSION-amd64 \
$IMAGE:$VERSION-arm64
fi