diff --git a/docs/automatic-releases/index.rst b/docs/automatic-releases/index.rst index b54eaa0ec..da3b417eb 100644 --- a/docs/automatic-releases/index.rst +++ b/docs/automatic-releases/index.rst @@ -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. diff --git a/docs/envvars.rst b/docs/envvars.rst index 58505a833..37486a317 100644 --- a/docs/envvars.rst +++ b/docs/envvars.rst @@ -91,8 +91,8 @@ when pushing tags, publishing releases etc. .. _env-repository: -Artifact Repository Authentication -================================== +Artifact Repository +=================== .. _env-pypi_token: @@ -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 `_. + +.. _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. diff --git a/semantic_release/defaults.cfg b/semantic_release/defaults.cfg index 642c9776b..d49e5982c 100644 --- a/semantic_release/defaults.cfg +++ b/semantic_release/defaults.cfg @@ -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} diff --git a/semantic_release/repository.py b/semantic_release/repository.py index ead23173c..2e99fe2d1 100644 --- a/semantic_release/repository.py +++ b/semantic_release/repository.py @@ -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: diff --git a/tests/test_repository.py b/tests/test_repository.py index 64b0ba40f..d48e080dd 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -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",