Skip to content

Commit a99abc5

Browse files
committed
fix: catch linter output in general way
Signed-off-by: Josef Andersson <janderssonse@proton.me>
1 parent 4faafa1 commit a99abc5

30 files changed

+584
-165
lines changed

linters/commits.sh

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,55 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1010
source "${SCRIPT_DIR}/../utils/colors.sh"
1111
source "${SCRIPT_DIR}/../utils/git-utils.sh"
1212

13+
emit_status() {
14+
[[ "${DEVBASE_CHECK_MARKERS:-0}" == "1" ]] || return 0
15+
printf "DEVBASE_CHECK_STATUS=%s\n" "$1"
16+
[[ -n "${2:-}" ]] && printf "DEVBASE_CHECK_DETAILS=%s\n" "$2"
17+
}
18+
1319
main() {
14-
print_header "COMMIT HEALTH (GOMMITLINT)"
15-
16-
local current_branch default_branch
17-
current_branch=$(git branch --show-current)
18-
default_branch=$(get_default_branch)
19-
20-
# Skip if on the base branch itself (gommitlint can't handle base..HEAD when they're the same)
21-
if [[ "$current_branch" == "$default_branch" ]]; then
22-
print_info "On ${default_branch} - no commits to check against base branch"
23-
return 0
24-
fi
25-
26-
if ! has_commits_since "$default_branch"; then
27-
print_info "No commits to check on ${current_branch} (compared to ${default_branch})"
28-
return 0
29-
fi
30-
31-
# Detect SHA-256 repo and select correct binary
32-
# See: https://github.com/go-git/go-git/issues/706
33-
local gommitlint_cmd="gommitlint"
34-
if git rev-parse --show-object-format 2>/dev/null | grep -q sha256; then
35-
gommitlint_cmd="gommitlint-sha256"
36-
fi
37-
38-
if ! command -v "$gommitlint_cmd" >/dev/null 2>&1; then
39-
print_warning "${gommitlint_cmd} not found in PATH - skipping commit linting"
40-
echo " Install: mise install"
41-
return 0
42-
fi
43-
44-
if $gommitlint_cmd validate --base-branch="${default_branch}" 2>/dev/null; then
45-
print_success "Commit health check passed"
46-
return 0
47-
else
48-
print_error "Commit health check failed - check your commit messages"
49-
return 1
50-
fi
20+
print_header "COMMIT HEALTH (GOMMITLINT)"
21+
22+
local current_branch default_branch
23+
current_branch=$(git branch --show-current)
24+
default_branch=$(get_default_branch)
25+
26+
# Skip if on the base branch itself (gommitlint can't handle base..HEAD when they're the same)
27+
if [[ "$current_branch" == "$default_branch" ]]; then
28+
print_info "On ${default_branch} - no commits to check against base branch"
29+
emit_status "na" "n/a"
30+
return 0
31+
fi
32+
33+
if ! has_commits_since "$default_branch"; then
34+
print_info "No commits to check on ${current_branch} (compared to ${default_branch})"
35+
emit_status "na" "n/a"
36+
return 0
37+
fi
38+
39+
# Detect SHA-256 repo and select correct binary
40+
# See: https://github.com/go-git/go-git/issues/706
41+
local gommitlint_cmd="gommitlint"
42+
if git rev-parse --show-object-format 2>/dev/null | grep -q sha256; then
43+
gommitlint_cmd="gommitlint-sha256"
44+
fi
45+
46+
if ! command -v "$gommitlint_cmd" >/dev/null 2>&1; then
47+
print_warning "${gommitlint_cmd} not found in PATH - skipping commit linting"
48+
echo " Install: mise install"
49+
emit_status "skip" "not in PATH"
50+
return 0
51+
fi
52+
53+
if $gommitlint_cmd validate --base-branch="${default_branch}" 2>/dev/null; then
54+
print_success "Commit health check passed"
55+
emit_status "pass" "ok"
56+
return 0
57+
else
58+
print_error "Commit health check failed - check your commit messages"
59+
emit_status "fail" "failed"
60+
return 1
61+
fi
5162
}
5263

5364
main

linters/container.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ set -uo pipefail
99
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1010
source "${SCRIPT_DIR}/../utils/colors.sh"
1111

