Skip to content

Commit e3bd534

Browse files
authored
chore: add checking package file count comparison in release script (appium#547)
* chore: Add file count in release script * use f string for Python 3 :P * handle exit in method
1 parent b41771b commit e3bd534

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

release.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ if [ -z "$PYTHON_BIN_PATH" ]; then
77
PYTHON_BIN_PATH=$(which python3 || which python || true)
88
fi
99

10+
export PYTHON_BIN_PATH
11+
1012
CONFIGURE_DIR=$(dirname "$0")
1113
"$PYTHON_BIN_PATH" "${CONFIGURE_DIR}/script/release.py" "$@"
1214

script/release.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,20 @@
1313
# limitations under the License.
1414
"""Release script to publish release module to pipy."""
1515

16+
import glob
1617
import io
1718
import os
19+
import shutil
20+
import subprocess
1821
import sys
22+
from typing import List
1923

2024
VERSION_FILE_PATH = os.path.join(os.path.dirname('__file__'), 'appium', 'version.py')
2125
CHANGELOG_PATH = os.path.join(os.path.dirname('__file__'), 'CHANGELOG.rst')
2226

27+
APPIUM_DIR_PATH = os.path.join(os.path.dirname('__file__'), 'appium')
28+
BUILT_APPIUM_DIR_PATH = os.path.join(os.path.dirname('__file__'), 'build', 'lib', 'appium')
29+
2330
MESSAGE_RED = '\033[1;31m{}\033[0m'
2431
MESSAGE_GREEN = '\033[1;32m{}\033[0m'
2532
MESSAGE_YELLOW = '\033[1;33m{}\033[0m'
@@ -101,6 +108,41 @@ def validate_release_env():
101108
exit("Please get twine via 'pip install gitchangelog' or 'pip install git+git://github.com/vaab/gitchangelog.git' for Python 3.7")
102109

103110

111+
def build() -> None:
112+
shutil.rmtree(BUILT_APPIUM_DIR_PATH, ignore_errors=True)
113+
status, output = subprocess.getstatusoutput('{} setup.py install'.format(os.getenv('PYTHON_BIN_PATH')))
114+
if status != 0:
115+
exit(f'Failed to build the package:\n{output}')
116+
117+
118+
def get_py_files_in_dir(root_dir: str) -> List[str]:
119+
return [
120+
file_path[len(root_dir):]
121+
for file_path in glob.glob(f"{root_dir}/**/*.py", recursive=True) + glob.glob(f"{root_dir}/**/*.typed", recursive=True)
122+
]
123+
124+
125+
def assert_files_count_in_package() -> None:
126+
original_files = get_py_files_in_dir(APPIUM_DIR_PATH)
127+
built_files = get_py_files_in_dir(BUILT_APPIUM_DIR_PATH)
128+
129+
if len(original_files) != len(built_files):
130+
print(f"The count of files in '{APPIUM_DIR_PATH}' and '{BUILT_APPIUM_DIR_PATH}' were different.")
131+
132+
original_files_set = set(original_files)
133+
built_files_set = set(built_files)
134+
135+
diff = original_files_set.difference(built_files_set)
136+
if diff:
137+
print(f"'{APPIUM_DIR_PATH}' has '{diff}' files than {BUILT_APPIUM_DIR_PATH}")
138+
diff = built_files_set.difference(original_files_set)
139+
if diff:
140+
print(f"{BUILT_APPIUM_DIR_PATH} has {diff} files than {APPIUM_DIR_PATH}")
141+
142+
exit(f"Python files in '{BUILT_APPIUM_DIR_PATH}' may differ from '{APPIUM_DIR_PATH}'. "
143+
"Please make sure setup.py is configured properly.")
144+
145+
104146
def main():
105147
validate_release_env()
106148

@@ -109,6 +151,9 @@ def main():
109151

110152
update_version_file(new_version)
111153

154+
build()
155+
assert_files_count_in_package()
156+
112157
ensure_publication(new_version)
113158

114159
commit_version_code(new_version)

0 commit comments

Comments
 (0)