|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is a GitHub Action written in Go that reads agent configuration metadata from a checked-out repository. The action reads a YAML configuration file (`.fleetControl/configurationDefinitions.yml`) from the local filesystem after the repository has been checked out by `actions/checkout`. |
| 8 | + |
| 9 | +**Future Direction**: This action will eventually use the data read in to call a service. |
| 10 | + |
| 11 | +## Project Structure |
| 12 | + |
| 13 | +The project follows standard Go conventions: |
| 14 | + |
| 15 | +``` |
| 16 | +├── cmd/ |
| 17 | +│ └── agent-metadata-action/ # Main application entry point |
| 18 | +│ └── main.go |
| 19 | +├── internal/ # Private application code |
| 20 | +│ ├── config/ # Configuration loading and file I/O |
| 21 | +│ │ ├── config.go |
| 22 | +│ │ ├── config_test.go |
| 23 | +│ │ └── integration_test.go |
| 24 | +│ └── models/ # Data structures |
| 25 | +│ └── models.go |
| 26 | +├── .fleetControl/ # Configuration files |
| 27 | +│ ├── configurationDefinitions.yml |
| 28 | +│ └── schemas/ |
| 29 | +│ └── myagent-config.json |
| 30 | +├── action.yml # GitHub Action definition |
| 31 | +├── go.mod |
| 32 | +└── run_local.sh # Local testing script |
| 33 | +``` |
| 34 | + |
| 35 | +## Build and Test Commands |
| 36 | + |
| 37 | +```bash |
| 38 | +# Build the action |
| 39 | +go build -o agent-metadata-action ./cmd/agent-metadata-action |
| 40 | + |
| 41 | +# Run all tests |
| 42 | +go test ./... |
| 43 | + |
| 44 | +# Run tests with verbose output |
| 45 | +go test -v ./... |
| 46 | + |
| 47 | +# Run tests for a specific package |
| 48 | +go test -v ./internal/config |
| 49 | + |
| 50 | +# Run a specific test |
| 51 | +go test -v -run TestLoadEnv_Success ./internal/config |
| 52 | + |
| 53 | +# Local development (requires GITHUB_WORKSPACE to be set) |
| 54 | +export GITHUB_WORKSPACE=/path/to/repo |
| 55 | +./agent-metadata-action |
| 56 | + |
| 57 | +# Or use run_local.sh for testing |
| 58 | +./run_local.sh |
| 59 | +``` |
| 60 | + |
| 61 | +## Architecture |
| 62 | + |
| 63 | +### Package Organization |
| 64 | + |
| 65 | +**cmd/agent-metadata-action/main.go**: Application entry point |
| 66 | +- Loads workspace path via `config.LoadEnv()` |
| 67 | +- Calls `config.ReadConfigurationDefinitions()` to read and parse YAML |
| 68 | +- Marshals results to JSON for output |
| 69 | +- Uses GitHub Actions annotation format for logging (`::error::`, `::notice::`, `::debug::`) |
| 70 | + |
| 71 | +**internal/config**: Configuration file I/O |
| 72 | +- `LoadEnv()`: Reads `GITHUB_WORKSPACE` environment variable |
| 73 | +- `ReadConfigurationDefinitions()`: Reads YAML file from local filesystem and parses it |
| 74 | +- Tests cover environment variable validation, file reading, and YAML parsing errors |
| 75 | + |
| 76 | +**internal/models**: Data structures |
| 77 | +- `ConfigurationDefinition`: Represents a single configuration with fields like name, slug, platform, description, type, version, format, and schema |
| 78 | +- `ConfigFile`: Root YAML structure containing `configurationDefinitions` array |
| 79 | +- `AgentMetadata`: (Currently unused - may be used for future service integration) |
| 80 | + |
| 81 | +### Data Flow |
| 82 | + |
| 83 | +1. `config.LoadEnv()` reads `GITHUB_WORKSPACE` environment variable |
| 84 | +2. `config.ReadConfigurationDefinitions()` constructs file path: `{workspace}/.fleetControl/configurationDefinitions.yml` |
| 85 | +3. `os.ReadFile()` reads the YAML file from local filesystem |
| 86 | +4. YAML is unmarshaled into `models.ConfigFile` structure |
| 87 | +5. Array of `ConfigurationDefinition` is returned |
| 88 | +6. Main function marshals each config to JSON and prints with `::debug::` annotations |
| 89 | + |
| 90 | +### GitHub Action Integration |
| 91 | + |
| 92 | +**action.yml** defines the composite action: |
| 93 | +- Sets up Go using version from `go.mod` (currently Go 1.25.3) |
| 94 | +- Builds binary from source: `go build -o agent-metadata-action ./cmd/agent-metadata-action` |
| 95 | +- Executes the built binary in the workspace |
| 96 | +- The action builds and runs on every invocation (no pre-built binary) |
| 97 | +- Supports optional `cache` input to control Go build caching (defaults to `true`) |
| 98 | + |
| 99 | +The action expects to run after `actions/checkout` which sets the `GITHUB_WORKSPACE` environment variable and checks out the repository containing the configuration file. |
| 100 | + |
| 101 | +## Key Behaviors |
| 102 | + |
| 103 | +- Reads from **local filesystem** only (no network calls) |
| 104 | +- Requires `GITHUB_WORKSPACE` environment variable to be set |
| 105 | +- Error output uses GitHub Actions annotation format: `::error::`, `::notice::`, `::debug::` |
| 106 | +- All errors result in exit code 1 |
| 107 | +- Target file path is hardcoded: `.fleetControl/configurationDefinitions.yml` |
| 108 | +- YAML structure maps directly to JSON output (no transformation/filtering) |
| 109 | +- The `schema` field in configurations contains relative paths to JSON schema files |
0 commit comments