# インフラ構成図

## 全体構成図

```mermaid
graph TB
    subgraph "Source Control"
        GH[GitHub Repository<br/>nushell/nushell]
        GHN[GitHub Repository<br/>nushell/nightly]
    end

    subgraph "CI/CD Pipeline"
        subgraph "GitHub Actions Runners"
            UBUNTU[Ubuntu 22.04 Runner]
            MACOS[macOS Runner]
            WIN[Windows Runner]
            WINARM[Windows 11 ARM Runner]
        end
    end

    subgraph "Build Artifacts"
        REL[GitHub Releases]
        ART[GitHub Actions Artifacts]
    end

    subgraph "Distribution Channels"
        CRATES[crates.io]
        DOCKER[Docker Hub / GHCR]
        BREW[Homebrew]
        WINGET[Winget]
        PKG[Other Package Managers]
    end

    GH -->|push/PR| UBUNTU
    GH -->|push/PR| MACOS
    GH -->|push/PR| WIN
    GH -->|tag push| WINARM
    GHN -->|nightly| UBUNTU
    GHN -->|nightly| MACOS
    GHN -->|nightly| WIN

    UBUNTU -->|build| REL
    MACOS -->|build| REL
    WIN -->|build| REL
    WINARM -->|build| REL

    UBUNTU -->|artifacts| ART
    MACOS -->|artifacts| ART
    WIN -->|artifacts| ART

    REL -->|distribute| CRATES
    REL -->|distribute| DOCKER
    REL -->|distribute| BREW
    REL -->|distribute| WINGET
    REL -->|distribute| PKG
```

## CI/CDパイプライン詳細

```mermaid
flowchart LR
    subgraph "Triggers"
        PR[Pull Request]
        PUSH[Push to main]
        TAG[Tag Push]
        SCHED[Schedule<br/>00:15 UTC]
    end

    subgraph "CI Jobs"
        FMT[fmt-clippy]
        TEST[tests]
        STD[std-lib-and-python-virtualenv]
        PLUG[plugins]
        WASM[wasm]
    end

    subgraph "Release Jobs"
        BUILD[Build Matrix<br/>13 targets]
        SHA[SHA256 Checksums]
    end

    subgraph "Security Jobs"
        AUDIT[Security Audit]
        DEPS[Dependabot]
    end

    PR --> FMT
    PR --> TEST
    PR --> STD
    PR --> PLUG
    PR --> WASM
    PR --> AUDIT

    PUSH --> FMT
    PUSH --> TEST
    PUSH --> STD
    PUSH --> PLUG
    PUSH --> WASM
    PUSH --> AUDIT

    TAG --> BUILD
    BUILD --> SHA

    SCHED --> BUILD
```

## ビルドマトリクス構成

```mermaid
graph TD
    subgraph "Build Matrix"
        subgraph "macOS"
            MAC_ARM[aarch64-apple-darwin<br/>macos-latest]
            MAC_X64[x86_64-apple-darwin<br/>macos-latest]
        end

        subgraph "Windows"
            WIN_X64[x86_64-pc-windows-msvc<br/>windows-latest]
            WIN_ARM[aarch64-pc-windows-msvc<br/>windows-11-arm]
        end

        subgraph "Linux GNU"
            LIN_X64[x86_64-unknown-linux-gnu<br/>ubuntu-22.04]
            LIN_ARM64[aarch64-unknown-linux-gnu<br/>ubuntu-22.04]
            LIN_ARM7[armv7-unknown-linux-gnueabihf<br/>ubuntu-22.04]
            LIN_RV64[riscv64gc-unknown-linux-gnu<br/>ubuntu-22.04]
            LIN_LA64[loongarch64-unknown-linux-gnu<br/>ubuntu-22.04]
        end

        subgraph "Linux MUSL"
            MUSL_X64[x86_64-unknown-linux-musl<br/>ubuntu-22.04]
            MUSL_ARM64[aarch64-unknown-linux-musl<br/>ubuntu-22.04]
            MUSL_ARM7[armv7-unknown-linux-musleabihf<br/>ubuntu-22.04]
            MUSL_LA64[loongarch64-unknown-linux-musl<br/>ubuntu-22.04]
        end
    end
```

## Docker環境構成

```mermaid
graph TB
    subgraph "Alpine Image"
        ALPINE[Alpine Linux v3.20]
        NU_ALPINE[Nushell Binary<br/>musl libc]
        PLUGINS_A[nu_plugin_*]
        USER_A[nushell user]

        ALPINE --> NU_ALPINE
        NU_ALPINE --> PLUGINS_A
        PLUGINS_A --> USER_A
    end

    subgraph "Debian Image"
        DEBIAN[Debian Bookworm Slim]
        NU_DEBIAN[Nushell Binary<br/>glibc]
        PLUGINS_D[nu_plugin_*]
        USER_D[nushell user]

        DEBIAN --> NU_DEBIAN
        NU_DEBIAN --> PLUGINS_D
        PLUGINS_D --> USER_D
    end

    subgraph "GitHub Release API"
        API[api.github.com/repos/nushell/nushell/releases/latest]
    end

    API -->|download| NU_ALPINE
    API -->|download| NU_DEBIAN
```

## 依存関係更新フロー

```mermaid
sequenceDiagram
    participant D as Dependabot
    participant GH as GitHub
    participant CI as GitHub Actions
    participant R as Reviewer

    D->>GH: Create PR (Weekly, Wednesday)
    GH->>CI: Trigger CI
    CI->>CI: Run Tests
    CI->>GH: Report Status
    GH->>R: Notify for Review
    R->>GH: Approve & Merge
```

## セキュリティ監視フロー

```mermaid
flowchart TD
    subgraph "Security Checks"
        CARGO[Cargo.toml/Cargo.lock Changes]
        AUDIT[cargo-audit]
        RUSTSEC[RustSec Advisory DB]
    end

    subgraph "Actions"
        WARN[Warning / Continue]
        ISSUE[Create Issue]
    end

    CARGO -->|PR/Push| AUDIT
    AUDIT -->|Check| RUSTSEC
    RUSTSEC -->|Advisory Found| WARN
    RUSTSEC -->|Critical| ISSUE
```

## ナイトリービルドフロー

```mermaid
sequenceDiagram
    participant S as Scheduler
    participant P as Prepare Job
    participant N as nushell/nightly
    participant B as Build Matrix
    participant R as Release

    S->>P: Trigger (00:15 UTC)
    P->>N: Sync main branch
    P->>P: Check if rebuild needed
    alt New commits exist
        P->>N: Create nightly tag
        P->>B: Trigger build matrix
        B->>B: Build 13 targets
        B->>R: Upload artifacts
        R->>R: Create SHA256SUMS
        R->>N: Cleanup old releases (keep 10)
    else No new commits
        P->>P: Skip build
    end
```
