Skip to content

Commit 408a575

Browse files
authored
Merge pull request #7131 from woocommerce/script/release-management-prechecks
Adds release management prechecks script
2 parents 2de96c1 + adf0ad2 commit 408a575

File tree

1 file changed

+135
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)