Add auto-skip build for documentation-only changes#75
Conversation
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.
There was a problem hiding this comment.
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.
| [[ "$file" == ".gitignore" ]] || \ | ||
| [[ "$file" =~ ^\.github/workflows/.*\.yml$ ]]; then |
There was a problem hiding this comment.
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.
| [[ "$file" == ".gitignore" ]] || \ | |
| [[ "$file" =~ ^\.github/workflows/.*\.yml$ ]]; then | |
| [[ "$file" == ".gitignore" ]]; then |
| BUILD_FULL="true" | ||
| elif [[ "$COMMIT_MESSAGE" == *"[build]"* ]]; then | ||
| BUILD_LITE="true" | ||
| BUILD_FULL="true" |
There was a problem hiding this comment.
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.
| BUILD_FULL="true" | |
| BUILD_FULL="true" | |
| PLATFORMS="linux/amd64,linux/arm64" # Explicitly set platforms for [build] tag |
| # 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 |
There was a problem hiding this comment.
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.
| 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 |
- 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
レビューコメントへの対応Copilotからの3つの指摘に対応しました(commit: bc3e791) 1. ワークフローファイルのスキップリストからの除外指摘: ワークフロー変更時もビルドをスキップするのは不適切 対応: - if [[ "$file" =~ \.(md|txt)$ ]] || \
- [[ "$file" == "LICENSE" ]] || \
- [[ "$file" == ".gitignore" ]] || \
- [[ "$file" =~ ^\.github/workflows/.*\.yml$ ]]; then
+ if [[ "$file" =~ \.(md|txt)$ ]] || \
+ [[ "$file" == "LICENSE" ]] || \
+ [[ "$file" == ".gitignore" ]]; then2.
|
There was a problem hiding this comment.
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.
| elif [[ "$COMMIT_MESSAGE" == *"[build]"* ]]; then | ||
| BUILD_LITE="true" | ||
| BUILD_FULL="true" | ||
| PLATFORMS="linux/amd64,linux/arm64" # Build both architectures for [build] tag |
There was a problem hiding this comment.
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.
| elif [[ "$COMMIT_MESSAGE" == *"[build]"* ]]; then | |
| BUILD_LITE="true" | |
| BUILD_FULL="true" | |
| PLATFORMS="linux/amd64,linux/arm64" # Build both architectures for [build] tag |
- 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
left a comment
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
|
|
||
| # 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) |
There was a problem hiding this comment.
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.
| 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 "") |
Fixes #75 - Add empty string fallback to git diff in pull request detection to handle initial commits gracefully.
Copilotレビューへの対応完了全てのレビューコメントに対応しました: 1. ワークフローファイルをスキップリストから削除 ✅コメント ID: 2486306187
2. [build]タグにPLATFORMS明示 ✅コメント ID: 2486306221
3. PRのフル版ビルド条件に[build-full]を追加 ✅コメント ID: 2486306240
4. [build]と[build-all]の重複を解消 ✅コメント ID: 2486321460
5. git diffフォールバックの追加 ✅コメント ID: 2486355872
全てのレビュー指摘に対応完了しました。マージ準備ができています。 |
There was a problem hiding this comment.
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.
変更内容
ドキュメントや設定ファイルのみの変更時に、コンテナビルドを自動的にスキップする機能を追加しました。
仕組み
変更されたファイルを分析し、以下のファイルのみの変更の場合はビルドをスキップ:
*.md,*.txt(ドキュメントファイル)LICENSE,.gitignore.github/workflows/*.yml(ワークフロー定義)それ以外のファイル(Dockerfile、ソースコード、ビルドスクリプト等)が変更されている場合は通常通りビルドを実行します。
コミットメッセージタグ(オーバーライド)
ファイル検出よりも優先される明示的な指定:
[skip-build]: ビルドを強制スキップ[build]: ライト版をビルド[build-all]: 両バージョンをビルド[build-full]: フル版のみビルド効果
Before: README.md更新でも1-2時間のビルドが実行される
After: ドキュメントのみの変更は数秒で完了
実装詳細
テスト
このPR自体がワークフロー定義のみの変更なので、ビルドがスキップされることを確認できます。
関連
分離前は #74 に含まれていましたが、独立した機能として別PRに分割しました。