Last active
February 5, 2019 07:37
-
-
Save vberlier/779c7488fc101685539d2e8673802229 to your computer and use it in GitHub Desktop.
Travis configuration for publishing python packages using poetry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
language: python | |
sudo: false | |
dist: xenial | |
cache: | |
pip: true | |
directories: | |
- $HOME/.cache/pypoetry | |
install: | |
- curl -sSL https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py | python | |
- source $HOME/.poetry/env | |
- poetry install | |
script: poetry run pytest | |
jobs: | |
include: | |
- python: 3.6 | |
- python: 3.7 | |
- stage: publish | |
python: 3.7 | |
if: tag IS present | |
script: ./publish.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
toml-string () { | |
grep -Po "^\s*$2\s*=\s*".+"\s*$" "$1" | sed -r 's!.*"(.+)".*!\1!' | |
} | |
published () { | |
local package="$1" | |
echo -e "\nComparing built distributions with published releases\n" | |
local releases=$(curl -sSL "https://pypi.org/simple/$package/") | |
for dist in $(ls dist); do | |
echo -e "Checking \033[1;33m$dist\033[0m" | |
if ! echo "$releases" | grep -Fq "$dist"; then | |
echo -e "\n\033[1;31mCouldn't find distribution $dist in the published releases\033[0m" | |
return 1 | |
fi | |
done | |
return 0 | |
} | |
publish () { | |
local name="$1" | |
local version="$2" | |
if published "$name"; then | |
echo -e "\n\033[1;36m$name v$version is already published\033[0m" | |
else | |
echo -e "\n\033[1;36mPublishing $name v$version\033[0m" | |
poetry publish \ | |
--username="$PYPI_USERNAME" \ | |
--password="$PYPI_PASSWORD" \ | |
--no-interaction || return 1 | |
fi | |
} | |
poetry build && publish \ | |
"$(toml-string pyproject.toml name)" \ | |
"$(toml-string pyproject.toml version)" || exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment