forked from youyo/aws-cdk-github-actions
-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
executable file
·106 lines (88 loc) · 2.63 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
set -u
function parseInputs(){
# Required inputs
if [ "${INPUT_CDK_SUBCOMMAND}" == "" ]; then
echo "Input cdk_subcommand cannot be empty"
exit 1
fi
}
function installTypescript(){
npm install typescript
}
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 installPipRequirements(){
if [ -e "requirements.txt" ]; then
echo "Install requirements.txt"
if [ "${INPUT_DEBUG_LOG}" == "true" ]; then
pip install -r requirements.txt
else
pip install -r requirements.txt >/dev/null 2>&1
fi
if [ "${?}" -ne 0 ]; then
echo "Failed to install requirements.txt"
else
echo "Successful install requirements.txt"
fi
fi
}
function runCdk(){
echo "Run cdk ${INPUT_CDK_SUBCOMMAND} ${*} \"${INPUT_CDK_STACK}\""
output=$(cdk ${INPUT_CDK_SUBCOMMAND} ${*} "${INPUT_CDK_STACK}" 2>&1)
exitCode=${?}
echo ::set-output name=status_code::${exitCode}
echo "${output}"
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}
installTypescript
installAwsCdk
installPipRequirements
runCdk ${INPUT_CDK_ARGS}
}
main