Skip to content

Commit

Permalink
Exit early when generation fails (#1066)
Browse files Browse the repository at this point in the history
* introduce pre-commit wrapper

* remove echo

* Regenerate client from commit 33b7a42c of spec repo

Co-authored-by: Sherzod Karimov <[email protected]>
Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com>
Co-authored-by: ci.datadog-api-spec <[email protected]>
  • Loading branch information
3 people authored Sep 8, 2022
1 parent 2cbf49b commit fab745f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.4",
"regenerated": "2022-09-06 20:47:04.321402",
"spec_repo_commit": "36a61042"
"regenerated": "2022-09-07 19:30:26.137328",
"spec_repo_commit": "33b7a42c"
},
"v2": {
"apigentools_version": "1.6.4",
"regenerated": "2022-09-06 20:47:04.337709",
"spec_repo_commit": "36a61042"
"regenerated": "2022-09-07 19:30:26.150016",
"spec_repo_commit": "33b7a42c"
}
}
}
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repos:
- id: generate
name: Generate
language: system
entry: make
entry: bash -c "./generate.sh"
files: '^(\.generator/.*|\.pre-commit-config\.yaml|Makefile|\features/.*)'
pass_filenames: false
- id: format-examples
Expand Down
7 changes: 0 additions & 7 deletions Makefile

This file was deleted.

30 changes: 30 additions & 0 deletions generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

DEFAULT_ERROR_CODES="0"

# First arg is the command
# Second arg is the string of acceptable error codes seperated by space. E.g. "0 1"
pre_commit_wrapper () {
echo "running pre-commit run --all-files --hook-stage=manual ${1}"

exec 5>&1
acceptable_errors=${2:-$DEFAULT_ERROR_CODES}
out=$(pre-commit run --all-files --hook-stage=manual "${1}" | tee >(cat - >&5))
exit_code=$( echo "$out" | grep -- "- exit code:" | cut -d":" -f2 | sed 's/[^0-9]*//g' )

if [[ -n $exit_code ]]; then
re="([^0-9]|^)$exit_code([^0-9]|$)"
if ! grep -qE "$re" <<< "$acceptable_errors" ; then
echo "pre-commit subcommand failed with error_code: $exit_code. See output above"
exit "$exit_code";
fi
fi

echo "command 'pre-commit run --all-files --hook-stage=manual ${1}' success"
}

rm -rf ./lib/datadog_api_client/v1 ./lib/datadog_api_client/v2 examples/*
pre_commit_wrapper generator
pre_commit_wrapper examples
pre_commit_wrapper format-examples 3
pre_commit_wrapper docs

0 comments on commit fab745f

Please sign in to comment.