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+ git config --global user.name ' Gardener'
46+ git config --global user.email ' gardener@cloud'
47+ if ! git rev-parse --git-dir & > /dev/null; then
48+ echo " Not a git repo, aborting"
49+ exit 1
50+ fi
51+
52+ if [[ " $( git rev-parse --abbrev-ref HEAD) " == " $check_branch " ]]; then
53+ echo " Already on check branch, aborting"
54+ exit 1
55+ fi
56+ delete-check-branch
57+
58+ if [[ " $( git status -s) " != " " ]]; then
59+ stashed=true
60+ git stash --include-untracked -q
61+ git stash apply -q & > /dev/null
62+ fi
63+
64+ checked_out=true
65+ git checkout -q -b " $check_branch "
66+ git add --all
67+ git commit -q --allow-empty -m ' checkpoint'
68+
69+ old_status=" $( git status -s) "
70+
71+ if ! out=$( rm -rf hack/tools/bin/ 2>&1 ) ; then
72+ echo " Error while cleaning hack/tools/bin/: $out "
73+ exit 1
74+ fi
75+
76+ echo " >> make generate"
77+ generated=true
78+ if ! out=$( make generate 2>&1 ) ; then
79+ echo " Error during calling make generate: $out "
80+ exit 1
81+ fi
82+ new_status=" $( git status -s) "
83+
84+ if [[ " $old_status " != " $new_status " ]]; then
85+ echo " make generate needs to be run:"
86+ echo " $new_status "
87+ exit 1
88+ fi
89+
90+ echo " >> make tidy"
91+ if ! out=$( make tidy 2>&1 ) ; then
92+ echo " Error during calling make tidy: $out "
93+ exit 1
94+ fi
95+ new_status=" $( git status -s) "
96+
97+ if [[ " $old_status " != " $new_status " ]]; then
98+ echo " make tidy needs to be run:"
99+ echo " $new_status "
100+ exit 1
101+ fi
102+ else
103+ echo " No git detected, cannot run make check-generate"
104+ fi
105+ exit 0
0 commit comments