Skip to content

Commit 52ccdb2

Browse files
committed
feat: add GitHub Action for CI/CD usage
1 parent b47c8a1 commit 52ccdb2

File tree

2 files changed

+167
-0
lines changed

2 files changed

+167
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# TreeMapper GitHub Action
2+
3+
Export your codebase for AI/LLM context in CI/CD pipelines.
4+
5+
## Usage
6+
7+
```yaml
8+
- uses: nikolay-e/treemapper/.github/actions/treemapper@main
9+
with:
10+
path: './src'
11+
format: 'yaml'
12+
output: 'context.yaml'
13+
```
14+
15+
## Inputs
16+
17+
| Input | Description | Default |
18+
|-------|-------------|---------|
19+
| `path` | Directory to analyze | `.` |
20+
| `format` | Output format (yaml/json/txt/md) | `yaml` |
21+
| `output` | Output file path | `tree.yaml` |
22+
| `max-depth` | Maximum traversal depth | unlimited |
23+
| `no-content` | Skip file contents | `false` |
24+
| `max-file-bytes` | Skip large files (bytes) | 10MB |
25+
| `ignore-file` | Custom ignore file | - |
26+
| `no-default-ignores` | Disable default ignores | `false` |
27+
28+
## Outputs
29+
30+
| Output | Description |
31+
|--------|-------------|
32+
| `output-file` | Path to generated file |
33+
| `token-count` | Approximate token count |
34+
35+
## Examples
36+
37+
### Upload as artifact
38+
39+
```yaml
40+
- uses: nikolay-e/treemapper/.github/actions/treemapper@main
41+
with:
42+
output: 'codebase.yaml'
43+
44+
- uses: actions/upload-artifact@v4
45+
with:
46+
name: llm-context
47+
path: codebase.yaml
48+
```
49+
50+
### PR comment with token count
51+
52+
```yaml
53+
- uses: nikolay-e/treemapper/.github/actions/treemapper@main
54+
id: treemap
55+
with:
56+
path: './src'
57+
58+
- uses: actions/github-script@v7
59+
with:
60+
script: |
61+
github.rest.issues.createComment({
62+
owner: context.repo.owner,
63+
repo: context.repo.repo,
64+
issue_number: context.issue.number,
65+
body: `📊 Codebase: ${{ steps.treemap.outputs.token-count }}`
66+
})
67+
```
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: 'TreeMapper'
2+
description: 'Export codebase structure and contents for AI/LLM context'
3+
author: 'nikolay-e'
4+
5+
branding:
6+
icon: 'folder'
7+
color: 'blue'
8+
9+
inputs:
10+
path:
11+
description: 'Directory to analyze'
12+
required: false
13+
default: '.'
14+
format:
15+
description: 'Output format (yaml, json, txt, md)'
16+
required: false
17+
default: 'yaml'
18+
output:
19+
description: 'Output file path'
20+
required: false
21+
default: 'tree.yaml'
22+
max-depth:
23+
description: 'Maximum traversal depth'
24+
required: false
25+
no-content:
26+
description: 'Skip file contents (structure only)'
27+
required: false
28+
default: 'false'
29+
max-file-bytes:
30+
description: 'Skip files larger than N bytes (0 for unlimited)'
31+
required: false
32+
ignore-file:
33+
description: 'Path to custom ignore file'
34+
required: false
35+
no-default-ignores:
36+
description: 'Disable default ignores'
37+
required: false
38+
default: 'false'
39+
python-version:
40+
description: 'Python version to use'
41+
required: false
42+
default: '3.11'
43+
44+
outputs:
45+
output-file:
46+
description: 'Path to generated output file'
47+
value: ${{ steps.run.outputs.output-file }}
48+
token-count:
49+
description: 'Approximate token count'
50+
value: ${{ steps.run.outputs.token-count }}
51+
52+
runs:
53+
using: 'composite'
54+
steps:
55+
- name: Set up Python
56+
uses: actions/setup-python@v5
57+
with:
58+
python-version: ${{ inputs.python-version }}
59+
60+
- name: Install treemapper
61+
shell: bash
62+
run: pip install treemapper
63+
64+
- name: Run treemapper
65+
id: run
66+
shell: bash
67+
run: |
68+
ARGS="${{ inputs.path }}"
69+
ARGS="$ARGS -f ${{ inputs.format }}"
70+
ARGS="$ARGS -o ${{ inputs.output }}"
71+
72+
if [ -n "${{ inputs.max-depth }}" ]; then
73+
ARGS="$ARGS --max-depth ${{ inputs.max-depth }}"
74+
fi
75+
76+
if [ "${{ inputs.no-content }}" = "true" ]; then
77+
ARGS="$ARGS --no-content"
78+
fi
79+
80+
if [ -n "${{ inputs.max-file-bytes }}" ]; then
81+
ARGS="$ARGS --max-file-bytes ${{ inputs.max-file-bytes }}"
82+
fi
83+
84+
if [ -n "${{ inputs.ignore-file }}" ]; then
85+
ARGS="$ARGS -i ${{ inputs.ignore-file }}"
86+
fi
87+
88+
if [ "${{ inputs.no-default-ignores }}" = "true" ]; then
89+
ARGS="$ARGS --no-default-ignores"
90+
fi
91+
92+
# Capture stderr for token count
93+
OUTPUT=$(treemapper $ARGS 2>&1 >/dev/null) || true
94+
TOKEN_COUNT=$(echo "$OUTPUT" | grep -oE '^~?[0-9,]+ tokens' | head -1 || echo "unknown")
95+
96+
echo "output-file=${{ inputs.output }}" >> $GITHUB_OUTPUT
97+
echo "token-count=$TOKEN_COUNT" >> $GITHUB_OUTPUT
98+
99+
# Actually run it
100+
treemapper $ARGS

0 commit comments

Comments
 (0)