1+ #! /usr/bin/env bash
2+ #
3+ # SPDX-FileCopyrightText: SAP SE or an SAP affiliate company and Gardener contributors
4+ #
5+ # SPDX-License-Identifier: Apache-2.0
6+
7+ set -e
8+
9+ echo " > Generate"
10+
11+ check_branch=" __check"
12+ stashed=false
13+ checked_out=false
14+ generated=false
15+
16+ function delete-check-branch {
17+ git rev-parse --verify " $check_branch " & > /dev/null && git branch -q -D " $check_branch " || :
18+ }
19+
20+ function cleanup {
21+ if [[ " $generated " == true ]]; then
22+ if ! clean_err=" $( make clean && git reset --hard -q && git clean -qdf) " ; then
23+ echo " Could not clean: $clean_err "
24+ fi
25+ fi
26+
27+ if [[ " $checked_out " == true ]]; then
28+ if ! checkout_err=" $( git checkout -q -) " ; then
29+ echo " Could not checkout to previous branch: $checkout_err "
30+ fi
31+ fi
32+
33+ if [[ " $stashed " == true ]]; then
34+ if ! stash_err=" $( git stash pop -q) " ; then
35+ echo " Could not pop stash: $stash_err "
36+ fi
37+ fi
38+
39+ delete-check-branch
40+ }
41+
42+ trap cleanup EXIT SIGINT SIGTERM
43+
44+ if which git & > /dev/null; then
45+ if ! git rev-parse --git-dir & > /dev/null; then
46+ echo " Not a git repo, aborting"
47+ exit 1
48+ fi
49+
50+ if [[ " $( git rev-parse --abbrev-ref HEAD) " == " $check_branch " ]]; then
51+ echo " Already on check branch, aborting"
52+ exit 1
53+ fi
54+ delete-check-branch
55+
56+ if [[ " $( git status -s) " != " " ]]; then
57+ stashed=true
58+ git stash --include-untracked -q
59+ git stash apply -q & > /dev/null
60+ fi
61+
62+ checked_out=true
63+ git checkout -q -b " $check_branch "
64+ git add --all
65+ git commit -q --allow-empty -m ' checkpoint'
66+
67+ old_status=" $( git status -s) "
68+
69+ if ! out=$( rm -rf hack/tools/bin/ 2>&1 ) ; then
70+ echo " Error while cleaning hack/tools/bin/: $out "
71+ exit 1
72+ fi
73+
74+ echo " >> make generate"
75+ generated=true
76+ if ! out=$( make generate 2>&1 ) ; then
77+ echo " Error during calling make generate: $out "
78+ exit 1
79+ fi
80+ new_status=" $( git status -s) "
81+
82+ if [[ " $old_status " != " $new_status " ]]; then
83+ echo " make generate needs to be run:"
84+ echo " $new_status "
85+ exit 1
86+ fi
87+
88+ echo " >> make tidy"
89+ if ! out=$( make tidy 2>&1 ) ; then
90+ echo " Error during calling make tidy: $out "
91+ exit 1
92+ fi
93+ new_status=" $( git status -s) "
94+
95+ if [[ " $old_status " != " $new_status " ]]; then
96+ echo " make tidy needs to be run:"
97+ echo " $new_status "
98+ exit 1
99+ fi
100+ else
101+ echo " No git detected, cannot run make check-generate"
102+ fi
103+ exit 0
0 commit comments