Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

branch_name="$(git symbolic-ref --short HEAD 2>/dev/null || true)"

if [ "$branch_name" = "main" ]; then
echo "Error: main ブランチへの直接コミットは禁止です。feature ブランチを切って作業してください。"
exit 1
fi

exit 0
13 changes: 13 additions & 0 deletions .githooks/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

blocked_ref="refs/heads/main"

while read -r local_ref local_sha remote_ref remote_sha
do
if [ "$remote_ref" = "$blocked_ref" ]; then
echo "Error: main ブランチへの直接 push は禁止です。Pull Request 経由で反映してください。"
exit 1
fi
done

exit 0
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: CI

on:
pull_request:
branches:
- main
push:
branches:
- main

permissions:
contents: read

concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 15

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: npm
cache-dependency-path: frontend/package-lock.json

- name: Install frontend dependencies
run: npm ci --prefix frontend

- name: Run frontend tests
run: npm run test --prefix frontend

- name: Build frontend
run: npm run build --prefix frontend

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
cache-dependency-path: backend/requirements.txt

- name: Install backend dependencies
run: |
python -m pip install --upgrade pip
pip install -r backend/requirements.txt

- name: Run backend tests
run: pytest -q backend/tests
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ venv/
# Node
node_modules/
dist/
frontend/.test-dist/
frontend/tsconfig.app.tsbuildinfo

# Env files
.env
Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,37 @@ cd backend
.venv/bin/python -m pytest -q
```

## CI (GitHub Actions)
- ワークフロー: `.github/workflows/ci.yml`
- 実行タイミング:
- `pull_request` (target: `main`)
- `push` (`main`)
- 実行内容:
- frontend: `npm run test`, `npm run build`
- backend: `pytest -q backend/tests`
- 低コスト運用の工夫:
- Linuxランナーのみ使用
- Node/Python依存キャッシュを利用
- `concurrency` で古い実行を自動キャンセル

## main ブランチ保護
### ローカル(ターミナル)での直コミット/直push防止
```bash
./scripts/setup-git-hooks.sh
```

- `.githooks/pre-commit`: `main` への直接コミットを拒否
- `.githooks/pre-push`: `main` への直接pushを拒否

### GitHub 側での強制保護(推奨)
1. GitHub リポジトリの `Settings` -> `Branches` -> `Add branch protection rule`
2. `Branch name pattern` に `main` を設定
3. 以下を有効化
- `Require a pull request before merging`
- `Require status checks to pass before merging`(`CI` を選択)
- `Do not allow bypassing the above settings`(利用可能な場合)
4. 保存

## メモ
- DBテーブルはFastAPI起動時に自動作成されます。
- CORS許可元は `backend/.env` の `CORS_ORIGINS` で調整できます。
Expand Down
10 changes: 10 additions & 0 deletions scripts/setup-git-hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -euo pipefail

repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"

chmod +x "$repo_root/.githooks/pre-commit" "$repo_root/.githooks/pre-push"
git -C "$repo_root" config core.hooksPath .githooks

echo "Git hooks enabled (core.hooksPath=.githooks)."