forked from guychauliac/aws-cdk-github-actions
-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
executable file
·85 lines (70 loc) · 2.21 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
set -u
function parseInputs(){
# Required inputs
if [ "${INPUT_CDK_SUBCOMMAND}" == "" ]; then
echo "Input cdk_subcommand cannot be empty"
exit 1
fi
}
function installAwsCdk(){
echo "Install aws-cdk ${INPUT_CDK_VERSION}"
if [ "${INPUT_CDK_VERSION}" == "latest" ]; then
if [ "${INPUT_DEBUG_LOG}" == "true" ]; then
npm install -g aws-cdk
else
npm install -g aws-cdk >/dev/null 2>&1
fi
if [ "${?}" -ne 0 ]; then
echo "Failed to install aws-cdk ${INPUT_CDK_VERSION}"
else
echo "Successful install aws-cdk ${INPUT_CDK_VERSION}"
fi
else
if [ "${INPUT_DEBUG_LOG}" == "true" ]; then
npm install -g aws-cdk@${INPUT_CDK_VERSION}
else
npm install -g aws-cdk@${INPUT_CDK_VERSION} >/dev/null 2>&1
fi
if [ "${?}" -ne 0 ]; then
echo "Failed to install aws-cdk ${INPUT_CDK_VERSION}"
else
echo "Successful install aws-cdk ${INPUT_CDK_VERSION}"
fi
fi
}
function runCdk(){
echo "Run cdk ${INPUT_CDK_SUBCOMMAND} ${*} \"${INPUT_CDK_STACK}\""
set -o pipefail
cdk ${INPUT_CDK_SUBCOMMAND} ${*} "${INPUT_CDK_STACK}" 2>&1 | tee output.log
exitCode=${?}
set +o pipefail
echo ::set-output name=status_code::${exitCode}
output=$(cat output.log)
commentStatus="Failed"
if [ "${exitCode}" == "0" ]; then
commentStatus="Success"
elif [ "${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
if [ "$GITHUB_EVENT_NAME" == "pull_request" ] && [ "${INPUT_ACTIONS_COMMENT}" == "true" ]; then
commentWrapper="#### \`cdk ${INPUT_CDK_SUBCOMMAND}\` ${commentStatus}
<details><summary>Show Output</summary>
\`\`\`
${output}
\`\`\`
</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
}
function main(){
parseInputs
cd ${GITHUB_WORKSPACE}/${INPUT_WORKING_DIR}
installAwsCdk
runCdk ${INPUT_CDK_ARGS}
}
main