structlint is designed to work seamlessly in CI/CD pipelines.
name: Validate Structure
on: [push, pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version: '1.25.x'
- name: Install structlint
run: go install github.com/AxeForging/structlint@latest
- name: Validate structure
run: structlint validate --config .structlint.yamlUse annotation output when you want violations to appear inline on pull requests.
- name: Validate structure
run: structlint validate --format githubUse SARIF when your pipeline collects code-scanning reports.
- name: Validate structure
run: structlint validate --format sarif > structlint.sarif
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: structlint.sarif - name: Validate structure
run: structlint validate --json-output report.json
- name: Upload report
uses: actions/upload-artifact@v4
if: always()
with:
name: structlint-report
path: report.jsonstructlint:
image: golang:1.24
stage: test
script:
- go install github.com/AxeForging/structlint@latest
- structlint validate --config .structlint.yaml
artifacts:
when: always
paths:
- report.json
expire_in: 1 weekBaselines let legacy repositories adopt structlint without blocking every existing violation. First, create a report from the current state:
structlint validate --json-output .structlint-baseline.json || trueThen fail only on new violations:
structlint validate --baseline .structlint-baseline.jsonThe baseline matches typed violations by code, path, and rule.
For fast pull-request checks, validate only changed files:
structlint validate --changed-onlyThis uses git diff --name-only --diff-filter=ACMRT HEAD. Repository-wide requirements such as required paths still run, while file-oriented checks are limited to changed files.
pipeline {
agent any
stages {
stage('Validate Structure') {
steps {
sh 'go install github.com/AxeForging/structlint@latest'
sh 'structlint validate --json-output report.json'
}
post {
always {
archiveArtifacts artifacts: 'report.json'
}
}
}
}
}structlint hook installAuto-detects lefthook, pre-commit, or a raw git hook and merges a structlint validate --staged --silent invocation. Idempotent.
structlint ships a .pre-commit-hooks.yaml, so consumers can pin it directly:
# .pre-commit-config.yaml
repos:
- repo: https://github.com/AxeForging/structlint
rev: v0.X.Y # first tag containing .pre-commit-hooks.yaml
hooks:
- id: structlintThe hook runs structlint validate --staged --silent via language: golang, so pre-commit clones the pinned rev and installs the binary in an isolated environment — no local install required.
# lefthook.yml
pre-commit:
commands:
structlint:
run: structlint validate --staged --silentrepos:
- repo: local
hooks:
- id: structlint
name: structlint
entry: structlint validate --staged --silent
language: system
pass_filenames: false
always_run: trueFROM golang:1.24-alpine AS builder
RUN go install github.com/AxeForging/structlint@latest
FROM alpine:latest
COPY --from=builder /go/bin/structlint /usr/local/bin/
ENTRYPOINT ["structlint"]Usage:
docker run --rm -v $(pwd):/project -w /project structlint validate.PHONY: lint-structure
lint-structure:
@structlint validate --config .structlint.yaml
ci: lint test lint-structure build-
Run early in the pipeline - Structure validation is fast and catches issues before expensive builds
-
Use typed output in CI - Prefer
--format github,--format sarif, or--json-output -
Generate reports - Always generate JSON reports for debugging
-
Cache the binary - In GitHub Actions, Go install is cached automatically with
actions/setup-go -
Fail fast - Put structlint before tests to catch structure issues immediately