Files
grimmory/.github/workflows/preview-image.yml
T
dependabot[bot] 851fa40c98 chore(deps): bump docker/setup-buildx-action from 4.0.0 to 4.1.0 (#1648)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-06-07 09:00:47 +01:00

103 lines
3.2 KiB
YAML

name: Preview - Build Image
on:
workflow_dispatch:
inputs:
ref:
description: 'Git ref to preview build'
required: true
type: string
pr_number:
description: 'Optional PR number for a pr-<number>-<sha> tag'
required: false
default: ''
type: string
refresh_shared_cache:
description: 'Rebuild from scratch and refresh the shared image cache'
required: false
default: false
type: boolean
jobs:
build-and-push:
name: Build and Push Preview Image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout Repository
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
fetch-depth: 1
ref: ${{ inputs.ref }}
- name: Generate Preview Tag
env:
PR_NUMBER: ${{ inputs.pr_number }}
run: |
short_sha=$(git rev-parse --short HEAD)
if [ -n "$PR_NUMBER" ]; then
case "$PR_NUMBER" in
(*[!0-9]*)
echo "Invalid PR number: $PR_NUMBER"
exit 1
;;
esac
preview_tag="pr-${PR_NUMBER}-${short_sha}"
else
preview_tag="preview-${short_sha}"
fi
echo "preview_tag=$preview_tag" >> "$GITHUB_ENV"
echo "commit_sha=$(git rev-parse HEAD)" >> "$GITHUB_ENV"
echo "Preview tag: $preview_tag"
- name: Set Up Docker Buildx
uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0
- name: Authenticate to GitHub Container Registry
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Build and push Preview image
if: ${{ !inputs.refresh_shared_cache }}
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
with:
context: .
file: Dockerfile
platforms: linux/amd64
push: true
tags: |
ghcr.io/grimmory-tools/grimmory:${{ env.preview_tag }}
build-args: |
APP_VERSION=${{ env.preview_tag }}
APP_REVISION=${{ env.commit_sha }}
cache-from: |
type=gha,scope=image-shared
type=registry,ref=ghcr.io/grimmory-tools/grimmory:buildcache
- name: Build and push Preview image with cache refresh
if: ${{ inputs.refresh_shared_cache }}
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
with:
context: .
file: Dockerfile
platforms: linux/amd64
push: true
no-cache: true
tags: |
ghcr.io/grimmory-tools/grimmory:${{ env.preview_tag }}
build-args: |
APP_VERSION=${{ env.preview_tag }}
APP_REVISION=${{ env.commit_sha }}
cache-to: |
type=gha,scope=image-shared,mode=max
type=registry,ref=ghcr.io/grimmory-tools/grimmory:buildcache,mode=max