Skip to content

Commit f6cd622

Browse files
author
gptkong
committed
refactor GitHub Actions workflow for Docker builds; add support for manual triggers and specific directory builds, and remove unused Dockerfile for Lucide Icon documentation
1 parent 36ace2b commit f6cd622

File tree

2 files changed

+47
-25
lines changed

2 files changed

+47
-25
lines changed

.github/workflows/docker-build-all.yml

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
name: Build All Docker Images
1+
name: Build Docker Images
22

33
on:
44
push:
55
branches: [ "main", "master" ]
6+
paths:
7+
- '**/Dockerfile'
8+
- '**/*.dockerfile'
9+
- '.github/workflows/docker-build-all.yml'
610
pull_request:
711
branches: [ "main", "master" ]
12+
paths:
13+
- '**/Dockerfile'
14+
- '**/*.dockerfile'
15+
- '.github/workflows/docker-build-all.yml'
816
# 允许手动触发工作流
917
workflow_dispatch:
18+
inputs:
19+
specific_dir:
20+
description: '指定构建目录(可选,留空构建所有变更的目录)'
21+
required: false
22+
type: string
1023

1124
env:
1225
REGISTRY: ghcr.io
@@ -19,15 +32,45 @@ jobs:
1932
steps:
2033
- name: Checkout repository
2134
uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 2
2237

23-
- name: Get all dockerfile directories
38+
- name: Get changed dockerfile directories
2439
id: set-matrix
2540
run: |
26-
DIRS=$(find . -name Dockerfile -type f -exec dirname {} \; | sed 's|^\./||' | jq -R -s -c 'split("\n")[:-1]')
27-
echo "matrix=${DIRS}" >> $GITHUB_OUTPUT
41+
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.specific_dir }}" ]; then
42+
# 如果是手动触发并指定了目录,只构建指定目录
43+
if [ -f "${{ github.event.inputs.specific_dir }}/Dockerfile" ]; then
44+
echo "matrix=[\"${{ github.event.inputs.specific_dir }}\"]" >> $GITHUB_OUTPUT
45+
else
46+
echo "Error: Specified directory does not contain a Dockerfile"
47+
exit 1
48+
fi
49+
else
50+
# 获取变更的文件列表
51+
if [ "${{ github.event_name }}" = "pull_request" ]; then
52+
git fetch origin ${{ github.base_ref }}
53+
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)
54+
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
55+
# 手动触发且未指定目录时,获取所有 Dockerfile
56+
CHANGED_FILES=$(find . -name Dockerfile)
57+
else
58+
CHANGED_FILES=$(git diff --name-only HEAD^ HEAD)
59+
fi
60+
61+
# 提取包含 Dockerfile 的目录
62+
DIRS=$(echo "$CHANGED_FILES" | grep -E "Dockerfile$" | xargs -I {} dirname {} | sed 's|^\./||' | sort -u | jq -R -s -c 'split("\n")[:-1]')
63+
if [ "$DIRS" = "[]" ] || [ -z "$DIRS" ]; then
64+
echo "No Dockerfile changes detected"
65+
echo "matrix=[]" >> $GITHUB_OUTPUT
66+
else
67+
echo "matrix=$DIRS" >> $GITHUB_OUTPUT
68+
fi
69+
fi
2870
2971
build:
3072
needs: prepare
73+
if: fromJson(needs.prepare.outputs.matrix)[0] != null
3174
runs-on: ubuntu-latest
3275
strategy:
3376
matrix:

lucide-icon-docs/Dockerfile

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)