This repository was archived by the owner on Jul 24, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·73 lines (58 loc) · 1.88 KB
/
Copy pathrelease.sh
File metadata and controls
executable file
·73 lines (58 loc) · 1.88 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
#!/bin/bash
# Python Package Build and Release
# https://pypi.org/project/mdtocf/
set -e
if [ -f .env ]; then
set -a && source .env && set +a
fi
if [ -z "$1" ]; then
echo "Usage: $0 <live|test>"
echo " live: Publish to PyPI"
echo " test: Publish to Test PyPI"
exit 1
fi
if [ "$1" == "live" ] && [ -z "$PYPI_LIVE_TOKEN" ]; then
echo "Error: PYPI_LIVE_TOKEN is not set."
exit 1
elif [ "$1" == "test" ] && [ -z "$PYPI_TEST_TOKEN" ]; then
echo "Error: PYPI_TEST_TOKEN is not set."
exit 1
fi
echo "Setting up virtual environment..."
if [ ! -f .venv/bin/uv ]; then
python3 -m venv .venv && .venv/bin/pip install uv --quiet
fi
.venv/bin/uv sync --group dev
echo "Running tests..."
.venv/bin/uv run pytest tests
echo "Running code formatting checks..."
.venv/bin/uv run ruff format --check . || {
echo "Fix code formatting issues before releasing."
exit 1
}
echo "Checking for uncommitted changes..."
git diff --exit-code
git diff --cached --exit-code
echo "Checking if git tag matches pyproject.toml version..."
PROJECT_VERSION=$(.venv/bin/uv run python -c "import tomllib; f=open('pyproject.toml','rb'); data=tomllib.load(f); f.close(); print(data['project']['version'])")
TAG_NAME="${PROJECT_VERSION}"
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
echo "Git tag '$TAG_NAME' already exists."
else
echo "Creating git tag '$TAG_NAME'..."
git tag "$TAG_NAME"
fi
echo "Cleaning up previous builds..."
rm -rf ./dist ./build *.egg-info
echo "Building the package..."
.venv/bin/uv build
echo "Pushing changes remote repository..."
git push
git push --tags
if [ "$1" == "live" ]; then
echo "Publishing to PyPI..."
.venv/bin/uvx twine upload --username __token__ --password "${PYPI_LIVE_TOKEN}" dist/*
elif [ "$1" == "test" ]; then
echo "Publishing to (Test) PyPI..."
.venv/bin/uvx twine upload --username __token__ --password "${PYPI_TEST_TOKEN}" --repository testpypi dist/*
fi