Skip to content

Commit 5d099d1

Browse files
authored
Merge pull request #1882 from cfengine/formatting-action-1756887993
Reformatted shell scripts
2 parents 5bde13b + 446377e commit 5d099d1

34 files changed

+1532
-1646
lines changed

build-scripts/autogen

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,42 +24,40 @@
2424
# Parse the required argument which should be set through the environment
2525
# variable PROJECT
2626
case "$PROJECT" in
27-
community)
27+
community)
2828
NOVA=no
2929
;;
30-
nova)
30+
nova)
3131
NOVA=yes
3232
;;
33-
*)
33+
*)
3434
if [ -z "${PROJECT}" ]; then
3535
echo "$(basename "$0"): Error: Expected environment variable PROJECT=[community|nova]"
3636
else
3737
echo "$(basename "$0"): Error: Unknown project '$PROJECT', expected 'community' or 'nova'"
3838
fi
3939
echo "Usage: PROJECT=[community|nova] $0"
40-
exit 42;;
40+
exit 42
41+
;;
4142
esac
4243

4344
# Determine which repositories should be included
4445
projects="core masterfiles"
45-
if test "$NOVA" = "yes"
46-
then
46+
if test "$NOVA" = "yes"; then
4747
projects="$projects enterprise nova"
4848
fi
4949

5050
# Fail early by checking that the required repositories are present before
5151
# running the autogen.sh.
52-
for proj in $projects
53-
do
52+
for proj in $projects; do
5453
if [ ! -d "$BASEDIR/$proj" ]; then
5554
echo "$(basename "$0"): Error: Expected to find the '$proj' repository in '$BASEDIR', but it's not there"
5655
exit 1
5756
fi
5857
done
5958

