Skip to content

Update GHA build workflow to build images on PRs, cleanup old images #18

Update GHA build workflow to build images on PRs, cleanup old images

Update GHA build workflow to build images on PRs, cleanup old images #18

Workflow file for this run

name: Build and Publish Docker Image
permissions:
contents: read
packages: write
on:
pull_request:
workflow_dispatch:
push:
branches:
- main
schedule:
- cron: 43 2 * * 0
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build initial image
uses: docker/build-push-action@v6
with:
cache-from: type=gha
cache-to: type=gha,mode=max
pull: true
load: true
tags: build-chromium
- name: Determine version of Chromium obtained
env:
CHROMIUM_VERSION_REGEXP: 'Chromium ([0-9]+)\.'
run: |
CURRENT_CHROMIUM_VERSION=$(docker container run --rm build-chromium --version)
if [[ ${CURRENT_CHROMIUM_VERSION} =~ ${CHROMIUM_VERSION_REGEXP} ]]; then
echo "ℹ Successfully extracted Chromium major version of ${BASH_REMATCH[1]} from '${CURRENT_CHROMIUM_VERSION}'"
else
echo "❌ Cannot extract Chromium major version from '${CURRENT_CHROMIUM_VERSION}'" >&2
exit 1
fi
echo "CHROMIUM_VERSION=${BASH_REMATCH[1]}" >> $GITHUB_ENV
- name: Build cross-platform images and push to registry
if: github.event_name != 'pull_request'
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
push: true
tags: |
ghcr.io/webfactory/alpine-chromium:latest
ghcr.io/webfactory/alpine-chromium:${{ env.CHROMIUM_VERSION }}
labels: org.opencontainers.image.source=https://github.com/webfactory/docker-alpine-chromium
env:
DOCKER_BUILD_SUMMARY: false
DOCKER_BUILD_RECORD_UPLOAD: false
- 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: alpine-chromium
owner_type: org
untagged_only: true