Skip to content

Commit 57a1e15

Browse files
committed
feat: add new hook to automatically generate kafka schemas
1 parent 779309a commit 57a1e15

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

.pre-commit-hooks.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,11 @@
3434
stages: [commit]
3535
always_run: true
3636
pass_filenames: false
37+
38+
- id: kafka-check-schemas
39+
name: Check if local Kafka Schemas are up to date with code
40+
language: script
41+
entry: ./kafka-check-local-schemas.sh
42+
stages: [commit]
43+
always_run: true
44+
pass_filenames: false

kafka-check-local-schemas.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
# Safety measures
4+
set -o errexit # Leave immediately if a command returns an error
5+
set -o nounset # Leave immediately if an unitialized value is used
6+
set -o pipefail # Leave immediately if a command fails in a pipe
7+
8+
[[ "${BASH_VERSION}" =~ ^(5|4\.[0-9]).* ]] && shopt -s inherit_errexit
9+
10+
#####################################################################
11+
# Helper functions
12+
#####################################################################
13+
14+
function error() {
15+
local msg="$1" exit_code="${2:-}"
16+
echo "ERROR: ${msg}">&2
17+
exit "${exit_code}"
18+
}
19+
20+
function check_binary_exists() {
21+
local binary="$1"
22+
command -v "${binary}" &>/dev/null || error "${binary} is required but it's not installed"
23+
}
24+
25+
#####################################################################
26+
# Main code
27+
#####################################################################
28+
29+
check_binary_exists "sbt"
30+
31+
sbt "runMain tools.generateSchemaFile schemas/schema.json"

0 commit comments

Comments
 (0)