Skip to content

Commit f6c4687

Browse files
authored
chore: use semantic-release for most of release script execution (#1165)
* chore: use semantic-release for most of release script execution * docs: update readme * remove unused modules from release.py * cleanup more * cleanup more * simplify * reformat with ruff
1 parent 04a8580 commit f6c4687

File tree

4 files changed

+25
-88
lines changed

4 files changed

+25
-88
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
# CHANGELOG
22

3+
<!-- version list -->
34

45
## Unreleased
56

67
### Chores
78

8-
- Add python-semantic-release as the deps
9-
([`0a2ffad`](https://github.com/appium/python-client/commit/0a2ffad9f3fb37f7ef5ef6632514f07e1fc97359))
9+
- Revert version created by release script checking
10+
([#1164](https://github.com/appium/python-client/pull/1164),
11+
[`04a8580`](https://github.com/appium/python-client/commit/04a8580f999843bc9d121c1ed4ce872761350f31))
12+
13+
- Use semantic release changelog instead of gitchangelog
14+
([#1163](https://github.com/appium/python-client/pull/1163),
15+
[`dd3709e`](https://github.com/appium/python-client/commit/dd3709e084e802d6534d51151be1bd45456a4ebd))
1016

1117
### Documentation
1218

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -529,13 +529,18 @@ uv run pytest -n 2 test/functional/ios/search_context/find_by_ios_class_chain_te
529529
530530
Follow the below steps.
531531
532+
Set `GH_TOKEN` env var to update the GitHub contents.
533+
532534
```bash
533-
uv pip install setuptools
535+
# Used to publish the package to pypi
534536
uv pip install twine
535-
# Type the new version number and 'yes' if you can publish it
536-
# You can test the command with DRY_RUN
537-
DRY_RUN=1 ./release.sh
538-
./release.sh # release
537+
538+
rm -rf dist
539+
# bumping the version, building a package and creating a tag.
540+
uv run semantic-release version
541+
542+
# this 'release' script now has pushing built modules to pypi only.
543+
./release.sh # and type the target version.
539544
```
540545
541546
If the `pypi` was not able to publish with user name and password, please try out `-u` and `-p` option by yourself with `twine` such as `twine upload -u <name> -p <pass> dist/Appium-Python-Client-4.1.0.tar.gz`.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ prerelease = false
102102
[tool.semantic_release.changelog]
103103
exclude_commit_patterns = []
104104
mode = "update"
105-
insertion_flag = "=========\nCHANGELOG\n========="
105+
insertion_flag = "<!-- version list -->"
106106
template_dir = "templates"
107107

108108
[tool.semantic_release.changelog.default_templates]

script/release.py

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

16-
import glob
1716
import os
18-
import shutil
19-
import subprocess
2017
import sys
21-
from typing import List
2218

2319
CHANGELOG_PATH = os.path.join(os.path.dirname('__file__'), 'CHANGELOG.md')
2420

@@ -35,35 +31,18 @@ def print_current_version():
3531

3632

3733
def get_new_version():
38-
print(MESSAGE_GREEN.format('new version:'))
34+
print(MESSAGE_GREEN.format('Pushing version:'))
3935
for line in sys.stdin:
4036
return line.rstrip()
4137

4238

43-
VERSION_FORMAT = "version = '{}'\n"
44-
45-
46-
def update_version_file(version):
47-
call_bash_script(f'uv version {version}')
48-
49-
5039
def call_bash_script(cmd):
5140
if os.environ.get('DRY_RUN') is not None:
5241
print('{} Calls: {}'.format(MESSAGE_RED.format('[DRY_RUN]'), cmd))
5342
else:
5443
os.system(cmd)
5544

5645

57-
def commit_version_code(new_version_num):
58-
call_bash_script('git commit pyproject.toml uv.lock -m "Bump {}"'.format(new_version_num))
59-
60-
61-
def tag_and_generate_changelog(new_version_num):
62-
call_bash_script('git tag "v{}"'.format(new_version_num))
63-
call_bash_script('uv run semantic-release changelog')
64-
call_bash_script('git commit {} -m "Update changelog for {}"'.format(CHANGELOG_PATH, new_version_num))
65-
66-
6746
def upload_sdist(new_version_num):
6847
wheel_file = 'dist/appium_python_client-{}-py3-none-any.whl'.format(new_version_num)
6948
push_file = 'dist/appium_python_client-{}.tar.gz'.format(new_version_num)
@@ -77,81 +56,28 @@ def upload_sdist(new_version_num):
7756
)
7857

7958

80-
def push_changes_to_master(new_version_num):
81-
call_bash_script('git push origin master')
82-
call_bash_script('git push origin "v{}"'.format(new_version_num))
83-
84-
8559
def ensure_publication(new_version_num):
8660
if os.environ.get('DRY_RUN') is not None:
8761
print('Run with {} mode.'.format(MESSAGE_RED.format('[DRY_RUN]')))
8862

89-
print('Are you sure to release as {}?[y/n]'.format(MESSAGE_YELLOW.format(new_version_num)))
63+
print(
64+
'Are you sure to publish a new built modules in dist directory as {}?[y/n]'.format(
65+
MESSAGE_YELLOW.format(new_version_num)
66+
)
67+
)
9068
for line in sys.stdin:
9169
if line.rstrip().lower() == 'y':
9270
return
9371
sys.exit('Canceled release process.')
9472

9573

96-
def build_sdist():
97-
call_bash_script('uv build')
98-
99-
100-
def build() -> None:
101-
shutil.rmtree(BUILT_APPIUM_DIR_PATH, ignore_errors=True)
102-
status, output = subprocess.getstatusoutput('uv run python setup.py install')
103-
if status != 0:
104-
sys.exit(f'Failed to build the package:\n{output}')
105-
106-
107-
def get_py_files_in_dir(root_dir: str) -> List[str]:
108-
return [
109-
file_path[len(root_dir) :]
110-
for file_path in glob.glob(f'{root_dir}/**/*.py', recursive=True) + glob.glob(f'{root_dir}/**/*.typed', recursive=True)
111-
]
112-
113-
114-
def assert_files_count_in_package() -> None:
115-
original_files = get_py_files_in_dir(APPIUM_DIR_PATH)
116-
built_files = get_py_files_in_dir(BUILT_APPIUM_DIR_PATH)
117-
118-
if len(original_files) != len(built_files):
119-
print(f"The count of files in '{APPIUM_DIR_PATH}' and '{BUILT_APPIUM_DIR_PATH}' were different.")
120-
121-
original_files_set = set(original_files)
122-
built_files_set = set(built_files)
123-
124-
diff = original_files_set.difference(built_files_set)
125-
if diff:
126-
print(f"'{APPIUM_DIR_PATH}' has '{diff}' files than {BUILT_APPIUM_DIR_PATH}")
127-
diff = built_files_set.difference(original_files_set)
128-
if diff:
129-
print(f'{BUILT_APPIUM_DIR_PATH} has {diff} files than {APPIUM_DIR_PATH}')
130-
131-
sys.exit(
132-
f"Python files in '{BUILT_APPIUM_DIR_PATH}' may differ from '{APPIUM_DIR_PATH}'. "
133-
'Please make sure setup.py is configured properly.'
134-
)
135-
136-
13774
def main():
13875
print_current_version()
13976
new_version = get_new_version()
14077

141-
update_version_file(new_version)
142-
143-
build()
144-
assert_files_count_in_package()
145-
14678
ensure_publication(new_version)
14779

148-
commit_version_code(new_version)
149-
build_sdist()
150-
151-
tag_and_generate_changelog(new_version)
152-
15380
upload_sdist(new_version)
154-
push_changes_to_master(new_version)
15581

15682

15783
if __name__ == '__main__':

0 commit comments

Comments
 (0)