Back to list
earthly

lunar-collector

by earthly

1🍴 0📅 Jan 25, 2026

SKILL.md


name: lunar-collector description: Create Lunar collector plugins that gather SDLC metadata for guardrail enforcement. Use when building collectors (Bash scripts) that collect data from repositories, CI pipelines, or external APIs and write to the Component JSON. Covers hook types (code, cron, ci-after-command), the lunar collect command, plugin structure, containerization, and best practices.

Lunar Collector Skill

Create collector plugins for Earthly Lunar—Bash scripts that gather SDLC metadata and write it to the Component JSON for policy evaluation.

Quick Start

  1. Read about-lunar.md for platform overview
  2. Read core-concepts.md for architecture and key entities
  3. Read collector-reference.md for comprehensive collector documentation

Collector Basics

A collector is a Bash script that:

  1. Gathers data (from files, CI artifacts, external APIs)
  2. Writes to the Component JSON using lunar collect
#!/bin/bash
set -e

if [ -f ./README.md ]; then
  lunar collect -j ".repo.readme_exists" true \
                   ".repo.readme_num_lines" "$(wc -l < ./README.md)"
else
  lunar collect -j ".repo.readme_exists" false
fi

Plugin Structure

my-collector/
├── lunar-collector.yml    # Required: plugin config
├── main.sh                # Main script
├── Dockerfile             # Optional: for containerization
├── README.md              # Documentation
└── install.sh             # Optional: install dependencies

lunar-collector.yml:

version: 0
name: my-collector
description: Collects X data
author: team@example.com

default_image: earthly/lunar-scripts:1.0.0

collectors:
  - name: my-collector
    mainBash: main.sh
    hook:
      type: code  # or: cron, ci-after-command, ci-after-job, etc.

inputs:
  threshold:
    description: Minimum threshold
    default: "10"

Hook Types

HookTriggerUse Case
codeGit pushFile analysis, config parsing
cronScheduleExternal API queries
ci-after-commandAfter CI commandCapture test coverage, scan results
ci-after-jobAfter CI jobJob-level artifact collection

The lunar collect Command

# String value
lunar collect ".repo.language" "go"

# JSON values (use -j)
lunar collect -j ".repo.readme_exists" true
lunar collect -j ".coverage.percentage" 85.5

# Multiple values
lunar collect -j ".repo.readme_exists" true ".repo.readme_lines" 150

# Pipe JSON from stdin
cat results.json | lunar collect -j ".test.results" -

Environment Variables

VariableDescription
LUNAR_COMPONENT_IDComponent identifier
LUNAR_COMPONENT_PRPR number (if in PR context)
LUNAR_COMPONENT_GIT_SHAGit SHA being evaluated
LUNAR_PLUGIN_ROOTPlugin root directory
LUNAR_SECRET_<NAME>Secrets

Inputs are available as uppercase environment variables (e.g., THRESHOLD for input threshold).

Reference Documentation

For detailed information, read these files in the references/ directory:

FileContent
about-lunar.mdPlatform overview, why Lunar exists
core-concepts.mdArchitecture, Component JSON, hooks, enforcement levels
collector-reference.mdComplete collector guide - hooks, environment variables, patterns
component-json/conventions.mdComponent JSON schema design principles, presence detection, source metadata
component-json/structure.mdComponent JSON schema categories (.repo, .k8s, .sca, etc.) with examples
strategies.mdImplementation strategies (CI detection, file parsing, API integration)
collector-README-template.mdREADME template for collector plugins

Full Lunar Documentation

For the complete Lunar platform documentation including installation, configuration, CLI reference, and SDK details, see docs/SUMMARY.md.

Local Development & Testing

Run collectors locally to test before deploying. Commands must be run from a directory containing lunar-config.yml.

Prerequisites:

  • Set LUNAR_HUB_TOKEN environment variable for authentication
  • Be in a directory with a valid lunar-config.yml

Run a collector against a remote component:

lunar collector dev <collector-name> --verbose --component github.com/org/repo

Run a collector against a local directory:

lunar collector dev <collector-name> --verbose --component-dir ../path/to/local/repo

Test a CI collector with a fake command:

lunar collector dev <collector-name> --fake-ci-cmd "npm test" --component github.com/org/repo

Collector names are dot-separated (e.g., k8s.yaml-collection, dockerfile.base-images).

The command outputs the resulting Component JSON to stdout, which can be piped to lunar policy dev for end-to-end testing:

lunar collector dev my-collector --component github.com/org/repo | \
  lunar policy dev my-policy --component-json -

Best Practices

  1. Always use set -e - Exit on errors
  2. Use structured JSON - Group related data together
  3. Include source metadata - Tool name, version, integration type
  4. Document Component JSON paths - In README.md
  5. Use earthly/lunar-scripts:1.0.0 - Official base image for containerized collectors
  6. Handle missing data gracefully - Check file existence before processing

Common Patterns

File parsing with find command input:

inputs:
  find_command:
    description: Command to find files
    default: "find . -type f -name '*.yaml'"

CI artifact collection:

# Hook: ci-after-command with pattern: ^go test.*
if [ -f coverage.out ]; then
  COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | tr -d '%')
  lunar collect -j ".testing.coverage.percentage" "$COVERAGE"
fi

External API query:

RESPONSE=$(curl -fsS -H "Authorization: Bearer $LUNAR_SECRET_API_TOKEN" \
  "https://api.example.com/repos/$LUNAR_COMPONENT_ID/status")
echo "$RESPONSE" | lunar collect -j ".external.status" -

Score

Total Score

60/100

Based on repository quality metrics

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

Reviews

💬

Reviews coming soon