-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·44 lines (31 loc) · 1.44 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
#set -x
export KUBECTL_EXTERNAL_DIFF="diff -u"
# first request is to establish
info=$(argocd --grpc-web --insecure --server $INPUT_SERVER --auth-token "$INPUT_TOKEN" app get $INPUT_APP -ojson)
local_path=$(jq -r .spec.source.path <<< $info)
# TODO: latesr comment directly on the build and block it if fail
df=$(argocd --grpc-web --insecure --server $INPUT_SERVER --auth-token "$INPUT_TOKEN" app diff --local $local_path $INPUT_APP 2>&1)
export res=$?
echo "Result: $res"
export pull_number=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
if [ $res -eq 20 ]; then
echo "argocd failed $df"
curl -XPOST -H "Authorization: Bearer $INPUT_GITHUB_TOKEN" \
$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/issues/$pull_number/comments --data \
"$(jq --arg d "$df" -n '{ body: ("**ArgoCD Failure**\n```\n" + $d + "\n```") }')"
# exit with error to prevent merging
exit 1
fi
if [ $res -eq 1 ]; then
echo "presenting diff"
echo "$df"
curl -XPOST -H "Authorization: Bearer $INPUT_GITHUB_TOKEN" \
$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/issues/$pull_number/comments --data \
"$(jq --arg d "$df" -n '{ body: ("**ArgoCD Diff**\n```diff\n" + $d + "\n```") }')"
fi
if [ $res -eq 0 ]; then
curl -XPOST -H "Authorization: Bearer $INPUT_GITHUB_TOKEN" \
$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/issues/$pull_number/comments --data \
"$(jq --arg d "$df" -n '{ body: ("**ArgoCD Diff**\n```\nno changes detected!\n```") }')"
fi