fix: workflow
All checks were successful
images-build-and-push / build (., debian-12.dockerfile, xdu/debian:bookworm , debian-12) (push) Successful in 1m11s
images-build-and-push / build (., debian.dockerfile, xdu/debian:latest xdu/debian:trixie , debian) (push) Successful in 40s
images-build-and-push / build (., ffmpeg-debian.dockerfile, xdu/ffmpeg:debian xdu/ffmpeg:latest , ffmpeg) (push) Successful in 3m27s
images-build-and-push / build (., ubuntu.dockerfile, xdu/ubuntu:latest xdu/ubuntu:25.10 , ubuntu) (push) Successful in 1m13s

This commit is contained in:
xkm
2025-10-16 19:47:10 +08:00
parent 05fe3d7848
commit 4b0e09e307

View File

@@ -3,6 +3,7 @@ name: images-build-and-push
on:
push:
branches: [ "main" ]
workflow_dispatch: {}
env:
REGISTRY: ${{ secrets.REGISTRY }}
@@ -11,64 +12,46 @@ env:
jobs:
build:
runs-on: docker
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: debian
context: dockerfiles
dockerfile: dockerfiles/debian.dockerfile
watch: |
dockerfiles/debian.dockerfile
context: .
dockerfile: debian.dockerfile
image: |
xdu/debian:latest
xdu/debian:trixie
- name: debian-12
context: dockerfiles
dockerfile: dockerfiles/debian-12.dockerfile
watch: |
dockerfiles/debian-12.dockerfile
image:
context: .
dockerfile: debian-12.dockerfile
image: |
xdu/debian:bookworm
- name: ubuntu
context: dockerfiles
dockerfile: dockerfiles/ubuntu.dockerfile
watch: |
dockerfiles/ubuntu.dockerfile
image:
context: .
dockerfile: ubuntu.dockerfile
image: |
xdu/ubuntu:latest
xdu/ubuntu:25.10
- name: ffmpeg
context: .
dockerfile: ffmpeg-debian.dockerfile
image: |
xdu/ffmpeg:debian
xdu/ffmpeg:latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Decide base commit
id: base
shell: bash
run: |
BASE="$(git rev-parse HEAD^ 2>/dev/null || true)"
if [ -z "$BASE" ]; then BASE="$(git rev-list --max-parents=0 HEAD)"; fi
echo "base=$BASE" >> $GITHUB_OUTPUT
- name: Check if changed
id: changed
shell: bash
run: |
CHANGED=false
while IFS= read -r p; do
[ -z "$p" ] && continue
if git diff --name-only "${{ steps.base.outputs.base }}"...HEAD -- "$p" | grep -q .; then
CHANGED=true; break
fi
done <<< "${{ matrix.watch }}"
echo "changed=$CHANGED" >> $GITHUB_OUTPUT
with:
fetch-depth: 1
- name: Login to registry
if: steps.changed.outputs.changed == 'true'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
@@ -76,11 +59,9 @@ jobs:
password: ${{ env.REGISTRY_PASSWORD }}
- name: Prepare tags & cache repo
if: steps.changed.outputs.changed == 'true'
id: meta
shell: bash
run: |
# 将 matrix.image 多行转为带 REGISTRY 前缀的完整 tags
FULL_TAGS=""
FIRST_REPO=""
while IFS= read -r line; do
@@ -91,7 +72,6 @@ jobs:
FIRST_REPO="${{ env.REGISTRY }}/$(echo "$line" | cut -d: -f1)"
fi
done <<< "${{ matrix.image }}"
{
echo "tags<<__TAGS__"
printf "%s" "$FULL_TAGS"
@@ -99,8 +79,7 @@ jobs:
echo "cache_repo=$FIRST_REPO"
} >> "$GITHUB_OUTPUT"
- name: Build & Push
if: steps.changed.outputs.changed == 'true'
- name: Build & Push (always)
uses: docker/build-push-action@v5
with:
context: ${{ matrix.context }}
@@ -109,7 +88,3 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=registry,ref=${{ steps.meta.outputs.cache_repo }}:buildcache
cache-to: type=registry,ref=${{ steps.meta.outputs.cache_repo }}:buildcache,mode=max
- name: Skip (no changes)
if: steps.changed.outputs.changed != 'true'
run: echo "No changes in watch list for ${{ matrix.name }}, skipping."