Skip to content

Build and Publish Docker Image #130

Build and Publish Docker Image

Build and Publish Docker Image #130

Workflow file for this run

name: Build and Publish Docker Image
permissions:
contents: read
packages: write
on:
push:
branches:
- main
schedule:
- cron: '43 2 * * 0'
pull_request:
workflow_dispatch:
inputs:
composer-require-checkerVersion:
description: 'composer-require-checker version to build'
required: true
default: 'null'
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Determine composer-require-checker version to build
run: |
if [[ -z "$COMPOSER_REQUIRE_CHECKER_VERSION" ]]; then
COMPOSER_REQUIRE_CHECKER_VERSION=`curl -sL https://api.github.com/repos/maglnet/ComposerRequireChecker/releases/latest | jq -r ".tag_name" | sed -e 's/^v//'`
fi
if [[ "$COMPOSER_REQUIRE_CHECKER_VERSION" == "null" ]]; then
echo "Failed to determine composer-require-checker version to build"
exit 1
fi
echo "Building composer-require-checker version $COMPOSER_REQUIRE_CHECKER_VERSION"
echo "COMPOSER_REQUIRE_CHECKER_VERSION=$COMPOSER_REQUIRE_CHECKER_VERSION" >> $GITHUB_ENV
env:
COMPOSER_REQUIRE_CHECKER_VERSION: ${{ github.event.inputs.composer-require-checkerVersion }}
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker Image
uses: docker/build-push-action@v6
with:
build-args: VERSION=${{ env.COMPOSER_REQUIRE_CHECKER_VERSION }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
pull: true
- name: Load image for current platform into local Docker
uses: docker/build-push-action@v6
with:
build-args: VERSION=${{ env.COMPOSER_REQUIRE_CHECKER_VERSION }}
cache-from: type=gha
load: true
tags: build
- name: Run smoke tests
run: |
# Check "composer-require-checker --version" output
docker run --rm build --version | grep -q $COMPOSER_REQUIRE_CHECKER_VERSION
- name: Push image to registry
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v6
with:
build-args: VERSION=${{ env.COMPOSER_REQUIRE_CHECKER_VERSION }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
push: true
tags: ghcr.io/webfactory/composer-require-checker:${{ env.COMPOSER_REQUIRE_CHECKER_VERSION }}
labels: org.opencontainers.image.source=https://github.com/webfactory/docker-composer-require-checker
- name: Delete potentially remaining, untagged container images
if: github.event_name != 'pull_request'
uses: Chizkiyahu/delete-untagged-ghcr-action@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
package_name: composer-require-checker
owner_type: org
untagged_only: true