12+
emit_status() {
13+
[[ "${DEVBASE_CHECK_MARKERS:-0}" == "1" ]] || return 0
14+
printf "DEVBASE_CHECK_STATUS=%s\n" "$1"
15+
[[ -n "${2:-}" ]] && printf "DEVBASE_CHECK_DETAILS=%s\n" "$2"
16+
}
17+
1218
find_containerfiles() {
1319
find . -type f \( -name "Containerfile" -o -name "Containerfile.*" -o -name "Dockerfile" -o -name "Dockerfile.*" \) -not -path "./.git/*" 2>/dev/null
1420
}
@@ -21,12 +27,14 @@ main() {
2127

2228
if [[ -z "$files" ]]; then
2329
print_info "No Containerfile/Dockerfile found to check"
30+
emit_status "na" "n/a"
2431
return 0
2532
fi
2633

2734
if ! command -v hadolint >/dev/null 2>&1; then
2835
print_warning "hadolint not found in PATH - skipping container linting"
2936
echo " Install: mise install"
37+
emit_status "skip" "not in PATH"
3038
return 0
3139
fi
3240

@@ -40,9 +48,11 @@ main() {
4048

4149
if [[ $failed -eq 0 ]]; then
4250
print_success "Container linting passed"
51+
emit_status "pass" "ok"
4352
return 0
4453
else
4554
print_error "Container linting failed"
55+
emit_status "fail" "failed"
4656
return 1
4757
fi
4858
}

linters/github-actions.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,35 @@ set -uo pipefail
99
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1010
source "${SCRIPT_DIR}/../utils/colors.sh"
1111

12+
emit_status() {
13+
[[ "${DEVBASE_CHECK_MARKERS:-0}" == "1" ]] || return 0
14+
printf "DEVBASE_CHECK_STATUS=%s\n" "$1"
15+
[[ -n "${2:-}" ]] && printf "DEVBASE_CHECK_DETAILS=%s\n" "$2"
16+
}
17+
1218
main() {
1319
print_header "GITHUB ACTIONS LINTING (ACTIONLINT)"
1420

1521
if [[ ! -d .github/workflows ]]; then
1622
print_info "No GitHub Actions workflows found to check"
23+
emit_status "na" "n/a"
1724
return 0
1825
fi
1926

2027
if ! command -v actionlint >/dev/null 2>&1; then
2128
print_warning "actionlint not found in PATH - skipping GitHub Actions linting"
2229
echo " Install: mise install"
30+
emit_status "skip" "not in PATH"
2331
return 0
2432
fi
2533

2634
if actionlint; then
2735
print_success "GitHub Actions linting passed"
36+
emit_status "pass" "ok"
2837
return 0
2938
else
3039
print_error "GitHub Actions linting failed"
40+
emit_status "fail" "failed"
3141
return 1
3242
fi
3343
}

linters/java/checkstyle.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,34 @@ source "${SCRIPT_DIR}/../../utils/colors.sh"
1111

1212
maven_opts=(--batch-mode --no-transfer-progress --errors -Dstyle.color=always)
1313

14+
emit_status() {
15+
[[ "${DEVBASE_CHECK_MARKERS:-0}" == "1" ]] || return 0
16+
printf "DEVBASE_CHECK_STATUS=%s\n" "$1"
17+
[[ -n "${2:-}" ]] && printf "DEVBASE_CHECK_DETAILS=%s\n" "$2"
18+
}
19+
1420
main() {
1521
print_header "JAVA CHECKSTYLE"
1622

1723
if [[ ! -f pom.xml ]]; then
1824
print_warning "No pom.xml found, skipping"
25+
emit_status "skip" "skipped"
1926
return 0
2027
fi
2128

2229
if ! command -v mvn >/dev/null 2>&1; then
2330
print_error "mvn not found. Install with: mise install maven"
31+
emit_status "fail" "failed"
2432
return 1
2533
fi
2634

2735
if mvn "${maven_opts[@]}" checkstyle:check; then
2836
print_success "Checkstyle passed"
37+
emit_status "pass" "ok"
2938
return 0
3039
else
3140
print_error "Checkstyle failed"
41+
emit_status "fail" "failed"
3242
return 1
3343
fi
3444
}

linters/java/format.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,16 @@ source "${SCRIPT_DIR}/../../utils/colors.sh"
1212
maven_opts=(--batch-mode --no-transfer-progress --errors -Dstyle.color=always)
1313
readonly ACTION="${1:-check}"
1414

15+
emit_status() {
16+
[[ "${DEVBASE_CHECK_MARKERS:-0}" == "1" ]] || return 0
17+
printf "DEVBASE_CHECK_STATUS=%s\n" "$1"
18+
[[ -n "${2:-}" ]] && printf "DEVBASE_CHECK_DETAILS=%s\n" "$2"
19+
}
20+
1521
check_maven() {
1622
if ! command -v mvn >/dev/null 2>&1; then
1723
print_error "mvn not found. Install with: mise install maven"
24+
emit_status "fail" "failed"
1825
return 1
1926
fi
2027
}
@@ -27,9 +34,11 @@ check_format() {
2734
print_info "Checking Java formatting..."
2835
if mvn "${maven_opts[@]}" formatter:validate; then
2936
print_success "Java formatting check passed"
37+
emit_status "pass" "ok"
3038
return 0
3139
else
3240
print_error "Java formatting check failed - run 'just lint-java-fmt-fix' to fix"
41+
emit_status "fail" "failed"
3342
return 1
3443
fi
3544
}
@@ -38,9 +47,11 @@ fix_format() {
3847
print_info "Formatting Java code..."
3948
if mvn "${maven_opts[@]}" formatter:format; then
4049
print_success "Java code formatted"
50+
emit_status "pass" "ok"
4151
return 0
4252
else
4353
print_error "Java formatting failed"
54+
emit_status "fail" "failed"
4455
return 1
4556
fi
4657
}
@@ -50,6 +61,7 @@ main() {
5061

5162
if ! has_pom; then
5263
print_warning "No pom.xml found, skipping"
64+
emit_status "skip" "skipped"
5365
return 0
5466
fi
5567

@@ -63,6 +75,7 @@ main() {
6375
*)
6476
print_error "Unknown action: $ACTION"
6577
printf "Usage: %s [check|fix]\n" "$0"
78+
emit_status "fail" "failed"
6679
return 1
6780
;;
6881
esac

linters/java/lint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,31 @@ source "${SCRIPT_DIR}/../../utils/colors.sh"
1111

1212
maven_opts=(--batch-mode --no-transfer-progress --errors -Dstyle.color=always)
1313

14+
emit_status() {
15+
[[ "${DEVBASE_CHECK_MARKERS:-0}" == "1" ]] || return 0
16+
printf "DEVBASE_CHECK_STATUS=%s\n" "$1"
17+
[[ -n "${2:-}" ]] && printf "DEVBASE_CHECK_DETAILS=%s\n" "$2"
18+
}
19+
1420
main() {
1521
print_header "JAVA LINTING (ALL)"
1622

1723
if [[ ! -f pom.xml ]]; then
1824
print_warning "No pom.xml found, skipping"
25+
emit_status "skip" "skipped"
1926
return 0
2027
fi
2128

2229
if ! command -v mvn >/dev/null 2>&1; then
2330
print_error "mvn not found. Install with: mise install maven"
31+
emit_status "fail" "failed"
2432
return 1
2533
fi
2634

2735
print_info "Building project (skip tests)..."
2836
if ! mvn "${maven_opts[@]}" install -DskipTests; then
2937
print_error "Build failed"
38+
emit_status "fail" "failed"
3039
return 1
3140
fi
3241

@@ -38,9 +47,11 @@ main() {
3847

3948
if [[ $failed -eq 0 ]]; then
4049
print_success "All Java linting passed"
50+
emit_status "pass" "ok"
4151
return 0
4252
else
4353
print_error "Some Java linting failed"
54+
emit_status "fail" "failed"
4455
return 1
4556
fi
4657
}

linters/java/pmd.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,34 @@ source "${SCRIPT_DIR}/../../utils/colors.sh"
1111

1212
maven_opts=(--batch-mode --no-transfer-progress --errors -Dstyle.color=always)
1313

14+
emit_status() {
15+
[[ "${DEVBASE_CHECK_MARKERS:-0}" == "1" ]] || return 0
16+
printf "DEVBASE_CHECK_STATUS=%s\n" "$1"
17+
[[ -n "${2:-}" ]] && printf "DEVBASE_CHECK_DETAILS=%s\n" "$2"
18+
}
19+
1420
main() {
1521
print_header "JAVA PMD"
1622

1723
if [[ ! -f pom.xml ]]; then
1824
print_warning "No pom.xml found, skipping"
25+
emit_status "skip" "skipped"
1926
return 0
2027
fi
2128

2229
if ! command -v mvn >/dev/null 2>&1; then
2330
print_error "mvn not found. Install with: mise install maven"
31+
emit_status "fail" "failed"
2432
return 1
2533
fi
2634

2735
if mvn "${maven_opts[@]}" pmd:check; then
2836
print_success "PMD passed"
37+
emit_status "pass" "ok"
2938
return 0
3039
else
3140
print_error "PMD failed"
41+
emit_status "fail" "failed"
3242
return 1
3343
fi
3444
}

linters/java/spotbugs.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,24 @@ maven_opts=(--batch-mode --no-transfer-progress --errors -Dstyle.color=always)
1414
# Default exclude file from devbase-check (excludes generated-sources)
1515
DEFAULT_EXCLUDE="${SCRIPT_DIR}/config/spotbugs-exclude.xml"
1616

17+
emit_status() {
18+
[[ "${DEVBASE_CHECK_MARKERS:-0}" == "1" ]] || return 0
19+
printf "DEVBASE_CHECK_STATUS=%s\n" "$1"
20+
[[ -n "${2:-}" ]] && printf "DEVBASE_CHECK_DETAILS=%s\n" "$2"
21+
}
22+
1723
main() {
1824
print_header "JAVA SPOTBUGS"
1925

2026
if [[ ! -f pom.xml ]]; then
2127
print_warning "No pom.xml found, skipping"
28+
emit_status "skip" "skipped"
2229
return 0
2330
fi
2431

2532
if ! command -v mvn >/dev/null 2>&1; then
2633
print_error "mvn not found. Install with: mise install maven"
34+
emit_status "fail" "failed"
2735
return 1
2836
fi
2937

@@ -39,9 +47,11 @@ main() {
3947

4048
if mvn "${maven_opts[@]}" ${exclude_opt[@]+"${exclude_opt[@]}"} spotbugs:check; then
4149
print_success "SpotBugs passed"
50+
emit_status "pass" "ok"
4251
return 0
4352
else
4453
print_error "SpotBugs failed"
54+
emit_status "fail" "failed"
4555
return 1
4656
fi
4757
}

0 commit comments

Comments
 (0)