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
28 changes: 20 additions & 8 deletions README-ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ PR の変更ファイルを検出し、変更があったサービスに対し
**特徴:**

- ラベルからターゲットへの解決
- 定義された環境からの対象選択
- 定義環境と探索した環境からの対象選択
- デプロイメント matrix 生成
- 安全性検証

Expand All @@ -57,7 +57,7 @@ PR の変更ファイルを検出し、変更があったサービスに対し

### Label Resolver

`environments` は任意の入力で、複数環境はカンマ区切りで指定します。省略すると全定義環境を対象にします。
`environments` は任意の入力で、複数環境はカンマ区切りで指定します。省略すると定義環境と探索した環境をすべて対象にします。

```yaml
- uses: panicboat/deploy-actions/label-resolver@v1
Expand Down Expand Up @@ -94,7 +94,11 @@ stacks:
- "dystopia/{service}"
- "system-components/{service}"
attributes:
repository: registry.example.com/app
repository: registry.example.com/{service}
- name: kubernetes
paths:
- "dystopia/{service}/kubernetes/overlays/{environment}"
- "system-components/{service}/kubernetes/overlays/{environment}"
```

### stack の定義
Expand All @@ -105,14 +109,22 @@ stacks:
| `id` | 任意 | インスタンス識別子。省略時は `name`。設定全体で一意 |
| `paths` | 必須 | 空でない相対パス配列。全パスに `{service}` が必要 |
| `environments` | 任意 | 環境名をキー、環境属性を値とする空でないマップ |
| `attributes` | 任意 | 環境共通の属性。`environments` と併用できない |
| `attributes` | 任意 | 環境共通の対象を明示する。`attributes: {}` も有効。`environments` と併用できない |
| `exclude` | 任意 | 除外条件の配列。省略時は空配列 |

共有するプロダクトは一つの定義の `paths` に追加します。独立させる場合は、同じ `name` に異なる `id` を付けた別定義にし、それぞれにパスと属性を置きます。

`environments` のキーがその stack の環境名です。環境一覧は全 stack の和集合になり、環境指定を省略すると全定義環境が対象になります。各 stack は自身の定義環境だけを生成し、未知の環境指定はエラーになります。属性の値と型はそのまま出力され、環境間の属性キーを揃える必要はありません。
`environments` のキーがその stack の環境名です。`environments` と `attributes` の両方を省略した stack は、パスに一致する実在ディレクトリの `{environment}` の位置から環境名を取得します。この場合は全パスに `{environment}` が必要で、含まないパスがあれば設定エラーになります。探索した対象に追加属性はなく、別 stack の環境・属性・除外条件は継承しません。

選択できる環境一覧は、全 stack の定義環境と実行時に探索した環境名の和集合です。除外された環境名も選択できます。環境指定を省略するとこの和集合を対象にします。各 stack は自身の定義環境または探索した環境だけを生成し、和集合にない環境指定はエラーになります。

パスに `{environment}` がなくても、`environments` があれば環境ごとの対象になります。同じディレクトリを異なる環境属性で使えます。`attributes` があれば環境共通で、環境選択数にかかわらず `environment: null` の対象を各ディレクトリにつき一度だけ生成します。この場合はパスに `{environment}` を指定できません。属性が不要な環境共通の対象には `attributes: {}` を明示します。

### Attribute Values

`attributes` と環境属性マップの文字列値では、`{service}` とパスから抽出した `{team}` などの任意 placeholder を使えます。環境属性では、パスに含まれない場合も `{environment}` を使えます。マップや配列に入れ子になった文字列にも同じ規則を適用します。マップのキーはリテラルのままで、文字列以外の値は型を保持します。環境間で属性キーを揃える必要はありません。

パスに `{environment}` がなくても、`environments` があれば環境ごとの対象になります。同じディレクトリを異なる環境属性で使えます。`environments` がなければ環境共通で、`environment: null` の対象を各ディレクトリにつき一度だけ生成します。この場合の属性は `attributes` から取得し、パスに `{environment}` は指定できません。
属性が参照する placeholder は、その stack のすべてのパスで取得できる必要があり、解決できない参照は設定エラーになります。環境共通の属性では `{environment}` を参照できません。例えば `paths: ["teams/{team}/{service}"]` と `attributes: {repository: "ghcr.io/{team}/{service}"}` の組み合わせは、`teams/payments/api` に対して `ghcr.io/payments/api` を出力します。

