Skip to content

Commit 33b5bf5

Browse files
committed
Adds first version of Scripts/release-management-prechecks.sh
1 parent 2de96c1 commit 33b5bf5

File tree

1 file changed

+140
-0
lines changed

1 file changed

+140
-0
lines changed
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#!/bin/bash
2+
3+
# ---------------------------------------------------------------------------------
4+
# 0a. Configuration
5+
# ---------------------------------------------------------------------------------
6+
7+
PROJECT_ROOT="."
8+
PROJECT_ENV_FILE="$HOME/.wcios-env.default"
9+
10+
P_ENV_GITHUB_TOKEN="GITHUB_TOKEN"
11+
P_ENV_SENTRY_AUTH_TOKEN="SENTRY_AUTH_TOKEN"
12+
P_ENV_SENTRY_ORG_SLUG="SENTRY_ORG_SLUG"
13+
P_ENV_SENTRY_PROJECT_SLUG="SENTRY_PROJECT_SLUG"
14+
P_ENV_BUILDKITE_TOKEN="BUILDKITE_TOKEN"
15+
P_ENV_FASTLANE_ITC_TEAM_ID="FASTLANE_ITC_TEAM_ID"
16+
17+
# TODO: Can we drop these values from the 'PROJECT_ENV_FILE' and add it to the repo?
18+
# We can simplify and improve this script if we can do that.
19+
P_ENV_SENTRY_ORG_SLUG_VALUE="a8c"
20+
P_ENV_SENTRY_PROJECT_SLUG_VALUE="woocommerce-ios"
21+
P_ENV_FASTLANE_ITC_TEAM_ID_VALUE="299112"
22+
23+
# ---------------------------------------------------------------------------------
24+
# 0b. Warning & Error Messages
25+
# ---------------------------------------------------------------------------------
26+
echoerr() { printf "\e[31;1m%s\e[0m\n" "$*" >&2; }
27+
error_incorrect_ruby_version() {
28+
echoerr \
29+
"Your local ruby version does not match the required ruby version.
30+
Please make sure \`ruby --version\` returns the same version as the version in \`.ruby-version\` file.
31+
We suggest using rbenv for managing your Ruby environment: https://github.com/rbenv/rbenv"
32+
}
33+
34+
error_project_env_file_missing() {
35+
echoerr "$PROJECT_ENV_FILE is missing!"
36+
}
37+
error_project_env_field_missing() {
38+
echoerr "'$1' is missing or incorrect in $PROJECT_ENV_FILE!"
39+
}
40+
warning_project_env_file_contents() {
41+
echo \
42+
"
43+
Please make sure you have the following information in '$PROJECT_ENV_FILE':
44+
45+
> $P_ENV_GITHUB_TOKEN={$P_ENV_GITHUB_TOKEN}
46+
>
47+
> $P_ENV_FASTLANE_ITC_TEAM_ID=$P_ENV_FASTLANE_ITC_TEAM_ID_VALUE
48+
>
49+
> $P_ENV_SENTRY_AUTH_TOKEN={$P_ENV_SENTRY_AUTH_TOKEN}
50+
> $P_ENV_SENTRY_ORG_SLUG=$P_ENV_SENTRY_ORG_SLUG_VALUE
51+
> $P_ENV_SENTRY_PROJECT_SLUG=$P_ENV_SENTRY_PROJECT_SLUG_VALUE
52+
>
53+
> $P_ENV_BUILDKITE_TOKEN={$P_ENV_BUILDKITE_TOKEN}
54+
55+
Here is how to retrieve these values:
56+
57+
$P_ENV_GITHUB_TOKEN: https://github.com/settings/tokens (requires 'repo')
58+
$P_ENV_SENTRY_AUTH_TOKEN: https://sentry.io/settings/account/api/auth-tokens/ (requires 'event:read, member:read, org:read, project:read, project:releases, team:read, event:admin')
59+
$P_ENV_BUILDKITE_TOKEN: https://buildkite.com/user/api-access-tokens (requires 'read_builds, write_builds')
60+
"
61+
}
62+
63+
# ---------------------------------------------------------------------------------
64+
# 0c. Helpers
65+
# ---------------------------------------------------------------------------------
66+
67+
HAS_WARNINGS=false
68+
LOG_SEPERATOR="
69+
------------------------------------------------------------------------
70+
"
71+
72+
# ---------------------------------------------------------------------------------
73+
# 1. Checking Ruby Version
74+
# ---------------------------------------------------------------------------------
75+
76+
PROJECT_RUBY_VERSION=$(cat $PROJECT_ROOT/.ruby-version)
77+
LOCAL_RUBY_VERSION=$(ruby -e 'puts RUBY_VERSION')
78+
79+
if [ "$LOCAL_RUBY_VERSION" != "$PROJECT_RUBY_VERSION" ]; then
80+
echo "Local Ruby Version: $LOCAL_RUBY_VERSION"
81+
echo "Project Ruby Version: $PROJECT_RUBY_VERSION"
82+
error_incorrect_ruby_version
83+
echo "$LOG_SEPERATOR"
84+
85+
HAS_WARNINGS=true
86+
fi
87+
88+
# ---------------------------------------------------------------------------------
89+
# 2. Checking Environment File
90+
# ---------------------------------------------------------------------------------
91+
92+
HAS_PROJECT_ENV_FILE_WARNINGS=false
93+
94+
if [ ! -f "$PROJECT_ENV_FILE" ]; then
95+
error_project_env_file_missing
96+
HAS_PROJECT_ENV_FILE_WARNINGS=true
97+
else
98+
check_project_env() {
99+
local arg_token=$1
100+
local arg_expected_value=$2
101+
102+
# '^' matches the start of line so that if a value is commented out, it'll result in error
103+
local regex="^$arg_token=$arg_expected_value"
104+
105+
if ! grep -oq "$regex" "$PROJECT_ENV_FILE"; then
106+
error_project_env_field_missing "$arg_token"
107+
HAS_PROJECT_ENV_FILE_WARNINGS=true
108+
fi
109+
}
110+
111+
match_any_word="\w*"
112+
113+
# These tokens can match to any string
114+
check_project_env "$P_ENV_GITHUB_TOKEN" "$match_any_word"
115+
check_project_env "$P_ENV_SENTRY_AUTH_TOKEN" "$match_any_word"
116+
check_project_env "$P_ENV_BUILDKITE_TOKEN" "$match_any_word"
117+
118+
# These values are set per project in configuration section and the value is not a secret
119+
check_project_env "$P_ENV_SENTRY_ORG_SLUG" "$P_ENV_SENTRY_ORG_SLUG_VALUE"
120+
check_project_env "$P_ENV_SENTRY_PROJECT_SLUG" "$P_ENV_SENTRY_PROJECT_SLUG_VALUE"
121+
check_project_env "$P_ENV_FASTLANE_ITC_TEAM_ID" "$P_ENV_FASTLANE_ITC_TEAM_ID_VALUE"
122+
fi
123+
124+
if [ "$HAS_PROJECT_ENV_FILE_WARNINGS" == true ]; then
125+
warning_project_env_file_contents
126+
echo "$LOG_SEPERATOR"
127+
128+
HAS_WARNINGS=true
129+
fi
130+
131+
# ---------------------------------------------------------------------------------
132+
# 3. Wrapping Up
133+
# ---------------------------------------------------------------------------------
134+
135+
if [ "$HAS_WARNINGS" == true ]; then
136+
echo "Please address the warnings and re-run this check before continuing with the release.
137+
If you need help, please contact @owl-team in #platform9 Slack channel."
138+
else
139+
echo "Everything looks good, good luck with the release!"
140+
fi

0 commit comments

Comments
 (0)