Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
735b433
feat: add pre-commit hooks and CI workflow
osterman Sep 7, 2025
b803e37
docs: add development guide with pre-commit workflow
osterman Sep 7, 2025
2198f29
chore: update .gitignore for .atmos.d directory
osterman Sep 7, 2025
12423af
feat: add check-pr command for PR-specific pre-commit checks
osterman Sep 7, 2025
338d912
fix: separate check from format commands to prevent accidental modifi…
osterman Sep 7, 2025
084cb67
fix: prevent test interference from repository .atmos.d directory
osterman Sep 8, 2025
ddb1da9
fix: correct exclusion logic for .atmos.d in tests
osterman Sep 8, 2025
4306fd4
fix: use TEST_GIT_ROOT to mock Git repository root in tests
osterman Sep 17, 2025
7264a96
fix: add TEST_EXCLUDE_ATMOS_D for tests with parent directory workdir
osterman Sep 17, 2025
b16c34b
fix: correct test isolation and use proper test scenarios
osterman Sep 20, 2025
e7fed91
fix: remove redundant help command from dev.yaml
osterman Sep 20, 2025
185dd1e
fix: improve cross-platform path handling in test exclusion logic
osterman Sep 20, 2025
d84436b
test: add comprehensive tests for .atmos.d exclusion logic
osterman Sep 20, 2025
036b275
test: improve mergeDefaultImports tests with proper assertions and cr…
osterman Sep 20, 2025
978de0e
fix: make dev validate command fail fast on lint/vet errors
osterman Sep 20, 2025
d876d7d
refactor: extract test exclusion logic into shouldExcludePathForTesti…
osterman Sep 20, 2025
5d2d2b3
fix: remove invalid severity configuration from golangci-lint config
osterman Sep 20, 2025
48fdeaf
fix: use --unsafe flag for check-yaml to support Atmos custom YAML tags
osterman Sep 20, 2025
93374d1
fix: correct YAML structure for dev subcommands to nest under 'atmos …
osterman Sep 21, 2025
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
18 changes: 18 additions & 0 deletions .atmos.d/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Atmos Custom Commands

This directory contains custom Atmos commands that are automatically loaded when you run `atmos` from the repository root.

## Development Commands

The `dev.yaml` file defines development workflow commands that help maintain code quality:

- `atmos dev setup` - Set up local development environment
- `atmos dev check` - Run pre-commit hooks on staged files
- `atmos dev check-all` - Run pre-commit hooks on all files
- `atmos dev lint` - Run golangci-lint

## Why Custom Commands?

We use Atmos custom commands for our development workflow as a form of "dogfooding" - using our own tool to manage our development process. This ensures we experience the same workflows our users do and helps us identify areas for improvement.