### パスの照合

Expand All @@ -126,7 +138,7 @@ stacks:

一つのマップ内は AND、配列内は OR で完全一致を判定します。省略したキーは制約になりません。service のみ、environment のみ、任意 placeholder のみでも指定できます。照合したパスにない抽出値を要求する条件は一致しません。

条件値は空でない文字列で、`/`、`.`、`..` は使えません。service はドットで始められません。環境条件は自身の定義環境だけを指定できます。環境共通 stack では environment の省略または `null` を受け付け、environment 以外の条件値に `null` は使えません。
条件値は空でない文字列で、`/`、`.`、`..` は使えません。service はドットで始められません。`environments` を指定した stack の環境条件は自身の定義環境だけを指定できます。環境を探索する stack では、まだ存在しないディレクトリの環境値も条件にできます。環境共通 stack では environment の省略または `null` を受け付け、environment 以外の条件値に `null` は使えません。条件値はリテラルで、placeholder は展開しません。

実行可能な設定例は [workflow-config.yaml](action-scripts/workflow-config.yaml) を参照してください。

Expand Down Expand Up @@ -183,7 +195,7 @@ jobs:
| キー | 出力元 |
|---|---|
| `service` | ラベルまたは `deploy:all` で探索したサービス名 |
| `environment` | 定義した環境名。環境共通なら `null` |
| `environment` | 定義または探索した環境名。環境共通なら `null` |
| `stack` | stack の `name` |
| `stack_id` | 確定した `id` |
| `working_directory` | 実在する対象ディレクトリの相対パス |
Expand Down
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Generates a matrix for downstream Actions from `deploy:<service>` labels and the
**Highlights:**

- Label-to-target resolution
- Target selection from configured environments
- Target selection from declared and discovered environments
- Deployment-matrix generation
- Safety validation

Expand All @@ -57,7 +57,7 @@ Generates a matrix for downstream Actions from `deploy:<service>` labels and the

### Label Resolver

`environments` is optional. Specify multiple environments as a comma-separated list; omit it to target all configured environments.
`environments` is optional. Specify multiple environments as a comma-separated list; omit it to target all declared and discovered environments.

```yaml
- uses: panicboat/deploy-actions/label-resolver@v1
Expand Down Expand Up @@ -94,7 +94,11 @@ stacks:
- "dystopia/{service}"
- "system-components/{service}"
attributes:
repository: registry.example.com/app
repository: registry.example.com/{service}
- name: kubernetes
paths:
- "dystopia/{service}/kubernetes/overlays/{environment}"
- "system-components/{service}/kubernetes/overlays/{environment}"
```

### Stack Definitions
Expand All @@ -105,14 +109,22 @@ stacks:
| `id` | Optional | Instance identifier; defaults to `name` and must be unique across the configuration |
| `paths` | Required | Nonempty array of relative paths; every path must contain `{service}` |
| `environments` | Optional | Nonempty map from environment names to environment attributes |
| `attributes` | Optional | Attributes shared across environments; cannot be combined with `environments` |
| `attributes` | Optional | Explicitly selects a target shared across environments, including `attributes: {}`; cannot be combined with `environments` |
| `exclude` | Optional | Array of exclusion conditions; defaults to an empty array |

Products that share a stack use multiple entries in one definition's `paths`. For independent stacks, use separate definitions with the same `name` and different `id` values, each with its own paths and attributes.

The keys in `environments` define the stack's environment names. The environment list is the union of all stacks' environment names. Omitting the environment selection targets all configured environments. Each stack generates targets only for its own environments, and selecting an unknown environment is an error. Attribute values and types are preserved in the output; environments do not need identical attribute keys.
The keys in `environments` define the stack's environment names. A stack with neither `environments` nor `attributes` discovers environment names from the `{environment}` position in existing directories matching its paths. Every path in that stack must contain `{environment}`; otherwise the configuration is invalid. Discovered targets have no additional attributes and do not inherit another stack's environments, attributes, or exclusions.

The selectable environment list is the union of all declared names and names discovered at execution time. Excluded environments remain selectable. Omitting the environment selection targets this union. Each stack generates targets only for its own declared or discovered environments. Selecting a name absent from the union is an error.

