Skip to content

Commit 2b51865

Browse files
authored
Merge pull request #2 from newrelic/mvick/refactor
chore: Refactor
2 parents 0afebb0 + 00b5ba3 commit 2b51865

File tree

14 files changed

+546
-420
lines changed

14 files changed

+546
-420
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
configurationDefinitions:
2+
- name: New relic myagent config for k8s
3+
slug: myagent-config
4+
platform: kubernetes
5+
description: myagent agent configuration, provided by the user
6+
type: myagent-config
7+
version: 1.0.0
8+
format: json
9+
schema: ./schemas/myagent-config.json
10+
- name: New relic myagent agent config for host
11+
slug: myagent-config
12+
platform: host
13+
description: myagent agent configuration, provided by the user
14+
type: myagent-config
15+
version: 1.0.0
16+
format: json
17+
schema: ./schemas/myagent-config.json
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://newrelic.com/schemas/myagent-configuration.json",
4+
"title": "New Relic My Agent Configuration Schema",
5+
"description": "Schema for New Relic My Agent configuration",
6+
"type": "object",
7+
"properties": {
8+
"common": {
9+
"type": "object",
10+
"description": "Common configuration settings shared across all environments",
11+
"properties": {
12+
"license_key": {
13+
"type": "string",
14+
"minLength": 1,
15+
"description": "New Relic license key",
16+
"examples": ["<%= license_key %>", "your_license_key_here"]
17+
},
18+
"agent_enabled": {
19+
"type": "boolean",
20+
"description": "Enable or disable the agent",
21+
"default": true
22+
},
23+
"app_name": {
24+
"type": "string",
25+
"minLength": 1,
26+
"description": "Application name as it will appear in New Relic",
27+
"examples": ["My Application"]
28+
},
29+
"log_level": {
30+
"type": "string",
31+
"enum": ["debug", "info", "warn", "error"],
32+
"description": "Log level for the agent"
33+
},
34+
"host": {
35+
"type": "string",
36+
"description": "New Relic collector host"
37+
},
38+
"labels": {
39+
"type": "string",
40+
"description": "Semicolon-separated list of key:value labels",
41+
"examples": ["Environment:Production;Team:Platform"]
42+
}
43+
},
44+
"required": ["license_key", "app_name"],
45+
"additionalProperties": false
46+
},
47+
"development": {
48+
"type": "object",
49+
"description": "Development environment specific configuration",
50+
"additionalProperties": true
51+
},
52+
"test": {
53+
"type": "object",
54+
"description": "Test environment specific configuration",
55+
"additionalProperties": true
56+
},
57+
"production": {
58+
"type": "object",
59+
"description": "Production environment specific configuration",
60+
"additionalProperties": true
61+
},
62+
"staging": {
63+
"type": "object",
64+
"description": "Staging environment specific configuration",
65+
"additionalProperties": true
66+
}
67+
},
68+
"required": ["common"],
69+
"additionalProperties": {
70+
"type": "object",
71+
"description": "Custom environment configuration",
72+
"additionalProperties": true
73+
}
74+
}

.github/workflows/test_action.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Action Test
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
push:
8+
branches:
9+
- '**'
10+
11+
jobs:
12+
action-test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v3
17+
18+
- name: Run Agent Metadata Action
19+
uses: ./
20+
with:
21+
cache: false

.github/workflows/unit_tests.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Go Unit Tests
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
push:
8+
branches:
9+
- '**'
10+
11+
jobs:
12+
test:
13+
name: Run Go Unit Tests
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- uses: actions/setup-go@v5
21+
with:
22+
go-version-file: 'go.mod'
23+
24+
- name: Cache Go modules
25+
uses: actions/cache@v3
26+
with:
27+
path: ~/go/pkg/mod
28+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
29+
restore-keys: |
30+
${{ runner.os }}-go-
31+
32+
- name: Download dependencies
33+
run: go mod download
34+
35+
- name: Run tests
36+
run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
37+
38+
- name: Display coverage
39+
run: go tool cover -func=coverage.out

CLAUDE.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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

README.md

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,92 @@
11
<a href="https://opensource.newrelic.com/oss-category/#community-project"><picture><source media="(prefers-color-scheme: dark)" srcset="https://github.com/newrelic/opensource-website/raw/main/src/images/categories/dark/Community_Project.png"><source media="(prefers-color-scheme: light)" srcset="https://github.com/newrelic/opensource-website/raw/main/src/images/categories/Community_Project.png"><img alt="New Relic Open Source community project banner." src="https://github.com/newrelic/opensource-website/raw/main/src/images/categories/Community_Project.png"></picture></a>
22

