From fa9cb2f468eb4d8a45c7cc0aef4afe8070ffb55a Mon Sep 17 00:00:00 2001 From: mhuin Date: Mon, 7 Jan 2019 18:16:56 +0100 Subject: [PATCH] upload-pypi: add option to register packages When uploading packages to a devPI instance, the role fails if the packages are not registered first. Since this is not required on PyPI, this adds the "pypi_register_first" option to the role so that users can choose to do so. Change-Id: I2b50362e485175d51840e49ffc09a734b44ec85d --- roles/upload-pypi/README.rst | 6 ++++++ roles/upload-pypi/defaults/main.yaml | 1 + roles/upload-pypi/tasks/main.yaml | 12 ++++++++++++ 3 files changed, 19 insertions(+) diff --git a/roles/upload-pypi/README.rst b/roles/upload-pypi/README.rst index cbcc0dab1..aba4b56f4 100644 --- a/roles/upload-pypi/README.rst +++ b/roles/upload-pypi/README.rst @@ -35,3 +35,9 @@ Upload python packages to PyPI :default: twine Path to twine executable. + +.. zuul:rolevar:: pypi_register_first + :default: false + + Whether the role should register the package before uploading it. This may + be required when uploading for the first time to a devPI instance. diff --git a/roles/upload-pypi/defaults/main.yaml b/roles/upload-pypi/defaults/main.yaml index c0cb93b96..1d4b7501f 100644 --- a/roles/upload-pypi/defaults/main.yaml +++ b/roles/upload-pypi/defaults/main.yaml @@ -3,3 +3,4 @@ pypi_path: "src/{{ zuul.project.canonical_name }}/dist" pypi_repository: "{{ pypi_info.repository|default('pypi') }}" pypi_repository_url: "{{ pypi_info.repository_url|default(None) }}" pypi_twine_executable: twine +pypi_register_first: false diff --git a/roles/upload-pypi/tasks/main.yaml b/roles/upload-pypi/tasks/main.yaml index 864fe4def..fb5c10cc8 100644 --- a/roles/upload-pypi/tasks/main.yaml +++ b/roles/upload-pypi/tasks/main.yaml @@ -20,6 +20,11 @@ msg: "Found no wheels to upload: {{found_wheels.msg}}" when: found_wheels.files == [] +- name: Register packages on the PyPI server (via wheels) + command: "{{ pypi_twine_executable }} register --config-file {{ _pypirc_tmp.path }} --repository {{ pypi_repository }} {{ item.path }}" + with_items: "{{ found_wheels.files }}" + when: pypi_register_first + - name: Upload wheel with twine before tarballs command: "{{ pypi_twine_executable }} upload --config-file {{ _pypirc_tmp.path }} -r {{ pypi_repository }} {{ item.path }}" with_items: "{{ found_wheels.files }}" @@ -35,6 +40,13 @@ msg: "Found no tarballs to upload: {{found_tarballs.msg}}" when: found_tarballs.files == [] +- name: Register packages on the PyPI server (via tarballs) + command: "{{ pypi_twine_executable }} register --config-file {{ _pypirc_tmp.path }} --repository {{ pypi_repository }} {{ item.path }}" + with_items: "{{ found_tarballs.files }}" + when: + - pypi_register_first + - found_wheels.files == [] + - name: Upload tarballs with twine command: "{{ pypi_twine_executable }} upload --config-file {{ _pypirc_tmp.path }} -r {{ pypi_repository }} {{ item.path }}" with_items: "{{ found_tarballs.files }}"