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@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
- 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'
}
}
}
}
}Add to .pre-commit-config.yaml:
repos:
- repo: local
hooks:
- id: structlint
name: structlint
entry: structlint validate
language: system
pass_filenames: false
always_run: trueOr with lefthook (.lefthook.yml):
pre-commit:
commands:
structlint:
run: structlint validate --silentFROM 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