3-
# [Name of Project] [build badges go here when available]
3+
# Agent Metadata Action
44

5-
>[Brief description - what is the project and value does it provide? How often should users expect to get releases? How is versioning set up? Where does this project want to go?]
5+
A GitHub Action that reads agent configuration metadata from a checked-out repository. This action parses the `.fleetControl/configurationDefinitions.yml` file and makes the configuration data available for downstream workflow steps.
66

77
## Installation
88

9-
> [Include a step-by-step procedure on how to get your code installed. Be sure to include any third-party dependencies that need to be installed separately]
9+
Add this action to your workflow after checking out your repository:
1010

11-
## Getting Started
12-
>[Simple steps to start working with the software similar to a "Hello World"]
11+
```yaml
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
15+
- name: Read agent metadata
16+
uses: newrelic/agent-metadata-action@v1
17+
```
1318
1419
## Usage
15-
>[**Optional** - Include more thorough instructions on how to use the software. This section might not be needed if the Getting Started section is enough. Remove this section if it's not needed.]
1620
21+
This action reads the `.fleetControl/configurationDefinitions.yml` file from your repository and outputs the configuration definitions. The action expects the file to be present after the repository has been checked out.
22+
23+
### Example Workflow
24+
25+
```yaml
26+
name: Process Agent Metadata
27+
on:
28+
push:
29+
branches: [main]
30+
31+
jobs:
32+
read-metadata:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Checkout repository
36+
uses: actions/checkout@v4
37+
38+
- name: Read agent metadata
39+
uses: newrelic/agent-metadata-action@v1
40+
with:
41+
cache: true # Optional: Enable Go build cache (default: true)
42+
```
43+
44+
### Configuration File Format
45+
46+
The action expects a YAML file at `.fleetControl/configurationDefinitions.yml` with the following structure:
47+
48+
```yaml
49+
configurationDefinitions:
50+
- name: "Configuration Name"
51+
slug: "config-slug"
52+
platform: "kubernetes" # or "host"
53+
description: "Description of the configuration"
54+
type: "config-type"
55+
version: "1.0.0"
56+
format: "json"
57+
schema: "./schemas/config-schema.json"
58+
```
1759

1860
## Building
1961

20-
>[**Optional** - Include this section if users will need to follow specific instructions to build the software from source. Be sure to include any third party build dependencies that need to be installed separately. Remove this section if it's not needed.]
62+
To build the action locally:
63+
64+
```bash
65+
# Build the binary
66+
go build -o agent-metadata-action ./cmd/agent-metadata-action
67+
68+
# Run locally (requires GITHUB_WORKSPACE environment variable)
69+
export GITHUB_WORKSPACE=/path/to/your/repo
70+
./agent-metadata-action
71+
```
2172

2273
## Testing
2374

24-
>[**Optional** - Include instructions on how to run tests if we include tests with the codebase. Remove this section if it's not needed.]
75+
Run the test suite:
76+
77+
```bash
78+
# Run all tests
79+
go test ./...
80+
81+
# Run tests with verbose output
82+
go test -v ./...
83+
84+
# Run tests for a specific package
85+
go test -v ./internal/config
86+
87+
# Run a specific test
88+
go test -v -run TestLoadEnv_Success ./internal/config
89+
```
2590

2691
## Support
2792

@@ -31,7 +96,7 @@ New Relic hosts and moderates an online forum where you can interact with New Re
3196

3297
## Contribute
3398

34-
We encourage your contributions to improve [project name]! Keep in mind that when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project.
99+
We encourage your contributions to improve Agent Metadata Action! Keep in mind that when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project.
35100

36101
If you have any questions, or to execute our corporate CLA (which is required if your contribution is on behalf of a company), drop us an email at [email protected].
37102

@@ -43,8 +108,8 @@ If you believe you have found a security vulnerability in this project or any of
43108

44109
If you would like to contribute to this project, review [these guidelines](./CONTRIBUTING.md).
45110

46-
To all contributors, we thank you! Without your contribution, this project would not be what it is today. We also host a community project page dedicated to [Project Name](<LINK TO https://opensource.newrelic.com/projects/... PAGE>).
111+
To all contributors, we thank you! Without your contribution, this project would not be what it is today.
47112

48113
## License
49-
[Project Name] is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License.
50-
>[If applicable: The [project name] also uses source code from third-party libraries. You can find full details on which libraries are used and the terms under which they are licensed in the third-party notices document.]
114+
115+
Agent Metadata Action is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License.

0 commit comments

Comments
 (0)