1+ #! /bin/bash
2+
3+ # Ensure the script exits if any command fails
4+ set -e
5+
6+ # Check if one argument is passed
7+ if [ " $# " -ne 1 ]; then
8+ echo " Usage: $0 <package-name>"
9+ echo " Example: $0 ansys-api-geometry"
10+ exit 1
11+ fi
12+
13+ # Assign the argument to a variable
14+ PACKAGE_NAME=$1
15+
16+ echo " Upgrading $PACKAGE_NAME to latest version..."
17+
18+ # Check if curl and jq are available
19+ if ! command -v curl & > /dev/null; then
20+ echo " Error: curl is required but not installed"
21+ exit 1
22+ fi
23+
24+ if ! command -v jq & > /dev/null; then
25+ echo " Error: jq is required but not installed"
26+ exit 1
27+ fi
28+
29+ # Check if the package exists on PyPI and get latest version
30+ echo " Fetching latest version from PyPI..."
31+ LATEST_VERSION=$( curl -s " https://pypi.org/pypi/$PACKAGE_NAME /json" | jq -r ' .info.version' )
32+
33+ if [ $? -ne 0 ]; then
34+ echo " Error: Failed to fetch package info from PyPI"
35+ exit 1
36+ fi
37+
38+ if [ " $LATEST_VERSION " == " null" ] || [ -z " $LATEST_VERSION " ]; then
39+ echo " Error: Could not find version for package $PACKAGE_NAME "
40+ echo " Please check that the package name is correct and exists on PyPI"
41+ exit 1
42+ fi
43+
44+ echo " Latest version found: $LATEST_VERSION "
45+
46+ # Files to update - with respect to this script file location
47+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
48+ PYPROJECT_FILE=" $SCRIPT_DIR /../pyproject.toml"
49+ SETUP_FILE=" $SCRIPT_DIR /../setup.py"
50+
51+ # Update pyproject.toml
52+ echo " Updating $PYPROJECT_FILE ..."
53+ # Use sed to replace the package version in pyproject.toml
54+ # This handles both == and >= patterns
55+ sed -i.tmp " s/\" $PACKAGE_NAME [=<>!]*[0-9.]*\" /\" $PACKAGE_NAME ==$LATEST_VERSION \" /g" " $PYPROJECT_FILE "
56+ rm -f " $PYPROJECT_FILE .tmp"
57+
58+ # Update setup.py
59+ echo " Updating $SETUP_FILE ..."
60+ # Use sed to replace the package version in setup.py
61+ # This handles both == and >= patterns in the install_requires list
62+ sed -i.tmp " s/\" $PACKAGE_NAME [=<>!]*[0-9.]*\" /\" $PACKAGE_NAME ==$LATEST_VERSION \" /g" " $SETUP_FILE "
63+ rm -f " $SETUP_FILE .tmp"
64+
65+ # Verify changes
66+ echo " "
67+ echo " Changes made:"
68+ echo " ============="
69+
70+ echo " "
71+ echo " In $PYPROJECT_FILE :"
72+ grep " $PACKAGE_NAME " " $PYPROJECT_FILE " || echo " Package not found in $PYPROJECT_FILE "
73+
74+ echo " "
75+ echo " In $SETUP_FILE :"
76+ grep " $PACKAGE_NAME " " $SETUP_FILE " || echo " Package not found in $SETUP_FILE "
77+
78+ echo " "
79+ echo " Upgrade completed successfully!"
80+ echo " Package $PACKAGE_NAME has been updated to version $LATEST_VERSION "
81+
82+ # Submit a pull request with the changes - create a branch, commit, push, and open PR
83+ # Only if there are changes to commit
84+ if git diff --quiet " $PYPROJECT_FILE " " $SETUP_FILE " ; then
85+ echo " No changes detected in $PYPROJECT_FILE or $SETUP_FILE . Exiting without creating a PR."
86+ exit 0
87+ else
88+ echo " Changes detected. Proceeding to create a pull request."
89+ fi
90+
91+ BRANCH_NAME=" upgrade/$PACKAGE_NAME -to-$LATEST_VERSION "
92+ git checkout -b " $BRANCH_NAME "
93+ git add " $PYPROJECT_FILE " " $SETUP_FILE "
94+ git commit -m " build: upgrade $PACKAGE_NAME to $LATEST_VERSION "
95+ git push origin " $BRANCH_NAME "
96+
97+ # Create the pull request
98+ gh pr create --title " build: upgrade $PACKAGE_NAME to $LATEST_VERSION " --body " This PR upgrades $PACKAGE_NAME to version $LATEST_VERSION ." --head " $BRANCH_NAME " --base main
99+ if [ $? -ne 0 ]; then
100+ echo " Error: Failed to create pull request"
101+ exit 1
102+ else
103+ echo " Pull request created successfully."
104+ fi
0 commit comments