Skip to content

Add auto-skip build for documentation-only changes#75

Merged
toshi0806 merged 4 commits into
mainfrom
auto-skip-docs-build
Nov 3, 2025
Merged

Add auto-skip build for documentation-only changes#75
toshi0806 merged 4 commits into
mainfrom
auto-skip-docs-build

Conversation

@toshi0806
Copy link
Copy Markdown
Member

変更内容

ドキュメントや設定ファイルのみの変更時に、コンテナビルドを自動的にスキップする機能を追加しました。

仕組み

変更されたファイルを分析し、以下のファイルのみの変更の場合はビルドをスキップ:

  • *.md, *.txt (ドキュメントファイル)
  • LICENSE, .gitignore
  • .github/workflows/*.yml (ワークフロー定義)

それ以外のファイル(Dockerfile、ソースコード、ビルドスクリプト等)が変更されている場合は通常通りビルドを実行します。

コミットメッセージタグ(オーバーライド)

ファイル検出よりも優先される明示的な指定:

  • [skip-build]: ビルドを強制スキップ
  • [build]: ライト版をビルド
  • [build-all]: 両バージョンをビルド
  • [build-full]: フル版のみビルド

効果

Before: README.md更新でも1-2時間のビルドが実行される
After: ドキュメントのみの変更は数秒で完了

実装詳細

# 変更ファイルの取得
git diff --name-only HEAD^ HEAD

# 各ファイルをチェック
while IFS= read -r file; do
  if [[ "$file" =~ \.(md|txt)$ ]] || ...; then
    continue  # ビルド不要
  fi
  DOCS_ONLY="false"  # ビルド必要
  break
done

# 判定結果に基づいてBUILD_LITE/BUILD_FULLを設定
if [[ "$DOCS_ONLY" == "true" ]]; then
  BUILD_LITE="false"
  BUILD_FULL="false"
fi

テスト

このPR自体がワークフロー定義のみの変更なので、ビルドがスキップされることを確認できます。

関連

分離前は #74 に含まれていましたが、独立した機能として別PRに分割しました。

Automatically skip container builds when only documentation or non-build
files are changed, significantly reducing CI time and resource usage.

Detection logic:
- Analyzes changed files in each commit
- Skips build if only .md, .txt, LICENSE, .gitignore, or workflow files changed
- Any other file triggers normal build process

Override options (highest priority):
- [skip-build]: Force skip regardless of changed files
- [build]: Force build lite version
- [build-all]: Force build both variants
- [build-full]: Force build full version only

This eliminates unnecessary 1-2 hour builds for README updates while
maintaining safety for actual code changes.
Copilot AI review requested due to automatic review settings November 3, 2025 12:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds automatic build skipping logic to the CI workflow based on changed files, complementing the existing commit message tags. The workflow now detects when only documentation files (.md, .txt, LICENSE, .gitignore, workflow files) are changed and automatically skips builds, unless overridden by commit message tags.

Key changes:

  • Automatic detection of documentation-only changes to skip unnecessary builds
  • New commit message tags: [skip-build] and [build] for explicit control
  • Priority system: commit message tags take precedence over file-based detection

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/build-staged.yml Outdated
Comment on lines +93 to +94
[[ "$file" == ".gitignore" ]] || \
[[ "$file" =~ ^\.github/workflows/.*\.yml$ ]]; then
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern ^\.github/workflows/.*\.yml$ will skip builds when workflow files change, but changes to workflow files should typically trigger builds to validate the workflow changes work correctly. Consider removing workflow files from the skip list or making this configurable.

Suggested change
[[ "$file" == ".gitignore" ]] || \
[[ "$file" =~ ^\.github/workflows/.*\.yml$ ]]; then
[[ "$file" == ".gitignore" ]]; then

Copilot uses AI. Check for mistakes.
Comment thread .github/workflows/build-staged.yml Outdated
BUILD_FULL="true"
elif [[ "$COMMIT_MESSAGE" == *"[build]"* ]]; then
BUILD_LITE="true"
BUILD_FULL="true"
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The [build] tag sets both BUILD_LITE and BUILD_FULL to true without setting PLATFORMS, which means it inherits whatever PLATFORMS was set to earlier (line 113: 'linux/amd64'). This creates inconsistent behavior compared to [build-all] which explicitly sets PLATFORMS. Consider either setting PLATFORMS explicitly here or documenting this difference in behavior.

Suggested change
BUILD_FULL="true"
BUILD_FULL="true"
PLATFORMS="linux/amd64,linux/arm64" # Explicitly set platforms for [build] tag

Copilot uses AI. Check for mistakes.
Comment thread .github/workflows/build-staged.yml Outdated
# Only set if not already configured by [build-all] or [build-full] tag
if [[ "$EVENT_NAME" == "pull_request" && "$COMMIT_MESSAGE" != *"[build-all]"* && "$BUILD_FULL" != "true" ]]; then
# Skip if docs-only or explicitly skipped
if [[ "$EVENT_NAME" == "pull_request" && "$DOCS_ONLY" != "true" && "$COMMIT_MESSAGE" != *"[skip-build]"* && "$COMMIT_MESSAGE" != *"[build-all]"* && "$BUILD_FULL" != "true" ]]; then
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conditional check is complex with 5 different conditions. The logic excludes [build-all] but not [build-full], which means a PR with [build-full] tag would still trigger this block and override the PLATFORMS setting. Consider also checking for [build-full] or using a more maintainable approach to track whether platforms have been explicitly set.

Suggested change
if [[ "$EVENT_NAME" == "pull_request" && "$DOCS_ONLY" != "true" && "$COMMIT_MESSAGE" != *"[skip-build]"* && "$COMMIT_MESSAGE" != *"[build-all]"* && "$BUILD_FULL" != "true" ]]; then
if [[ "$EVENT_NAME" == "pull_request" && "$DOCS_ONLY" != "true" && "$COMMIT_MESSAGE" != *"[skip-build]"* && "$COMMIT_MESSAGE" != *"[build-all]"* && "$COMMIT_MESSAGE" != *"[build-full]"* && "$BUILD_FULL" != "true" ]]; then

Copilot uses AI. Check for mistakes.
- Remove workflow files from skip list (workflows should be tested)
- Add explicit PLATFORMS setting for [build] tag for consistency
- Add [build-full] check to PR default build condition

Addresses review comments in #75
@toshi0806
Copy link
Copy Markdown
Member Author

レビューコメントへの対応

Copilotからの3つの指摘に対応しました(commit: bc3e791

1. ワークフローファイルのスキップリストからの除外

指摘: ワークフロー変更時もビルドをスキップするのは不適切

対応: .github/workflows/*.yml をスキップリストから削除しました。ワークフロー変更時は通常通りビルドが実行されます。

- if [[ "$file" =~ \.(md|txt)$ ]] || \
-    [[ "$file" == "LICENSE" ]] || \
-    [[ "$file" == ".gitignore" ]] || \
-    [[ "$file" =~ ^\.github/workflows/.*\.yml$ ]]; then
+ if [[ "$file" =~ \.(md|txt)$ ]] || \
+    [[ "$file" == "LICENSE" ]] || \
+    [[ "$file" == ".gitignore" ]]; then

2. [build]タグのPLATFORMS明示的設定

指摘: [build]タグが[build-all]と異なりPLATFORMSを明示的に設定していない

対応: [build]タグでも両アーキテクチャをビルドするよう明示的に設定しました。

 elif [[ "$COMMIT_MESSAGE" == *"[build]"* ]]; then
   BUILD_LITE="true"
   BUILD_FULL="true"
+  PLATFORMS="linux/amd64,linux/arm64"  # Build both architectures for [build] tag

3. PRデフォルトビルド条件の改善

指摘: [build-full]タグのチェックが抜けている

対応: [build-full]タグも条件に追加し、明示的にフルビルドを指定した場合はPRデフォルトビルドをスキップするようにしました。

-if [[ "$EVENT_NAME" == "pull_request" && "$DOCS_ONLY" != "true" && "$COMMIT_MESSAGE" != *"[skip-build]"* && "$COMMIT_MESSAGE" != *"[build-all]"* && "$BUILD_FULL" != "true" ]]; then
+if [[ "$EVENT_NAME" == "pull_request" && "$DOCS_ONLY" != "true" && "$COMMIT_MESSAGE" != *"[skip-build]"* && "$COMMIT_MESSAGE" != *"[build-all]"* && "$COMMIT_MESSAGE" != *"[build-full]"* && "$BUILD_FULL" != "true" ]]; then

すべての指摘に対応しました。

@toshi0806 toshi0806 requested a review from Copilot November 3, 2025 12:27
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/build-staged.yml Outdated
Comment on lines +129 to +132
elif [[ "$COMMIT_MESSAGE" == *"[build]"* ]]; then
BUILD_LITE="true"
BUILD_FULL="true"
PLATFORMS="linux/amd64,linux/arm64" # Build both architectures for [build] tag
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The [build] tag has the same behavior as [build-all] (lines 123-126), creating duplicate logic. Consider either removing this redundant tag or documenting the distinction between [build] and [build-all] if they're intended to serve different purposes.

Suggested change
elif [[ "$COMMIT_MESSAGE" == *"[build]"* ]]; then
BUILD_LITE="true"
BUILD_FULL="true"
PLATFORMS="linux/amd64,linux/arm64" # Build both architectures for [build] tag

Copilot uses AI. Check for mistakes.
- Rename [build] to [build-lite] to avoid duplication with [build-all]
- [build-lite]: Build only lite version (both architectures)
- [build-full]: Build only full version
- [build-all]: Build both versions (both architectures)
- [skip-build]: Skip all builds

This creates a clear, non-redundant tag system for workflow control.
@toshi0806 toshi0806 requested a review from Copilot November 3, 2025 12:38
Copy link
Copy Markdown
Member Author

@toshi0806 toshi0806 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I've differentiated the tags to create a clear, non-redundant system:

  • [build-lite]: Build only lite version (both architectures)
  • [build-full]: Build only full version
  • [build-all]: Build both versions (both architectures)
  • [skip-build]: Skip all builds

The previous [build] tag was indeed redundant with [build-all]. Now each tag has a distinct purpose.

Latest commit: c4885e6

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/build-staged.yml Outdated

# Detect changed files for auto-skip detection
if [[ "$EVENT_NAME" == "pull_request" ]]; then
CHANGED_FILES=$(git diff --name-only HEAD^2 HEAD 2>/dev/null || git diff --name-only HEAD^ HEAD)
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback git diff --name-only HEAD^ HEAD will fail silently when there's no parent commit (e.g., initial commit). Consider adding || echo \"\" to the end of line 77 to match the pattern used in line 79, ensuring consistent empty string handling.

Suggested change
CHANGED_FILES=$(git diff --name-only HEAD^2 HEAD 2>/dev/null || git diff --name-only HEAD^ HEAD)
CHANGED_FILES=$(git diff --name-only HEAD^2 HEAD 2>/dev/null || git diff --name-only HEAD^ HEAD 2>/dev/null || echo "")

Copilot uses AI. Check for mistakes.
Fixes #75 - Add empty string fallback to git diff in pull request
detection to handle initial commits gracefully.
@toshi0806
Copy link
Copy Markdown
Member Author

Copilotレビューへの対応完了

全てのレビューコメントに対応しました:

1. ワークフローファイルをスキップリストから削除 ✅

コメント ID: 2486306187

  • ワークフロー定義の変更は検証のためビルドすべき
  • .github/workflows/\*.yml をスキップ対象から削除
  • コミット: bc3e791

2. [build]タグにPLATFORMS明示 ✅

コメント ID: 2486306221

  • [build]タグ使用時のPLATFORMS設定を明示
  • PLATFORMS="linux/amd64,linux/arm64" を追加
  • コミット: bc3e791

3. PRのフル版ビルド条件に[build-full]を追加 ✅

コメント ID: 2486306240

  • [build-full]タグでもPR用フル版ビルドをスキップ
  • 条件に && \$COMMIT_MESSAGE != *"[build-full]"* を追加
  • コミット: bc3e791

4. [build]と[build-all]の重複を解消 ✅

コメント ID: 2486321460

  • [build]を[build-lite]に変更して明確化
  • 各タグの役割を分離:
    • [build-lite]: ライト版のみ(両アーキテクチャ)
    • [build-full]: フル版のみ
    • [build-all]: 両バージョン(両アーキテクチャ)
    • [skip-build]: 全スキップ
  • コミット: c4885e6

5. git diffフォールバックの追加 ✅

コメント ID: 2486355872

  • 初回コミット時の対応として || echo \"\" を追加
  • line 77と79で一貫した空文字列処理
  • コミット: da5171b

全てのレビュー指摘に対応完了しました。マージ準備ができています。

@toshi0806 toshi0806 requested a review from Copilot November 3, 2025 13:02
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@toshi0806 toshi0806 merged commit 3b1c517 into main Nov 3, 2025
11 checks passed
@toshi0806 toshi0806 deleted the auto-skip-docs-build branch November 3, 2025 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants