Skip to content

Commit

Permalink
Merge pull request #3 from rtCamp/add/env-var-check
Browse files Browse the repository at this point in the history
Add missing secret error handling
  • Loading branch information
mrrobot47 authored Jan 27, 2020
2 parents 2472d9a + 7d613b2 commit 6851251
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
#!/usr/bin/env bash

# Check required env variables
flag=0
if [[ -z "$SLACK_WEBHOOK" ]]; then
flag=1
missing_secret="SLACK_WEBHOOK"
if [[ -n "$VAULT_ADDR" ]] && [[ -n "$VAULT_TOKEN" ]]; then
flag=0
fi
if [[ -n "$VAULT_ADDR" ]] || [[ -n "$VAULT_TOKEN" ]]; then
missing_secret="VAULT_ADDR and/or VAULT_TOKEN"
fi
fi

if [[ "$flag" -eq 1 ]]; then
printf "[\e[0;31mERROR\e[0m] Secret \`$missing_secret\` is missing. Please add it to this action for proper execution.\nRefer https://github.com/rtCamp/action-slack-notify for more information.\n"
exit 1
fi

# custom path for files to override default files
custom_path="$GITHUB_WORKSPACE/.github/slack"
main_script="/main.sh"
Expand All @@ -9,4 +27,4 @@ if [[ -d "$custom_path" ]]; then
chmod +x /*.sh
fi

bash "$main_script"
bash "$main_script"

0 comments on commit 6851251

Please sign in to comment.