Add upload-pypi role

Create a role to upload python artificats using twine

username and password are required, so remove them from
defaults. Install twine in the homedir by default if the twine command
is not found.

Upload wheels if found first, then tarballs.
Change-Id: I8857e2983e1175107164536d57e313a5b404bddb
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
This commit is contained in:
Paul Belanger 2017-08-21 15:53:09 -04:00 committed by Monty Taylor
parent 0f7b75094a
commit f94b0b809d
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
4 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,32 @@
Upload python packages to PyPI
**Role Variables**
.. zuul:rolevar:: pypi_info
Complex argument which contains the information about the PyPI
server as well as the authentication information needed. It is
expected that this argument comes from a `Secret`.
.. zuul:rolevar:: username
Username to use to log in to PyPI.
.. zuul:rolevar:: password
Password to use to log in to PyPI.
.. zuul:rolevar:: repository
:default: pypi
Name of the repository to upload to
.. zuul:rolevar:: repository_url
:default: https://pypi.python.org/pypi
URL of the PyPI repostory
.. zuul:rolevar:: pypi_path
:default: src/{{ zuul.project.canonical_name }}/dist
Path containing artifacts to upload.

View File

@ -0,0 +1,4 @@
---
pypi_path: "src/{{ zuul.project.canonical_name }}/dist"
pypi_repository: "{{ pypi_info.repository|default('pypi') }}"
pypi_repository_url: "{{ pypi_info.repository_url|default('https://pypi.python.org/pypi') }}"

View File

@ -0,0 +1,36 @@
- name: Check for twine install
command: which twine
ignore_errors: yes
register: twine_command_which
- name: Ensure twine is installed
command: pip install --user twine
when: not twine_command_which|succeeded
- name: Install .pypirc configuration file
template:
dest: ~/.pypirc
mode: 0400
src: .pypirc.j2
- name: Find wheels to upload
find:
paths: "{{ pypi_path }}"
patterns: "*.whl"
register: found_wheels
- name: Upload wheel with twine before tarballs
command: "twine upload -r {{ pypi_repository }} {{ item }}"
with_items: "{{ found_wheels.files }}"
when: found_wheels.matched|bool
- name: Find tarballs to upload
find:
paths: "{{ pypi_path }}"
patterns: "*.tar.gz"
register: found_tarballs
- name: Upload tarballs with twine
command: "twine upload -r {{ pypi_repository }} {{ item }}"
with_items: "{{ found_tarballs.files }}"
when: found_tarballs.matched|bool

View File

@ -0,0 +1,8 @@
[distutils]
index-servers=
{{ pypi_repository }}
[{{ pypi_repository }}]
repository:{{ pypi_repository_url }}
username:{{ pypi_info.username }}
password:{{ pypi_info.password }}