6059
# Run autogen.sh on each repository
61-
for proj in $projects
62-
do
60+
for proj in $projects; do
6361
# autogen.sh is quite verbose, so only print the output in case of failure
6462
echo "$(basename "$0"): Debug: Running autogen.sh for project $proj..."
6563
(

build-scripts/bin/get-github-pull-request-info

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,42 @@
1313
# $PR_STATUSES_URL - GH API URL to set PR's statuses
1414
# Returns:
1515
# 0 - success, 1 - error
16-
if [ -z "$1" ]; then echo "First argument, project, is required"; exit 1; fi
17-
if [ -z "$2" ]; then echo "Second argument, pull request number, is required"; exit 1; fi
16+
if [ -z "$1" ]; then
17+
echo "First argument, project, is required"
18+
exit 1
19+
fi
20+
if [ -z "$2" ]; then
21+
echo "Second argument, pull request number, is required"
22+
exit 1
23+
fi
1824

1925
json_out="$(mktemp)"
2026

2127
# curl 7.88 ish supports --header @file but apparently 7.52 (on bootstrap vm (deb-9)) does not, so compose a script
2228
curl_script_file="$(mktemp)"
2329
chmod 600 "$curl_script_file"
24-
echo -n "curl --insecure --fail --header \"Authorization: Bearer " > "$curl_script_file"
30+
echo -n "curl --insecure --fail --header \"Authorization: Bearer " >"$curl_script_file"
2531

2632
_dir=$(readlink -e "$(dirname "$0")")
27-
"$_dir"/get-pr-token "$1" >> "$curl_script_file"
28-
echo "\" https://api.github.com/repos/$1/pulls/$2" >> "$curl_script_file"
33+
"$_dir"/get-pr-token "$1" >>"$curl_script_file"
34+
echo "\" https://api.github.com/repos/$1/pulls/$2" >>"$curl_script_file"
2935

3036
if ( # sub-shell to preserve original shell -/+x -/+e state
31-
set +x # hide curl command below as it contains a secret! don't remove me!
32-
# uncomment the below to debug, warning: will reveal secrets in logs
33-
# cat "$curl_script_file" >&2
34-
bash "$curl_script_file" >"$json_out"
37+
set +x # hide curl command below as it contains a secret! don't remove me!
38+
# uncomment the below to debug, warning: will reveal secrets in logs
39+
# cat "$curl_script_file" >&2
40+
bash "$curl_script_file" >"$json_out"
3541
); then
36-
if command -v jq > /dev/null; then
37-
URL=$(jq ".statuses_url" < "$json_out" | tr -d '"')
38-
status=$?
39-
else
40-
URL=$(grep "statuses_url" "$json_out" | head -n1 | sed -r 's/\s+"statuses_url": "([^"]+)",/\1/')
41-
status=$?
42-
fi
42+
if command -v jq >/dev/null; then
43+
URL=$(jq ".statuses_url" <"$json_out" | tr -d '"')
44+
status=$?
45+
else
46+
URL=$(grep "statuses_url" "$json_out" | head -n1 | sed -r 's/\s+"statuses_url": "([^"]+)",/\1/')
47+
status=$?
48+
fi
4349
else
44-
echo "Request failed. Response was $(cat "$json_out")" >&2
45-
status=1
50+
echo "Request failed. Response was $(cat "$json_out")" >&2
51+
status=1
4652
fi
4753

4854
# uncomment the below deletion of files for debugging

build-scripts/bin/get-pr-token

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,38 @@
88
# $CFENGINE_PR_TOKEN_PATH - file path containing token associated with CFEngine github organization
99
# $NTHQ_PR_TOKEN_PATH - file path containing token associated with NorthernTechHQ github organization
1010
( # hide commands as they may contain secrets or paths to secrets
11-
set +x
12-
if [ -z "$1" ]; then echo "Need repository identifier as first argument"; exit 1; fi
13-
if [ -z "$CFENGINE_PR_TOKEN_PATH" ]; then echo "Env var CFENGINE_PR_TOKEN_PATH is required"; exit 1; fi
14-
if [ ! -f "$CFENGINE_PR_TOKEN_PATH" ]; then echo "CFENGINE_PR_TOKEN_PATH file must exist"; exit 1; fi
15-
if [ -z "$NTHQ_PR_TOKEN_PATH" ]; then echo "Env var NTHQ_PR_TOKEN_PATH is required"; exit 1; fi
16-
if [ ! -f "$NTHQ_PR_TOKEN_PATH" ]; then echo "NTHQ_PR_TOKEN_PATH file must exist"; exit 1; fi
11+
set +x
12+
if [ -z "$1" ]; then
13+
echo "Need repository identifier as first argument"
14+
exit 1
15+
fi
16+
if [ -z "$CFENGINE_PR_TOKEN_PATH" ]; then
17+
echo "Env var CFENGINE_PR_TOKEN_PATH is required"
18+
exit 1
19+
fi
20+
if [ ! -f "$CFENGINE_PR_TOKEN_PATH" ]; then
21+
echo "CFENGINE_PR_TOKEN_PATH file must exist"
22+
exit 1
23+
fi
24+
if [ -z "$NTHQ_PR_TOKEN_PATH" ]; then
25+
echo "Env var NTHQ_PR_TOKEN_PATH is required"
26+
exit 1
27+
fi
28+
if [ ! -f "$NTHQ_PR_TOKEN_PATH" ]; then
29+
echo "NTHQ_PR_TOKEN_PATH file must exist"
30+
exit 1
31+
fi
1732
)
1833
# debug the following sha256sum commands to help determine if the tokens are correct in jenkins builds
1934
#echo "sha256sum of CFENGINE_PR_TOKEN_PATH..." >&2
2035
#sha256sum "$CFENGINE_PR_TOKEN_PATH" >&2
2136
#echo "sha256sum of NTHQ_PR_TOKEN_PATH..." >&2
2237
#sha256sum "$NTHQ_PR_TOKEN_PATH" >&2
2338
if [ "${1%/*}" = "cfengine" ]; then
24-
tr -d '\n' < "$CFENGINE_PR_TOKEN_PATH"
39+
tr -d '\n' <"$CFENGINE_PR_TOKEN_PATH"
2540
elif [ "${1%/*}" = "NorthernTechHQ" ]; then
26-
tr -d '\n' < "$NTHQ_PR_TOKEN_PATH"
41+
tr -d '\n' <"$NTHQ_PR_TOKEN_PATH"
2742
else
28-
echo "$0 doesn't know about tokens for organization ${1%/*}"
29-
exit 1
43+
echo "$0 doesn't know about tokens for organization ${1%/*}"
44+
exit 1
3045
fi

build-scripts/bin/set-github-status

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,55 +42,55 @@ else
4242
fi
4343

4444
function set_status() {
45-
set -ex
45+
set -ex
4646
# Actually set status at GitHub
4747
# Args:
4848
# $1 - repo identifier (organization/project)
4949
# $2 - statuses API URL of the PR
5050
# Env:
5151

5252
if [ -z "$1" ]; then
53-
echo "Missing repo identifier (organization/project) as first argument"
54-
exit 1
53+
echo "Missing repo identifier (organization/project) as first argument"
54+
exit 1
5555
fi
5656
if [ -z "$2" ]; then
57-
echo "Missing pull request API URL as second argument"
58-
exit 1
57+
echo "Missing pull request API URL as second argument"
58+
exit 1
5959
fi
6060

6161
# curl 7.88 ish supports --header @file but apparently 7.52 (on bootstrap vm (deb-9)) does not, so compose a script
6262
curl_script_file="$(mktemp)"
6363
chmod 600 "$curl_script_file"
64-
echo -n "curl --fail --insecure -X POST --header \"Authorization: Bearer " > "$curl_script_file"
64+
echo -n "curl --fail --insecure -X POST --header \"Authorization: Bearer " >"$curl_script_file"
6565
_dir=$(readlink -e "$(dirname "$0")")
66-
"$_dir"/get-pr-token "$1" >> "$curl_script_file"
67-
echo -n "\" $2 --data " >> "$curl_script_file"
66+
"$_dir"/get-pr-token "$1" >>"$curl_script_file"
67+
echo -n "\" $2 --data " >>"$curl_script_file"
6868

6969
if [ -n "$JSON_file" ]; then
7070
(
71-
set +x # hide secrets
72-
echo "@$JSON_file" >> "$curl_script_file"
71+
set +x # hide secrets
72+
echo "@$JSON_file" >>"$curl_script_file"
7373
)
7474
else
7575
(
76-
set +x # hide secrets
77-
echo -n "@- <<EOF" >> "$curl_script_file"
78-
echo -n "
76+
set +x # hide secrets
77+
echo -n "@- <<EOF" >>"$curl_script_file"
78+
echo -n "
7979
{
8080
\"state\" : \"$state\",
8181
\"target_url\" : \"$job_url\",
8282
\"description\" : \"$description\",
8383
\"context\" : \"$job_spec\"
8484
}
85-
EOF" >> "$curl_script_file"
85+
EOF" >>"$curl_script_file"
8686
)
8787
fi
8888

89-
# uncomment the below cat to see the curl_script_file location
90-
# cat "$curl_script_file" >&2
89+
# uncomment the below cat to see the curl_script_file location
90+
# cat "$curl_script_file" >&2
9191
bash "$curl_script_file"
9292

93-
# uncomment the below file deletion to debug curl_script_file
93+
# uncomment the below file deletion to debug curl_script_file
9494
rm "$curl_script_file"
9595
return $?
9696
}
@@ -101,4 +101,4 @@ while read -r line; do
101101
REPO_IDENTIFIER=$(echo "$line" | awk '{ print $1 };')
102102
STATUS_URL=$(echo "$line" | awk '{ print $3 };')
103103
set_status "$REPO_IDENTIFIER" "$STATUS_URL"
104-
done < "$PRs_file"
104+
done <"$PRs_file"

0 commit comments

Comments
 (0)