# golles/mock-yaml-secrets-action architecture

> Architecture diagram of the GitHub repository golles/mock-yaml-secrets-action, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/golles/mock-yaml-secrets-action
- Repository: https://github.com/golles/mock-yaml-secrets-action

## Overview

##### Project type and purpose
- This is an open-source GitHub Action written in TypeScript/Node.js.
- Its purpose is to scan a user’s YAML files in a repository for secret-looking keys (via regex rules) and emit a `secrets.yaml` file with dummy values, so later CI/CD steps don’t fail due to missing secrets.

##### File structure
- Top-level entrypoint for the Action: `action.yml`
- Source code in `src/`:
- `index.ts` (reads inputs, kicks off processing)
- `main.ts` (core orchestration)
- `utils/`: `config.ts` (parses JSON config), `files.ts` (recursive file scanning), `rules.ts` (regex matching)
- Build artifacts in `dist/` (bundled with Rollup as CommonJS for Node)
- Tests in `__tests__/` with fixtures in `__fixtures__/`
- Configuration & metadata: `package.json`, `rollup.config.ts`, TypeScript configs, GitHub workflows for CI, linting, release.

##### README for additional insights
- Inputs: `configFile` path pointing to a JSON specifying:
- `directory` to scan
- `excludePaths`, `secretFile` name, `defaultValue`, `rules` map
- Usage under a GitHub workflow: checks out code, runs “Mock secrets” step, then downstream build.