A stack with `environments` generates targets for each environment even when its paths do not contain `{environment}`. The same directory can use different environment attributes. A stack with `attributes` generates one target with `environment: null` per directory, regardless of environment selection. Its paths cannot contain `{environment}`. Use `attributes: {}` when a shared target needs no attributes.

### Attribute Values

String values in `attributes` and environment attribute maps support `{service}` and arbitrary placeholders captured from the path, such as `{team}`. Environment attributes also support `{environment}`, even if the path does not contain it. The same rules apply to strings nested in maps or arrays. Map keys remain literal, and non-string values retain their types. Environments do not need identical attribute keys.

A stack with `environments` generates targets for each environment even when its paths do not contain `{environment}`. The same directory can use different environment attributes. A stack without `environments` is shared across environments and generates one target with `environment: null` per directory. It uses `attributes` and cannot contain `{environment}` in its paths.
Every placeholder referenced by an attribute must be available for every path in that stack; unresolved references are configuration errors. Shared attributes cannot reference `{environment}`. For example, `paths: ["teams/{team}/{service}"]` with `attributes: {repository: "ghcr.io/{team}/{service}"}` produces `ghcr.io/payments/api` for `teams/payments/api`.

### Path Matching

Expand All @@ -126,7 +138,7 @@ Each entry in `exclude` is a nonempty condition map. Conditions can use `service

Conditions use exact matching: keys within a map are combined with AND, and entries in the array are combined with OR. Omitted keys impose no restriction. A condition can specify only a service, only an environment, or only an arbitrary placeholder. A condition requiring a captured value absent from the matched path does not match.

Condition values must be nonempty strings representing one path segment; `/`, `.`, and `..` are not allowed. Service names cannot start with a dot. Environment conditions can name only the stack's own environments. For stacks shared across environments, `environment` can be omitted or set to `null`; other condition values cannot be `null`.
Condition values must be nonempty strings representing one path segment; `/`, `.`, and `..` are not allowed. Service names cannot start with a dot. When `environments` is specified, environment conditions can name only the stack's declared environments. For stacks that discover environments, an environment condition may name a directory value that does not yet exist. For stacks shared across environments, `environment` can be omitted or set to `null`; other condition values cannot be `null`. Condition values are literal and do not expand placeholders.

See [workflow-config.yaml](action-scripts/workflow-config.yaml) for a working configuration example.

Expand Down Expand Up @@ -183,7 +195,7 @@ The execution layer (`aws`, `kubernetes`, etc.) is intentionally not part of thi
| Key | Source |
|---|---|
| `service` | Service name from a label or discovered through `deploy:all` |
| `environment` | Configured environment name, or `null` for a target shared across environments |
| `environment` | Declared or discovered environment name, or `null` for a target shared across environments |
| `stack` | Stack `name` |
| `stack_id` | Resolved `id` |
| `working_directory` | Relative path of the existing target directory |
Expand Down
10 changes: 5 additions & 5 deletions action-scripts/config-manager/README-ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ Config Manager は `config-manager/bin/config-manager` を通じて CLI イン

| コマンド | 結果 |
|---|---|
| `bundle exec ruby config-manager/bin/config-manager validate` | 設定の検証結果と stack・環境数 |
| `bundle exec ruby config-manager/bin/config-manager validate` | 設定の検証結果と stack・定義環境数 |
| `bundle exec ruby config-manager/bin/config-manager show` | 各 stack ID の全パス、環境属性または共通属性、除外条件 |
| `bundle exec ruby config-manager/bin/config-manager environments` | 定義した環境名の和集合 |
| `bundle exec ruby config-manager/bin/config-manager environments` | 定義環境と探索した環境名の和集合 |
| `bundle exec ruby config-manager/bin/config-manager test SERVICE_NAME [ENVIRONMENT]` | 実在する全一致対象と除外状態 |
| `bundle exec ruby config-manager/bin/config-manager diagnostics` | 設定、環境変数、Git 状態、設定ファイルの診断 |
| `bundle exec ruby config-manager/bin/config-manager template` | 新しい設定を作るための YAML の表示 |
| `bundle exec ruby config-manager/bin/config-manager check_file` | 既定ファイルの存在、読み取り、YAML 構文の確認 |

### サービス診断

環境を省略すると、そのサービスの全定義環境と共通対象を調べます。環境を指定すると、指定環境と共通対象を調べます。サービスの登録は不要です。パスに一致しないサービスは空の結果になります。
環境を省略すると、そのサービスの定義環境・探索した環境・共通対象をすべて調べます。環境を指定すると、指定環境と共通対象を調べます。サービスの登録は不要です。パスに一致しないサービスは空の結果になります。

一致する全ディレクトリを stack ID ごとに表示し、属性と任意 placeholder の抽出値を保持します。除外された対象も `excluded: true` として表示するため、実行対象から外れる条件を確認できます。
一致する全ディレクトリを stack ID ごとに表示し、展開後の属性値と任意 placeholder の抽出値を出力します。除外された対象も `excluded: true` として表示するため、実行対象から外れる条件を確認できます。

```bash
bundle exec ruby config-manager/bin/config-manager test demo
Expand All @@ -50,7 +50,7 @@ bundle exec ruby config-manager/bin/config-manager test demo production

