-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·60 lines (48 loc) · 1.91 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
set -u
# Change working directory
cd ${GITHUB_WORKSPACE}/${INPUT_WORKING_DIR}
OUTPUT_FILE="output.json"
# output the CDK version
echo "cdk version: $(cdk --version)"
# Run cdk command
echo "Run cdk ${INPUT_CDK_SUBCOMMAND} --outputs-file ${OUTPUT_FILE} ${INPUT_CDK_ARGS} \"${INPUT_CDK_STACK}\""
output=$(cdk ${INPUT_CDK_SUBCOMMAND} --outputs-file ${OUTPUT_FILE} ${INPUT_CDK_ARGS} "${INPUT_CDK_STACK}" 2>&1)
exitCode=${?}
echo "status_code=${exitCode}" >> $GITHUB_OUTPUT
echo "${output}"
# If output file exists set outputs
if test -f "${OUTPUT_FILE}"; then
echo "json=$(jq -r -c . ${OUTPUT_FILE})" >> $GITHUB_OUTPUT
cdk_output=$(jq '[leaf_paths as $path | { "key": $path | join("-"), "value": getpath($path) } ] | from_entries' ${OUTPUT_FILE})
for key in $(echo $cdk_output | jq -r 'keys[]');
do
value=$(echo $cdk_output | jq -r --arg ARG "$key" '.[$ARG]')
echo "${key}=${value}" >> $GITHUB_OUTPUT
done
fi
# Check status
if [ "${exitCode}" == "0" ]; then
commentStatus="Success"
elif [ "${exitCode}" != "0" ]; then
commentStatus="Failed"
fi
# Update PR with comment
if [ "$GITHUB_EVENT_NAME" == "pull_request" ] && [ "${INPUT_ACTIONS_COMMENT}" == "true" ]; then
commentWrapper="#### \`cdk ${INPUT_CDK_SUBCOMMAND}\` ${commentStatus}
<details>
<summary>Show Output</summary>
<pre>
${output}
</pre>
</details>
*Workflow: \`${GITHUB_WORKFLOW}\`, Action: \`${GITHUB_ACTION}\`, Working Directory: \`${INPUT_WORKING_DIR}\`*"
payload=$(echo "${commentWrapper}" | jq -R --slurp '{body: .}')
commentsURL=$(cat ${GITHUB_EVENT_PATH} | jq -r .pull_request.comments_url)
echo "${payload}" | curl -s -S -H "Authorization: token ${GITHUB_TOKEN}" --header "Content-Type: application/json" --data @- "${commentsURL}" > /dev/null
fi
# Exit with failure message
if [ "${exitCode}" != "0" ]; then
echo "CDK subcommand ${INPUT_CDK_SUBCOMMAND} for stack ${INPUT_CDK_STACK} has failed. See above console output for more details."
exit 1
fi