a. Main components
1. GitHub Actions Runner (host environment)
2. Checkout & Setup step (retrieves user repo + this Action)
3. Mock-YAML-Secrets Action container/process:
- Action Entrypoint (`action.yml`)
- Runtime (Node.js)
- Bundled code (`dist/main.js`)
- Modules: Config Loader, File Scanner, Rule Engine, YAML Generator
4. Input artifacts: user’s YAML files + JSON config file
5. Output artifact: generated `secrets.yaml` in workspace
6. Downstream steps (other Actions or build steps) that consume `secrets.yaml`
b. Relationships & data flow
- Runner invokes Action → reads inputs → invokes Config Loader
- File Scanner walks target directory, filters by `excludePaths`
- For each YAML file, data passes to Rule Engine → produces key/value pairs
- YAML Generator emits `secrets.yaml`
- Output file lands back on the runner workspace for next job
c. Architectural patterns & principles
- Modular design: each concern in its own utility module (single responsibility)
- Pipeline pattern: Input → Transform → Output
- CLI/Action abstraction: `action.yml` ties GitHub Actions meta to code
d. Relevant technologies/frameworks
- TypeScript & Node.js runtime
- Rollup bundler (produces `dist/`)
- Jest for testing (fixtures under `__fixtures__`)
- GitHub Actions metadata (`action.yml`)
- GitHub workflows for CI/CD in `.github/workflows/`

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Host
    Runner["GitHub Actions Runner"]:::external
    Checkout["Checkout & Setup Step"]:::external

    %% Inputs
    subgraph "Inputs"
        direction TB
        UserRepo["User Repository"]:::input
        ConfigJSON["Config JSON"]:::input
        YamlFiles["User YAML Files"]:::input
    end

    %% Action Entrypoint & Runtime
    subgraph "Action Invocation"
        direction TB
        ActionYML["action.yml"]:::infra
        NodeRuntime["Node.js Runtime"]:::infra
    end

    %% Core Orchestration
    subgraph "Action Core Modules"
        direction TB
        IndexTS["src/index.ts"]:::core
        IndexJS["dist/index.js"]:::core
        MainTS["src/main.ts"]:::core
        MainJS["dist/main.js"]:::core

        subgraph "Utils"
            direction TB
            ConfigLoaderTS["src/utils/config.ts"]:::core
            ConfigLoaderJS["dist/utils/config.js"]:::core
            FileScannerTS["src/utils/files.ts"]:::core
            FileScannerJS["dist/utils/files.js"]:::core
            RuleEngineTS["src/utils/rules.ts"]:::core
            RuleEngineJS["dist/utils/rules.js"]:::core
        end

        YAMLGen["YAML Generator (main.ts)"]:::core
    end

    %% Output & Downstream
    SecretsFile["secrets.yaml"]:::output
    Downstream["Downstream Steps"]:::external

    %% Build & Config Files
    subgraph "Build & Config"
        direction TB
        Rollup["rollup.config.ts"]:::infra
        TSConfig["tsconfig.json"]:::infra
        Package["package.json"]:::infra
    end

    %% CI/CD & Workflows
    subgraph "CI/CD Workflows"
        direction TB
        CI[".github/workflows/ci.yaml"]:::infra
        CheckDist[".github/workflows/check-dist.yaml"]:::infra
        LinterWF[".github/workflows/linter.yaml"]:::infra
        CodeQL[".github/workflows/codeql.yaml"]:::infra
        ReleaseWF[".github/workflows/release.yaml"]:::infra
    end

    %% Tests & Fixtures
    subgraph "Tests & Fixtures"
        direction TB
        ConfigTest["__tests__/utils/config.test.ts"]:::test
        FilesTest["__tests__/utils/files.test.ts"]:::test
        RulesTest["__tests__/utils/rules.test.ts"]:::test
        ConfigData["__tests__/data/config"]:::test
        FilesData["__tests__/data/files"]:::test
        Fixtures["__fixtures__/core.ts"]:::test
    end

    %% Scripts & Linting
    subgraph "Scripts & Linting"
        direction TB
        NewVersion["scripts/new_version.sh"]:::infra
        MarkdownLint[".markdown-lint.yml"]:::infra
        YAMLLint[".yaml-lint.yml"]:::infra
        Prettier[".prettierrc.yml"]:::infra
        ESLint["eslint.config.mjs"]:::infra
    end

    %% Connections - Invocation Flow
    Runner --> Checkout
    Checkout --> ActionYML
    ActionYML --> NodeRuntime
    NodeRuntime --> IndexJS
    NodeRuntime --> MainJS

    %% Core Pipeline
    IndexJS --> MainJS
    MainJS --> ConfigLoaderJS
    MainJS --> FileScannerJS
    MainJS --> RuleEngineJS
    MainJS --> YAMLGen
    ConfigLoaderJS -->|"loads JSON"| ConfigJSON
    FileScannerJS -->|"scans"| UserRepo
    FileScannerJS --> YamlFiles
    RuleEngineJS -->|"matches secrets"| YamlFiles
    YAMLGen -->|"generates"| SecretsFile
    SecretsFile --> Downstream

    %% Build & CI
    Rollup --> MainJS
    TSConfig --> IndexTS
    TSConfig --> MainTS
    Package --> Rollup
    CI --> Checkout
    CheckDist --> CI
    LinterWF --> CI
    CodeQL --> CI
    ReleaseWF --> CI

    %% Tests & Fixtures
    ConfigTest --> ConfigLoaderTS
    FilesTest --> FileScannerTS
    RulesTest --> RuleEngineTS
    ConfigTest --> ConfigData
    FilesTest --> FilesData
    Fixtures --> MainTS

    %% Click Events
    click ActionYML "https://github.com/golles/mock-yaml-secrets-action/blob/main/action.yml"
    click IndexTS "https://github.com/golles/mock-yaml-secrets-action/blob/main/src/index.ts"
    click IndexJS "https://github.com/golles/mock-yaml-secrets-action/blob/main/dist/index.js"
    click MainTS "https://github.com/golles/mock-yaml-secrets-action/blob/main/src/main.ts"
    click MainJS "https://github.com/golles/mock-yaml-secrets-action/blob/main/dist/main.js"
    click ConfigLoaderTS "https://github.com/golles/mock-yaml-secrets-action/blob/main/src/utils/config.ts"
    click ConfigLoaderJS "https://github.com/golles/mock-yaml-secrets-action/blob/main/dist/utils/config.js"
    click FileScannerTS "https://github.com/golles/mock-yaml-secrets-action/blob/main/src/utils/files.ts"
    click FileScannerJS "https://github.com/golles/mock-yaml-secrets-action/blob/main/dist/utils/files.js"
    click RuleEngineTS "https://github.com/golles/mock-yaml-secrets-action/blob/main/src/utils/rules.ts"
    click RuleEngineJS "https://github.com/golles/mock-yaml-secrets-action/blob/main/dist/utils/rules.js"
    click ConfigTest "https://github.com/golles/mock-yaml-secrets-action/blob/main/__tests__/utils/config.test.ts"
    click FilesTest "https://github.com/golles/mock-yaml-secrets-action/blob/main/__tests__/utils/files.test.ts"
    click RulesTest "https://github.com/golles/mock-yaml-secrets-action/blob/main/__tests__/utils/rules.test.ts"
    click CI "https://github.com/golles/mock-yaml-secrets-action/blob/main/.github/workflows/ci.yaml"
    click CheckDist "https://github.com/golles/mock-yaml-secrets-action/blob/main/.github/workflows/check-dist.yaml"
    click LinterWF "https://github.com/golles/mock-yaml-secrets-action/blob/main/.github/workflows/linter.yaml"
    click CodeQL "https://github.com/golles/mock-yaml-secrets-action/blob/main/.github/workflows/codeql.yaml"
    click ReleaseWF "https://github.com/golles/mock-yaml-secrets-action/blob/main/.github/workflows/release.yaml"

    %% Styles
    classDef external fill:#CCCCCC,stroke:#333,stroke-width:1px
    classDef input fill:#E0FFD8,stroke:#2F8F2F,stroke-width:1px
    classDef output fill:#D8EEFF,stroke:#1F5F8F,stroke-width:1px
    classDef core fill:#BBDEFB,stroke:#1E88E5,stroke-width:1px
    classDef infra fill:#FFE0B2,stroke:#EF6C00,stroke-width:1px
    classDef test fill:#F3E5F5,stroke:#8E24AA,stroke-width:1px
```
