forked from craftyc0der/github-action-helm3-eks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
72 lines (57 loc) · 1.99 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
#!/bin/sh
set -e
if [ -z "$INPUT_KUBECONFIG" ]; then
echo "INPUT_KUBECONFIG is not set. EKS will not be called."
else
if [ -z "$INPUT_AWS_ACCESS_KEY_ID" ]; then
echo "INPUT_AWS_ACCESS_KEY_ID is not set. Quitting."
exit 1
else
INPUT_AWS_ACCESS_KEY_ID=$(echo "${INPUT_AWS_ACCESS_KEY_ID}" | xargs)
fi
if [ -z "$INPUT_AWS_SECRET_ACCESS_KEY" ]; then
echo "INPUT_AWS_SECRET_ACCESS_KEY is not set. Quitting."
exit 1
else
INPUT_AWS_SECRET_ACCESS_KEY=$(echo "${INPUT_AWS_SECRET_ACCESS_KEY}" | xargs)
fi
# Default to us-east-1 if AWS_REGION not set.
if [ -z "$INPUT_AWS_REGION" ]; then
AWS_REGION="us-east-2"
fi
# Create a dedicated profile for this action to avoid conflicts
# with past/future actions.
aws configure --profile github_user <<-EOF > /dev/null 2>&1
${INPUT_AWS_ACCESS_KEY_ID}
${INPUT_AWS_SECRET_ACCESS_KEY}
${INPUT_AWS_REGION}
text
EOF
echo -e "\033[36mSetting up kubectl configuration\033[0m"
mkdir -p ~/.kube/
echo "${INPUT_KUBECONFIG}" > ~/.kube/config
fi
echo -e "\033[36mPreparing helm execution\033[0m"
echo "${INPUT_EXEC}" > run.sh
chmod +x ./run.sh
echo -e "\033[36mExecuting helm\033[0m"
# In case INPUT_EXEC includes git commands, the user/group info may mismatch
# between container and host, and it may cause git to complain with:
# `detected dubious ownership in repository`.
# Therefore mark everything as safe here as we don't know where the repository is,
# (although it is likely /github/workspace)
# For more info: https://github.com/actions/runner-images/issues/6775
git config --global --add safe.directory '*'
helm_output=$(./run.sh)
echo "$helm_output"
mkdir -p _temp
printf "# Helm Results\n\n\`\`\`bash\n$helm_output\n\`\`\`" > ./_temp/helm_output
helm_output="${helm_output//'%'/'%25'}"
helm_output="${helm_output//$'\n'/'%0A'}"
helm_output="${helm_output//$'\r'/'%0D'}"
echo "helm_output=$helm_output" >> $GITHUB_OUTPUT
echo -e "\033[36mCleaning up: \033[0m"
rm ./run.sh -Rf
echo -e "\033[36m - exec ✅ \033[0m"
rm ~/.kube/config -Rf
echo -e "\033[36m - kubeconfig ✅ \033[0m"