-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate_version.sh
More file actions
executable file
·84 lines (71 loc) · 2.34 KB
/
update_version.sh
File metadata and controls
executable file
·84 lines (71 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
#
# Update the version of AnsiblePlayTest and create a release
#
# Default values
NEW_VERSION=""
TAG_VERSION=true
PUSH_CHANGES=false
# Parse command-line arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--version) NEW_VERSION="$2"; shift ;;
--no-tag) TAG_VERSION=false ;;
--push) PUSH_CHANGES=true ;;
*) echo "Unknown parameter: $1"; exit 1 ;;
esac
shift
done
# Check if version is provided
if [ -z "$NEW_VERSION" ]; then
echo "Error: Version must be specified with --version parameter"
echo "Usage: $0 --version X.Y.Z [--no-tag] [--push]"
exit 1
fi
# Get the directory of this script
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# Check that the version has a valid format
if ! [[ $NEW_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Version must be in format X.Y.Z"
exit 1
fi
# Update version in pyproject.toml
echo "Updating version in pyproject.toml..."
sed -i "s/^version = \".*\"/version = \"$NEW_VERSION\"/" "$SCRIPT_DIR/pyproject.toml"
# Update version in __init__.py
echo "Updating version in __init__.py..."
sed -i "s/__version__ = \".*\"/__version__ = \"$NEW_VERSION\"/" "$SCRIPT_DIR/ansible_playtest/__init__.py"
# Update version in setup.py (if needed)
if [ -f "$SCRIPT_DIR/setup.py" ]; then
if grep -q "version=" "$SCRIPT_DIR/setup.py"; then
echo "Updating version in setup.py..."
sed -i "s/version=\".*\"/version=\"$NEW_VERSION\"/" "$SCRIPT_DIR/setup.py"
fi
fi
# Create a git commit for the version change
echo "Creating git commit for version $NEW_VERSION..."
git add "$SCRIPT_DIR/pyproject.toml" "$SCRIPT_DIR/ansible_playtest/__init__.py"
if [ -f "$SCRIPT_DIR/setup.py" ]; then
git add "$SCRIPT_DIR/setup.py"
fi
git commit -m "Release version $NEW_VERSION"
# Create a git tag for the version
if $TAG_VERSION; then
echo "Creating git tag v$NEW_VERSION..."
git tag -a "v$NEW_VERSION" -m "Version $NEW_VERSION"
fi
# Push changes if requested
if $PUSH_CHANGES; then
echo "Pushing changes and tags to remote repository..."
git push
git push --tags
fi
echo "Version updated to $NEW_VERSION"
echo ""
echo "Next steps:"
if ! $PUSH_CHANGES; then
echo "1. Push the changes: git push && git push --tags"
fi
echo "2. Build the distribution: python -m build"
echo "3. Upload to PyPI: twine upload dist/*"
exit 0