### 検証の流れ

YAML を読み込み、設定モデルで構造と整合性を検証し、検証結果と stack・環境数を表示します。検証規則の詳細は [設定](../../README-ja.md#設定) を参照してください。
YAML を読み込み、設定モデルで構造と整合性を検証し、検証結果と stack・定義環境数を表示します。検証と設定表示ではディレクトリを列挙しません。実在ディレクトリの環境名は `environments` またはサービス診断で取得します。検証規則の詳細は [設定](../../README-ja.md#設定) を参照してください。

## エラー処理

Expand Down
10 changes: 5 additions & 5 deletions action-scripts/config-manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ Run commands from the `action-scripts` directory.

| Command | Result |
|---|---|
| `bundle exec ruby config-manager/bin/config-manager validate` | Validation result and stack/environment counts |
| `bundle exec ruby config-manager/bin/config-manager validate` | Validation result and stack/declared environment counts |
| `bundle exec ruby config-manager/bin/config-manager show` | All paths, environment or shared attributes, and exclusions for each stack ID |
| `bundle exec ruby config-manager/bin/config-manager environments` | Union of configured environment names |
| `bundle exec ruby config-manager/bin/config-manager environments` | Union of declared and discovered environment names |
| `bundle exec ruby config-manager/bin/config-manager test SERVICE_NAME [ENVIRONMENT]` | All existing matching targets and their exclusion status |
| `bundle exec ruby config-manager/bin/config-manager diagnostics` | Diagnostics for configuration, environment variables, Git state, and the configuration file |
| `bundle exec ruby config-manager/bin/config-manager template` | Display of YAML for creating a configuration |
| `bundle exec ruby config-manager/bin/config-manager check_file` | Existence, readability, and YAML syntax checks for the default file |

### Service Diagnosis

Omitting the environment inspects all configured environments and shared targets for the service. Selecting an environment inspects that environment and shared targets. Services do not require registration. A service that matches no paths produces an empty result.
Omitting the environment inspects all declared and discovered environments and shared targets for the service. Selecting an environment inspects that environment and shared targets. Services do not require registration. A service that matches no paths produces an empty result.

All matching directories are displayed by stack ID, preserving attributes and captured arbitrary placeholders. Excluded targets are also displayed with `excluded: true`, so you can inspect why they are omitted from deployment.
All matching directories are displayed by stack ID, with expanded attribute values and captured arbitrary placeholders. Excluded targets are also displayed with `excluded: true`, so you can inspect why they are omitted from deployment.

```bash
bundle exec ruby config-manager/bin/config-manager test demo
Expand All @@ -50,7 +50,7 @@ Unknown environments, invalid configuration, directory enumeration failures, and

### Validation Flow

Loads YAML, validates structure and consistency through the configuration model, and displays the validation result with stack/environment counts. See [Configuration](../../README.md#configuration) for the validation rules.
Loads YAML, validates structure and consistency through the configuration model, and displays the validation result with stack/declared environment counts. Validation and configuration display do not enumerate directories; use `environments` or service diagnosis to discover environment names from existing directories. See [Configuration](../../README.md#configuration) for the validation rules.

## Error Handling

Expand Down
Loading
Loading