Skip to content

Commit

Permalink
feat: override repository_url w REPOSITORY_URL env var (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
briandcho authored and relekang committed Jul 29, 2022
1 parent d6fcb5f commit cb7578c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
5 changes: 3 additions & 2 deletions docs/automatic-releases/index.rst
Expand Up @@ -75,8 +75,9 @@ Configuring distribution upload
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
In order to upload to an artifact repository, Python Semantic Release needs credentials to access
the project. You will need to set the environment variables :ref:`env-repository_username` and
:ref:`env-repository_password`. Use :ref:`config-repository_url` to set a custom repository url.
As an alternative the repository and/or credentials can be configured using the ``~/.pypirc`` file.
:ref:`env-repository_password`. Use :ref:`config-repository_url` or :ref:`env-repository_url` to
set a custom repository url. As an alternative the repository and/or credentials can be configured
using the ``~/.pypirc`` file.

.. warning::
Make sure to protect any environment variable containing secrets on your CI service.
Expand Down
13 changes: 11 additions & 2 deletions docs/envvars.rst
Expand Up @@ -91,8 +91,8 @@ when pushing tags, publishing releases etc.

.. _env-repository:

Artifact Repository Authentication
==================================
Artifact Repository
===================

.. _env-pypi_token:

Expand Down Expand Up @@ -150,3 +150,12 @@ Also used for token when using token authentication.
output. This can break things, for example repository links.

- Find more information on `how to obtain a token <https://pypi.org/help/#apitoken>`_.

.. _env-repository_url:

``REPOSITORY_URL``
------------------
Custom repository (package index) URL to upload the package to.
Takes precedence over :ref:`config-repository_url`

See :ref:`automatic-dist-upload` for more about uploads to custom repositories.
1 change: 1 addition & 0 deletions semantic_release/defaults.cfg
Expand Up @@ -36,6 +36,7 @@ pypi_token_var=PYPI_TOKEN
pypi_user_var=PYPI_USERNAME
repository_user_var=REPOSITORY_USERNAME
repository_pass_var=REPOSITORY_PASSWORD
repository_url_var=REPOSITORY_URL
remove_dist=true
tag_commit=true
tag_format=v{version}
Expand Down
2 changes: 1 addition & 1 deletion semantic_release/repository.py
Expand Up @@ -109,7 +109,7 @@ def _handle_repository_config(self) -> None:
Defaults to repository_name `pypi` when both are not set.
"""
repository_url = config.get("repository_url")
repository_url = get_env_var("repository_url_var") or config.get("repository_url")
repository_name = config.get("repository")

if repository_url:
Expand Down
7 changes: 7 additions & 0 deletions tests/test_repository.py
Expand Up @@ -155,6 +155,13 @@ def test_repo_with_custom_repo_url(mock_handle_creds):
assert repo.repository_url == "https://custom-repo"


@mock.patch.dict("os.environ", {"REPOSITORY_URL": "https://custom-repo"})
@mock.patch.object(ArtifactRepo, "_handle_credentials_init")
def test_repo_with_custom_repo_url_from_env(mock_handle_creds):
repo = ArtifactRepo(Path("dist"))
assert repo.repository_url == "https://custom-repo"


@mock.patch("semantic_release.repository.twine_upload")
@mock.patch(
"semantic_release.repository.config.get",
Expand Down

0 comments on commit cb7578c

Please sign in to comment.