GitHub リポジトリから指定されたファイルを YAML 設定に基づいてローカルに同期するPythonツールです。環境変数の置換機能も提供します。
- 複数のGitHubリポジトリから複数のファイルを一括ダウンロード
- プライベートリポジトリのサポート(GitHub token使用)
- ダウンロードしたファイル内での環境変数置換
- 外部ファイルからの環境変数定義読み込み
- ドライランモード(実際にファイルを作成せずに動作確認)
- ディレクトリ構造の保持オプション
- 接続テスト機能
# 依存関係のインストール
uv sync
# 開発用依存関係も含める場合
uv sync --group devenvs_file: repo-file-sync.envs.yaml
sources:
- repo: owner/repository-name
ref: main
files:
- README.md
- LICENSE
- repo: another-owner/another-repo
ref: v1.0.0
files:
- config/settings.yaml- name: OLD_VALUE
value: NEW_VALUE
- name: actions/checkout
value: awesome-checkout-action
- name: PROJECT_NAME
value: "My Awesome Project"このツールは GitHub Action として簡単に使用できます:
# .github/workflows/sync-files.yml
name: Sync Repository Files
on:
schedule:
- cron: '0 0 * * *' # 毎日実行
workflow_dispatch: # 手動実行も可能
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Sync files from other repositories
uses: StudistCorporation/actions-repo-file-sync@main
with:
config: '.github/repo-file-sync.yaml'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Commit synced files
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add ./synced-files
git diff --staged --quiet || git commit -m "🔄 Sync files from repositories"
git push# .github/workflows/sync-files-pr.yml
name: Sync Repository Files with PR
on:
schedule:
- cron: '0 0 * * *' # 毎日実行
workflow_dispatch: # 手動実行も可能
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Sync files and create PR
uses: StudistCorporation/actions-repo-file-sync@main
with:
config: '.github/repo-file-sync.yaml'
github-token: ${{ secrets.GITHUB_TOKEN }}
create-pr: true
pr-title: '🔄 Sync files from repositories'
pr-body: |
Automated file sync from configured repositories.
Files have been updated based on the latest versions from source repositories.
branch-name: 'sync/repo-files'name: Advanced File Sync with Custom PR
on:
workflow_dispatch:
inputs:
dry-run:
description: 'Run in dry-run mode'
required: false
default: false
type: boolean
create-pr:
description: 'Create pull request'
required: false
default: true
type: boolean
branch-name:
description: 'Branch name for PR'
required: false
default: 'sync/repo-files'
type: string
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Sync files with advanced options
uses: StudistCorporation/actions-repo-file-sync@main
with:
config: '.github/custom-sync-config.yaml'
github-token: ${{ secrets.PAT_TOKEN }} # カスタムトークン
dry-run: ${{ github.event.inputs.dry-run }}
create-pr: ${{ github.event.inputs.create-pr }}
pr-title: '🔄 Custom sync: ${{ github.event.inputs.branch-name }}'
pr-body: |
Automated file sync triggered manually.
- Branch: ${{ github.event.inputs.branch-name }}
- Dry run: ${{ github.event.inputs.dry-run }}
- Triggered by: @${{ github.actor }}
branch-name: ${{ github.event.inputs.branch-name }}
id: sync
- name: Show sync results
run: |
echo "Files synced: ${{ steps.sync.outputs.files-synced }}"| パラメータ | 説明 | 必須 | デフォルト |
|---|---|---|---|
config |
設定ファイルのパス | No | .github/repo-file-sync.yaml |
github-token |
GitHubトークン | No | ${{ github.token }} |
dry-run |
ドライランモード | No | false |
create-pr |
プルリクエストを作成する | No | false |
pr-title |
プルリクエストのタイトル | No | 🔄 Sync files from repositories |
pr-body |
プルリクエストの説明文 | No | Automated file sync from configured repositories |
branch-name |
プルリクエスト用のブランチ名 | No | sync/repo-files |
| パラメータ | 説明 |
|---|---|
files-synced |
同期されたファイル一覧(形式: repo:file,repo:file) |
# デフォルト設定でファイルを同期
uv run python -m src.cli
# カスタム設定ファイルを使用
uv run python -m src.cli --config custom-config.yaml
# カスタム出力ディレクトリを指定
uv run python -m src.cli --output ./downloads
# 詳細ログを表示
uv run python -m src.cli --verbose# GitHub tokenを環境変数で設定
export GITHUB_TOKEN=ghp_your_token_here
uv run python -m src.cli# ドライラン(実際にファイルを作成しない)
uv run python -m src.cli --dry-run
# リポジトリのディレクトリ構造を保持
uv run python -m src.cli --preserve-structure
# 接続テスト
uv run python -m src.cli --test-connection
# プルリクエストを作成
uv run python -m src.cli --create-pr
# カスタムPRタイトルとブランチ名
uv run python -m src.cli --create-pr --pr-title "Custom sync" --branch-name "feature/sync"
# タイムアウトを設定(秒)
uv run python -m src.cli --timeout 60
# ヘルプを表示
uv run python -m src.cli --helpダウンロードしたファイル内で文字列の置換が行われます:
name: actions/checkout
version: v4
project: PROJECT_NAMEname: awesome-checkout-action
version: v4
project: My Awesome Project# 全テストを実行
uv run pytest
# 詳細な出力でテストを実行
uv run pytest -v
# カバレッジレポート付きでテストを実行
uv run pytest --cov=src --cov-report=term-missing
# 特定のテストファイルのみ実行
uv run pytest tests/test_config.py
# 特定のテストケースのみ実行
uv run pytest tests/test_config.py::test_load_config_with_envs_filetests/test_config.py- 設定ファイルの解析とバリデーションtests/test_github.py- GitHubクライアントの機能tests/test_cli.py- コマンドライン引数の解析と実行
tests/test_integration.py- エンドツーエンドの動作確認- 環境変数置換の統合テスト
- 実際のGitHub APIとの連携テスト(
GITHUB_TOKENが設定されている場合) - ドライランモードのテスト
テスト用の設定ファイルは tests/fixtures/ ディレクトリに配置されています:
test-config.yaml- テスト用メイン設定test-envs.yaml- テスト用環境変数定義
- HTTP リクエストは
responsesライブラリでモック - ファイルシステム操作は
tmp_pathフィクスチャを使用 - 設定ファイルの読み込みテスト用のサンプルデータを提供
実際のGitHub APIを使用したテストを実行するには:
export GITHUB_TOKEN=your_github_token
uv run pytest tests/test_integration.py::TestIntegration::test_real_github_integration# コードの静的解析
uv run ruff check .
# 自動修正可能な問題を修正
uv run ruff check . --fix
# コードフォーマット
uv run ruff format .# 型チェック(オプション、pyrightがインストールされている場合)
uv run pyrightsrc/
├── __init__.py # パッケージ初期化
├── cli.py # コマンドライン インターフェース
├── config.py # 設定ファイル解析
├── github.py # GitHub API クライアント
└── sync.py # ファイル同期ロジック
GitHubClient- GitHub からのファイルダウンロードと環境変数置換RepoFileSync- ファイル同期の統合処理SyncResult- 同期結果の管理- 設定型 - TypedDict による型安全な設定管理
-
プライベートリポジトリにアクセスできない
GITHUB_TOKEN環境変数が設定されているか確認- トークンに適切な権限があるか確認
-
設定ファイルが見つからない
- ファイルパスが正しいか確認
- 相対パスの場合、実行ディレクトリを確認
-
環境変数ファイルが見つからない
envs_fileパスがメイン設定ファイルからの相対パスで正しいか確認
-
接続エラー
--test-connectionオプションで接続を確認- ネットワーク設定やプロキシ設定を確認
詳細なログを出力してデバッグ:
uv run python -m src.cli --verboseこのプロジェクトのライセンスについては、リポジトリのライセンスファイルを参照してください。