Skip to content

Commit 657eb63

Browse files
api-clients-generation-pipeline[bot]skarimoci.datadog-api-spec
authored
Exit early when generation fails (#831)
* 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]>
1 parent 6e95b74 commit 657eb63

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.6.4",
7-
"regenerated": "2022-09-06 20:46:59.630821",
8-
"spec_repo_commit": "36a61042"
7+
"regenerated": "2022-09-07 19:30:40.870279",
8+
"spec_repo_commit": "33b7a42c"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.4",
12-
"regenerated": "2022-09-06 20:46:59.643602",
13-
"spec_repo_commit": "36a61042"
12+
"regenerated": "2022-09-07 19:30:40.887104",
13+
"spec_repo_commit": "33b7a42c"
1414
}
1515
}
1616
}

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repos:
44
- id: generate
55
name: Generate
66
language: node
7-
entry: make
7+
entry: bash -c "./generate.sh"
88
files: '^(\.generator/.*|\.pre-commit-config\.yaml|package\.json|yarn\.lock|\.eslintrc\.js|Makefile|\features/.*)'
99
pass_filenames: false
1010
- id: lint

Makefile

Lines changed: 0 additions & 8 deletions
This file was deleted.

generate.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
DEFAULT_ERROR_CODES="0"
4+
5+
# First arg is the command
6+
# Second arg is the string of acceptable error codes seperated by space. E.g. "0 1"
7+
pre_commit_wrapper () {
8+
echo "running pre-commit run --all-files --hook-stage=manual ${1}"
9+
10+
exec 5>&1
11+
acceptable_errors=${2:-$DEFAULT_ERROR_CODES}
12+
out=$(pre-commit run --all-files --hook-stage=manual "${1}" | tee >(cat - >&5))
13+
exit_code=$( echo "$out" | grep -- "- exit code:" | cut -d":" -f2 | sed 's/[^0-9]*//g' )
14+
15+
if [[ -n $exit_code ]]; then
16+
re="([^0-9]|^)$exit_code([^0-9]|$)"
17+
if ! grep -qE "$re" <<< "$acceptable_errors" ; then
18+
echo "pre-commit subcommand failed with error_code: $exit_code. See output above"
19+
exit "$exit_code";
20+
fi
21+
fi
22+
23+
echo "command 'pre-commit run --all-files --hook-stage=manual ${1}' success"
24+
}
25+
26+
rm -rf packages/datadog-api-client-v*/ examples/v*
27+
rm -rf packages/datadog-api-client-*/
28+
pre_commit_wrapper generator
29+
pre_commit_wrapper lint
30+
pre_commit_wrapper examples
31+
pre_commit_wrapper lint-examples

0 commit comments

Comments
 (0)