-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpublish.sh
executable file
·60 lines (51 loc) · 2.31 KB
/
publish.sh
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
current_git_branch=$(git name-rev --name-only HEAD)
is_main_branch=$(echo $current_git_branch | tr -d "\n" | grep -E "(^|^remotes\/origin\/)main$")
if [[ -z "$is_main_branch" ]]
then
old_version=$(git diff origin/main -- pyproject.toml | grep '^\-version' | tr -dc '0-9.')
new_version=$(git diff origin/main -- pyproject.toml | grep '^\+version' | tr -dc '0-9.')
else
old_version=$(git diff HEAD~1 -- pyproject.toml | grep '^\-version' | tr -dc '0-9.')
new_version=$(git diff HEAD~1 -- pyproject.toml | grep '^\+version' | tr -dc '0-9.')
fi
echo "On branch \"$current_git_branch\": old_version=\"$old_version\", new_version=\"$new_version\""
if [ -z "$new_version" ]
then
echo "Changes not meant as a new version. Aborting."
exit
fi
echo "Changes meant as new a version (from $old_version to $new_version)"
if [[ -z "$is_main_branch" ]]
then
echo "Not on \"origin/main\" branch [branch=$current_git_branch], creating custom dev version based on commit hash ..."
git_short_commit_hash_int=$(git rev-parse --short=7 HEAD | python -c "import sys; print(int(input(), 16))")
new_version_custom="$new_version.dev$git_short_commit_hash_int"
sed -i "s/version = \"$new_version\"/version = \"$new_version_custom\"/" pyproject.toml
new_version=$new_version_custom
repository="pypitest"
download_index_url="https://test.pypi.org/simple/"
export TWINE_PASSWORD=$PYPI_TOKEN_DEV
trap "git checkout -- pyproject.toml" EXIT
else
echo "On \"$current_git_branch\" branch"
repository="pypi"
download_index_url="https://pypi.org/simple/"
export TWINE_PASSWORD=$PYPI_TOKEN
fi
echo "Installling build & twine ..."
pip install build > /dev/null
pip install twine > /dev/null
echo "Building aiotaskq==$new_version..."
rm -rf dist/
python -m build
echo "Uploading to $repository ..."
python -m twine check --strict dist/*
python -m twine upload --repository $repository --non-interactive --config-file ./.pypirc --verbose dist/*
echo "You can now install aiotaskq==$new_version from $repository using the following command"
if [ -z "$is_main_branch" ]
then
echo "(Might need to wait for a few hours (~12 hours), see https://github.com/pypa/pypi-support/issues/235#issuecomment-592930117)"
fi
echo "***"
echo "pip install --index-url $download_index_url --no-deps aiotaskq==$new_version"
echo "***"