-
-
Notifications
You must be signed in to change notification settings - Fork 133
feat: add pre-commit hooks and development workflow #1469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
osterman
wants to merge
19
commits into
main
Choose a base branch
from
precommit-hooks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,320
−421
Open
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 b803e37
docs: add development guide with pre-commit workflow
osterman 2198f29
chore: update .gitignore for .atmos.d directory
osterman 12423af
feat: add check-pr command for PR-specific pre-commit checks
osterman 338d912
fix: separate check from format commands to prevent accidental modifi…
osterman 084cb67
fix: prevent test interference from repository .atmos.d directory
osterman ddb1da9
fix: correct exclusion logic for .atmos.d in tests
osterman 4306fd4
fix: use TEST_GIT_ROOT to mock Git repository root in tests
osterman 7264a96
fix: add TEST_EXCLUDE_ATMOS_D for tests with parent directory workdir
osterman b16c34b
fix: correct test isolation and use proper test scenarios
osterman e7fed91
fix: remove redundant help command from dev.yaml
osterman 185dd1e
fix: improve cross-platform path handling in test exclusion logic
osterman d84436b
test: add comprehensive tests for .atmos.d exclusion logic
osterman 036b275
test: improve mergeDefaultImports tests with proper assertions and cr…
osterman 978de0e
fix: make dev validate command fail fast on lint/vet errors
osterman d876d7d
refactor: extract test exclusion logic into shouldExcludePathForTesti…
osterman 5d2d2b3
fix: remove invalid severity configuration from golangci-lint config
osterman 48fdeaf
fix: use --unsafe flag for check-yaml to support Atmos custom YAML tags
osterman 93374d1
fix: correct YAML structure for dev subcommands to nest under 'atmos …
osterman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" | ||
|
||
osterman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
- 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.