For more information on custom commands, see the [Atmos Custom Commands documentation](https://atmos.tools/core-concepts/custom-commands/).
211 changes: 211 additions & 0 deletions .atmos.d/dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
name: dev
description: Development workflow commands for Atmos development
commands:
- name: setup
description: Set up local development environment
steps:
- |
echo "🚀 Setting up Atmos development environment..."

echo "1️⃣ Installing Go dependencies..."
go mod download

echo "2️⃣ Installing pre-commit and golangci-lint..."
if ! command -v pre-commit >/dev/null 2>&1; then
if command -v brew >/dev/null 2>&1; then
echo "Installing pre-commit via Homebrew..."
brew install pre-commit
elif command -v apt-get >/dev/null 2>&1; then
echo "Installing pre-commit via apt..."
sudo apt-get update && sudo apt-get install -y pre-commit
else
echo "Installing pre-commit via pip..."
pip install --user pre-commit || pip install pre-commit
fi
else
echo "pre-commit is already installed: $(pre-commit --version)"
fi

if ! command -v golangci-lint >/dev/null 2>&1; then
if command -v brew >/dev/null 2>&1; then
echo "Installing golangci-lint via Homebrew..."
brew install golangci-lint
else
echo "Installing golangci-lint via curl..."
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
fi
else
echo "golangci-lint is already installed: $(golangci-lint --version)"
fi

echo "3️⃣ Installing pre-commit hooks..."
pre-commit install

echo "4️⃣ Installing Go tools..."
go install mvdan.cc/gofumpt@latest

echo "✅ Development environment setup complete!"
echo ""
echo "Run 'atmos dev check' to check staged files (read-only)"
echo "Run 'atmos dev check-pr' to check PR changes (read-only)"
echo "Run 'atmos dev format' to auto-format staged files"
echo "Run 'atmos dev format-pr' to auto-format PR changes"

- name: check
description: Check staged files for issues (read-only, no modifications)
steps:
- |
echo "🔍 Checking staged files (read-only)..."
# Run checks without modifying files
STAGED_GO_FILES=$(git diff --cached --name-only --diff-filter=ACM -- '*.go' | grep -v -E '^(vendor/|tests/test-cases/|tests/testdata/|tests/snapshots/)' || true)
if [ -n "$STAGED_GO_FILES" ]; then
echo "Checking Go formatting..."
echo "$STAGED_GO_FILES" | xargs -I {} gofumpt -d {} 2>/dev/null | head -20 || true
echo "Running golangci-lint..."
golangci-lint run --new-from-rev=origin/main --config=.golangci.yml $STAGED_GO_FILES || true
fi
echo "💡 To auto-fix issues, run: atmos dev format"

- name: check-pr
description: Check PR changes for issues (read-only, no modifications)
steps:
- |
echo "🔍 Checking PR changes (read-only)..."
BASE_REF="${GITHUB_BASE_REF:-main}"
# Get changed Go files
CHANGED_GO_FILES=$(git diff origin/$BASE_REF...HEAD --name-only -- '*.go' | grep -v -E '^(vendor/|tests/test-cases/|tests/testdata/|tests/snapshots/)' || true)
if [ -n "$CHANGED_GO_FILES" ]; then
echo "Checking Go formatting..."
echo "$CHANGED_GO_FILES" | xargs -I {} gofumpt -d {} 2>/dev/null | head -20 || true
echo "Running golangci-lint..."
golangci-lint run --new-from-rev=origin/$BASE_REF --config=.golangci.yml || true
fi
echo "💡 To auto-fix issues, run: atmos dev format-pr"

- name: check-all
description: Check all files for issues (read-only, no modifications)
steps:
- |
echo "🔍 Checking all files (read-only)..."
echo "⚠️ This may take a while..."
# Check formatting without modifying
echo "Checking Go formatting..."
find . -name '*.go' -not -path './vendor/*' -not -path './tests/test-cases/*' -not -path './tests/testdata/*' -not -path './tests/snapshots/*' | xargs gofumpt -d 2>/dev/null | head -50 || true
echo "Running comprehensive linting..."
golangci-lint run --config=.golangci.yml || true
echo "💡 To auto-fix issues, run: atmos dev format-all (⚠️ DANGEROUS)"

- name: format
description: Auto-format staged files
steps:
- |
echo "🔧 Auto-formatting staged files..."
pre-commit run || true
echo "✅ Formatting applied to staged files"

- name: format-pr
description: Auto-format PR changes
steps:
- |
echo "🔧 Auto-formatting PR changes..."
BASE_REF="${GITHUB_BASE_REF:-main}"
pre-commit run --from-ref origin/$BASE_REF --to-ref HEAD || true
echo "✅ Formatting applied to PR changes"

- name: format-all
description: ⚠️ DANGEROUS - Auto-format ALL files (excludes golden snapshots)
steps:
- |
echo "⚠️ WARNING: This will modify many files!"
echo " Excludes: vendor/, tests/test-cases/, tests/testdata/, tests/snapshots/"
echo " Golden snapshots and fixtures are protected."
echo ""
echo " Press Ctrl+C to cancel, or wait 5 seconds to continue..."
sleep 5
echo "🔧 Auto-formatting all files..."
# Run pre-commit on all files with our exclude patterns
pre-commit run --all-files || true
echo "✅ Formatting complete. Review changes with: git diff"

- name: lint
description: Run golangci-lint
steps:
- golangci-lint run --config=.golangci.yml

- name: test
description: Run tests
steps:
- go test ./... -v

- name: validate
description: Validate code by running build, lint, and tests
steps:
- |
echo "🔨 Building..."
go build ./... || { echo "❌ Build failed"; exit 1; }

echo "🔍 Linting..."
if command -v golangci-lint >/dev/null 2>&1; then
golangci-lint run --config=.golangci.yml || { echo "⚠️ Linting issues found"; }
else
echo "⚠️ golangci-lint not found, falling back to go vet..."
go vet ./... || { echo "⚠️ go vet found issues"; }
fi

echo "🧪 Testing..."
go test ./... -v || { echo "❌ Tests failed"; exit 1; }

echo "✅ Validation complete!"

- name: build
description: Build the Atmos binary
steps:
- make build

- name: quick
description: Quick build and test
steps:
- |
echo "🏃 Running quick build and test..."
make build
./build/atmos version
echo "✅ Quick build successful!"

- name: update-hooks
description: Update pre-commit hooks to latest versions
steps:
- pre-commit autoupdate

- name: help
description: Show available dev commands
steps:
- |
echo "Available Atmos dev commands:"
echo ""
echo " atmos dev setup - Set up local development environment"
echo ""
echo " Checking (read-only, no modifications):"
echo " atmos dev check - Check staged files for issues"
echo " atmos dev check-pr - Check PR changes for issues"
echo " atmos dev check-all - Check all files for issues"
echo ""
echo " Formatting (modifies files):"
echo " atmos dev format - Auto-format staged files"
echo " atmos dev format-pr - Auto-format PR changes"
echo " atmos dev format-all - ⚠️ DANGEROUS: Auto-format ALL files"
echo ""
echo " atmos dev lint - Run golangci-lint"
echo " atmos dev test - Run tests"
echo " atmos dev build - Build the Atmos binary"
echo " atmos dev quick - Quick build and test"
echo " atmos dev update-hooks - Update pre-commit hooks to latest versions"
echo ""
echo "Pre-commit hooks include:"
echo " - go-fumpt: Go code formatting"
echo " - go-build-mod: Verify Go compilation"
echo " - go-mod-tidy: Ensure go.mod is tidy"
echo " - golangci-lint: Comprehensive Go linting"
echo " - trailing-whitespace: Remove trailing whitespace"
echo " - end-of-file-fixer: Ensure files end with newline"
echo " - check-yaml: Validate YAML files"
echo " - check-added-large-files: Prevent large files"
51 changes: 51 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Pre-commit

on:
pull_request:
types: [opened, synchronize, reopened]

env:
# Ensure pre-commit uses the right Python version
PYTHON_VERSION: "3.11"

jobs:
pre-commit:
name: Run pre-commit hooks
runs-on: ubuntu-latest
timeout-minutes: 15

steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
# Fetch full history for proper diff checking
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true

- name: Install Go tools
run: |
# Install gofumpt for pre-commit
go install mvdan.cc/gofumpt@latest

# Install golangci-lint
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

# Add Go bin to PATH
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Run CloudPosse pre-commit action
uses: cloudposse/[email protected]
with:
# Run against files changed in the PR only
# This prevents formatting/checking unrelated files
extra_args: --from-ref ${{ github.event.pull_request.base.sha }} --to-ref HEAD
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
**/.atmos/cache.yaml
**/cache.*.txt

# Development configs - track only specific files
.atmos.d/*
!.atmos.d/dev.yaml
!.atmos.d/README.md

# Ignore components vendored during tests
examples/demo-vendoring/components/**
tests/fixtures/scenarios/vendor-globs/components/**
Expand Down
44 changes: 44 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
repos:
# Go-specific hooks
- repo: https://github.com/tekwizely/pre-commit-golang
rev: v1.0.0-rc.1
hooks:
- id: go-fumpt
args: [-w]
exclude: ^(vendor/|tests/test-cases/|tests/testdata/|tests/snapshots/)

- id: go-build-mod
name: Check Go build
description: Ensure code compiles before commit

- id: go-mod-tidy
name: Tidy go.mod
description: Ensure go.mod and go.sum are clean

# Run golangci-lint using system binary to avoid Go 1.25 compatibility issues
- repo: local
hooks:
- id: golangci-lint
name: golangci-lint
description: Run golangci-lint on modified Go files
entry: golangci-lint run --new-from-rev=origin/main --config=.golangci.yml
language: system
types: [go]
pass_filenames: false
require_serial: true
exclude: ^(vendor/|tests/test-cases/|tests/testdata/|tests/snapshots/)

# General file hygiene
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
exclude: ^(vendor/|tests/test-cases/|tests/testdata/|tests/snapshots/|.*\.md)
- id: end-of-file-fixer
exclude: ^(vendor/|tests/test-cases/|tests/testdata/|tests/snapshots/)
- id: check-yaml
exclude: ^(examples/|tests/test-cases/|vendor/)
args: [--allow-multiple-documents]
- id: check-added-large-files
args: [--maxkb=500]
exclude: ^(docs/demo.gif|website/)
Loading
Loading