
# GitHub

GitHub はレジストリをホストする最も簡単な方法です。ブロックをリポジトリにプッシュし、GitHub の raw content URL を使います。

## セットアップ

次の構成でリポジトリを作成します:

```
acme-blocks/
  registry.json
  blocks/
    hero/
      block.json
      index.php
    card/
      block.json
      index.php
      style.scss
```

## registry.json

`blocks/` ディレクトリの raw GitHub URL を `baseUrl` に設定します:

```json
{
  "name": "acme",
  "description": "Acme Corp block library.",
  "baseUrl": "https://raw.githubusercontent.com/acme/acme-blocks/main/blocks",
  "blocks": [
    {
      "name": "hero",
      "title": "Hero",
      "category": "layout",
      "type": "blockstudio",
      "files": ["block.json", "index.php"]
    },
    {
      "name": "card",
      "title": "Card",
      "category": "components",
      "type": "blockstudio",
      "files": ["block.json", "index.php", "style.scss"]
    }
  ]
}
```

`baseUrl` は `raw.githubusercontent.com` を使い、CLI が raw ファイルの内容を取得できるようにします。GitHub HTML ページは取得しません。

## 利用側の設定

ユーザーは `blocks.json` にレジストリを追加します:

```json
{
  "directory": "blockstudio",
  "registries": {
    "acme": "https://raw.githubusercontent.com/acme/acme-blocks/main/registry.json"
  }
}
```

その後:

```bash
npx blockstudio add acme/hero
```

## リリースを固定する

特定のバージョンに固定するには、`main` の代わりにタグまたはコミット SHA を使います:

```json
{
  "registries": {
    "acme": "https://raw.githubusercontent.com/acme/acme-blocks/v1.0.0/registry.json"
  }
}
```

この方法なら、そのタグの `registry.json` も `baseUrl` で同じタグを使っている限り、既存プロジェクトに破壊的変更が及ぶのを防げます。CLI はブロックファイルを `baseUrl` からダウンロードするため、`baseUrl` が `main` を指しているタグ付きの `registry.json` では、`main` のファイルがインストールされます。コミット SHA でも同様です。ブロック一覧は固定されますが、ファイルはそのコミットの `baseUrl` が示す参照先から取得されます。

## GitHub Pages

よりすっきりした URL を使いたい場合は、GitHub Pages 経由でレジストリを配信することもできます:

1. リポジトリで GitHub Pages を有効にします
2. `baseUrl` に Pages の URL を設定します: `https://acme.github.io/acme-blocks/blocks`
3. `registry.json` は `https://acme.github.io/acme-blocks/registry.json` からアクセスできます

## プライベートリポジトリ

プライベートリポジトリでは、GitHub パーソナルアクセストークンを使うオブジェクト形式のレジストリを指定します:

```json
{
  "registries": {
    "private": {
      "url": "https://raw.githubusercontent.com/acme/private-blocks/main/registry.json",
      "headers": {
        "Authorization": "Bearer ${GITHUB_TOKEN}"
      }
    }
  }
}
```

環境変数にトークンを設定します:

```bash
export GITHUB_TOKEN=ghp_abc123
npx blockstudio add private/hero
```

`raw.githubusercontent.com` 経由でプライベートリポジトリのコンテンツにアクセスするには、トークンに `repo` スコープ (または細分化トークンの場合は `contents:read`) が必要です。
