/CD のコストは じわじわ膨らむタイプ。気付いたら GitHub Actions が月 $500、Vercel が月 $300、CircleCI が月 $400 という事態に。各サービスの でリポジトリ別・ワークフロー別の使用量を取得し、削減ポイントを見つけます。
GitHub Actions の使用量
GitHub API: workflow runs から実行時間を取得
Python
def fetch_workflow_runs(org: str, repo: str, since: str) -> list[dict]: runs = [] page = 1 while True: r = requests.get( f"https://api.github.com/repos/{org}/{repo}/actions/runs", headers=HEADERS, params={"per_page": 100, "page": page, "created": f">={since}"}, ) r.raise_for_status() items = r.json().get("workflow_runs", []) if not items: break runs.extend(items) if len(items) < 100: break page += 1 return runs
# 各 run の billable minutes を取得def get_billable(run_id: int, org: str, repo: str) -> dict: r = requests.get( f"https://api.github.com/repos/{org}/{repo}/actions/runs/{run_id}/timing", headers=HEADERS, ) return r.json() # billable.UBUNTU.total_ms など
# 集計total_min_by_workflow = {}for run in runs: timing = get_billable(run["id"], org, repo) minutes = timing["billable"].get("UBUNTU", {}).get("total_ms", 0) / 60_000 name = run["name"] total_min_by_workflow[name] = total_min_by_workflow.get(name, 0) + minutes
print(sorted(total_min_by_workflow.items(), key=lambda x: -x[1])[:10])Vercel のビルド・帯域使用量
Vercel API
Python
VERCEL_TOKEN = os.environ["VERCEL_TOKEN"]TEAM_ID = "team_xxx"
# Deployments 一覧r = requests.get( "https://api.vercel.com/v6/deployments", headers={"Authorization": f"Bearer {VERCEL_TOKEN}"}, params={"teamId": TEAM_ID, "limit": 100},)deployments = r.json()["deployments"]# 各 deployment の buildingAt / ready で時間計算
# Bandwidth と関数実行時間は Usage API でr = requests.get( "https://api.vercel.com/v1/teams/{TEAM_ID}/usage", headers={"Authorization": f"Bearer {VERCEL_TOKEN}"}, params={"period": "current"},)print(r.json()) # bandwidthGB, executionDurationSeconds などCI/CD コスト削減 5 つの定石
- 並列実行の見直し: 同時実行 30 並列 → 10 並列で月数万円減
- キャッシュの活用: actions/cache、 layer cache、依存パッケージ
- ジョブの実行条件: PR の `paths:` フィルタで関係ないジョブは走らせない
- self-hosted runner: 安定的な負荷なら自前 runner で大幅減
- の Slim CI 同様、差分テストで変更分だけ検証 (dbt EP.12)
ダッシュに載せる指標
- サービス別の月次費用: GitHub Actions / Vercel / CircleCI / その他
- ワークフロー別の累積時間: TOP 10 が全体の 80% 占めている定番分布
- リポジトリ別: 1 リポで全体の半分使ってないか
- 失敗 run の比率: 失敗ばかり走ってコスト無駄、改善余地
- 前月比: 急増のアラート
次の話
EP.06 では / / のクラウドコスト集計を扱います。
この記事の感想を教えてください
あなたの 1 クリックで、本当にこの記事は更新されます。「もっと詳しく」「続編希望」が一定数集まった記事は、 ふくふくが 実際に内容を拡充したり続編記事を公開 します。 送信したリアクションはお使いのブラウザに記録され、再カウントされません。