Repository navigation
Expand file tree
/
Copy pathstackorder-stub.sh
More file actions
executable file
·66 lines (63 loc) · 1.83 KB
/
Copy pathstackorder-stub.sh
File metadata and controls
executable file
·66 lines (63 loc) · 1.83 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
set -euo pipefail
command=$1
shift
echo "$command $*" >> "$RUNNER_TEMP/stackorder-calls.log"
flag() {
local name=$1
shift
while [ $# -gt 1 ]; do
if [ "$1" = "$name" ]; then
echo "$2"
return
fi
shift
done
echo "missing $name" >&2
exit 1
}
case "$command" in
resolve)
{
echo "run-id=00000000-0000-4000-8000-000000000001"
echo 'matrix={"include":[{"stack":"stacks/app","key":"stacks/app:blue","instance":"blue","workspace":"","environment":"blue","wave":0,"tool":"terraform","tool_version":"","plan_output":"full"}]}'
echo 'waves=[["stacks/app:blue"]]'
echo 'affected=[{"key":"stacks/app:blue","path":"stacks/app","instance":"blue","wave":0,"reasons":["changed"]}]'
echo "count=1"
echo "unconfirmed=false"
} >> "$GITHUB_OUTPUT"
;;
plan)
stack=$(flag --stack "$@")
slug="${stack//[\/:]/-}-$(printf '%s' "$stack" | sha256sum | cut -c1-8)"
artifact="stackorder-plan-$slug-$GITHUB_SHA"
mkdir -p "$STACKORDER_PLAN_DIR"
echo "plan of $stack" > "$STACKORDER_PLAN_DIR/$artifact.tfplan"
{
echo "has-changes=true"
echo "artifact=$artifact"
echo "plan-file=$STACKORDER_PLAN_DIR/$artifact.tfplan"
echo 'summary={"adds":1,"changes":0,"destroys":0,"replaces":0}'
echo "unconfirmed=false"
} >> "$GITHUB_OUTPUT"
;;
apply)
plan_file=$(flag --plan-file "$@")
grep -q "^plan of " "$plan_file"
echo 'summary={"adds":1,"changes":0,"destroys":0,"replaces":0}' >> "$GITHUB_OUTPUT"
;;
drift)
code=${STUB_DRIFT_EXIT:-2}
drifted=false
[ "$code" -ne 2 ] || drifted=true
{
echo "drifted=$drifted"
echo 'summary={"adds":0,"changes":1,"destroys":0,"replaces":0}'
} >> "$GITHUB_OUTPUT"
exit "$code"
;;
*)
echo "unexpected command: $command" >&2
exit 1
;;
esac