Skip to content

Commit

Permalink
ci: add a linting check for HCL files (#7791)
Browse files Browse the repository at this point in the history
Running `make dev` runs `hclfmt`, but this isn't checked as part of
CI. That makes it possible to merge un-formatted HCL and Nomad
jobspecs that later will make for dirty git staging areas when
developers pull master.

This changeset adds HCL linting to the `make check` target.
  • Loading branch information
tgross authored Apr 23, 2020
1 parent 22d4b88 commit 8af65c5
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
6 changes: 5 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ check: ## Lint the source code

@echo "==> Check proto files are in-sync..."
@$(MAKE) proto
@if (git status | grep -q .pb.go); then echo the following proto files are out of sync; git status |grep .pb.go; exit 1; fi
@if (git status -s | grep -q .pb.go); then echo the following proto files are out of sync; git status -s | grep .pb.go; exit 1; fi

@echo "==> Check format of jobspecs and HCL files..."
@$(MAKE) hclfmt
@if (git status -s | grep -q -e '\.hcl$$' -e '\.nomad$$'); then echo the following HCL files are out of sync; git status -s | grep -e '\.hcl$$' -e '\.nomad$$'; exit 1; fi

@echo "==> Check API package is isolated from rest"
@if go list --test -f '{{ join .Deps "\n" }}' ./api | grep github.com/hashicorp/nomad/ | grep -v -e /vendor/ -e /nomad/api/ -e nomad/api.test; then echo " /api package depends the ^^ above internal nomad packages. Remove such dependency"; exit 1; fi
Expand Down
3 changes: 1 addition & 2 deletions jobspec/test-fixtures/tg-scaling-policy-minimal.hcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
job "elastic" {
group "group" {
scaling {
}
scaling {}
}
}
3 changes: 1 addition & 2 deletions jobspec/test-fixtures/tg-scaling-policy-multi-policy.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ job "elastic" {

policy {
foo = "wrong"
c = false
c = false
}

}
}
}
3 changes: 2 additions & 1 deletion jobspec/test-fixtures/tg-service-connect-local-service.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ job "connect-proxy-local-service" {
group "group" {
service {
name = "example"

connect {
sidecar_service {
proxy {
Expand All @@ -14,4 +15,4 @@ job "connect-proxy-local-service" {
}
}
}
}
}
8 changes: 7 additions & 1 deletion jobspec/test-fixtures/tg-service-connect-proxy.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,39 @@ job "service-connect-proxy" {
group "group" {
service {
name = "example"

connect {
sidecar_service {
proxy {
local_service_port = 8080
local_service_address = "10.0.1.2"

upstreams {
destination_name = "upstream1"
local_bind_port = 2001
}

upstreams {
destination_name = "upstream2"
local_bind_port = 2002
}

expose {
path {
path = "/metrics"
protocol = "http"
local_path_port = 9001
listener_port = "metrics"
}

path {
path = "/health"
protocol = "http"
local_path_port = 9002
listener_port = "health"
}
}

config {
foo = "bar"
}
Expand All @@ -39,4 +45,4 @@ job "service-connect-proxy" {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ job "sidecar_task_name" {
group "group" {
service {
name = "example"

connect {
sidecar_service {}
sidecar_service = {}

sidecar_task {
name = "my-sidecar"
}
}
}
}
}
}

0 comments on commit 8af65c5

Please sign in to comment.