Skip to content

Commit

Permalink
feat(PyPi): Deploy to Test PyPi with Tags #13 (#115)
Browse files Browse the repository at this point in the history
Test PyPi allows checking a new package without using the main
PyPi index.

closes #13
  • Loading branch information
imAsparky committed Sep 23, 2021
1 parent 6050722 commit f0fe67f
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.rst
Expand Up @@ -89,6 +89,8 @@ Features
first commit automatically. Also if you have opted to use the
Conventional-Commits_ style git commit message template, cookiecutter
will simultaneously add it to your local git config file.
#. Optional to use Test PyPi. Create a git `dev` tag before you push
to the repository.

.. note::

Expand Down
7 changes: 4 additions & 3 deletions cookiecutter.json
Expand Up @@ -21,11 +21,12 @@
"use_pre_commit": "y",
"use_GH_custom_issue_templates": "y",
"automatic_set_up_git_and_initial_commit": "y",
"use_release_to_test_pypi_with_tags": "n",
"open_source_license": ["MIT license", "BSD license", "ISC license", "Apache Software License 2.0", "GNU General Public License v3", "Not open source"],
"_copy_without_render": [
".github/workflows/test_contribution.yaml",
".pre-commit-config.yaml",
".github/workflows/semantic_release.yaml",
".pre-commit-config.yaml"

".github/workflows/semantic_release_test_pypi.yaml",
".github/workflows/test_contribution.yaml"
]
}
1 change: 1 addition & 0 deletions docs/source/prompts.rst
Expand Up @@ -232,6 +232,7 @@ project.
be one way to use the test PyPi releases.



**open_source_license**
*default = MIT*

Expand Down
3 changes: 3 additions & 0 deletions hooks/post_gen_project.py
Expand Up @@ -165,3 +165,6 @@ def remove_file(filepath):

if "{{ cookiecutter.create_conventional_commits_edit_message}}" == "y":
git_configure_custom_commit_message()

if "{{ cookiecutter.use_release_to_test_pypi_with_tags }}" != "y":
remove_file(".github/workflows/semantic_release_test_pypi.yaml")
28 changes: 28 additions & 0 deletions tests/test_bake_project.py
Expand Up @@ -677,3 +677,31 @@ def test_bake_with_git_add_commit_success(cookies):
assert "HEAD@{0}: commit (initial):" in post_gen_setup(
"git", "reflog", cwd=str(result.project)
)


def test_bake_with_release_test_pypi(cookies):
"""
Test cookiecutter created the package with release to test pypi.
"""
with bake_in_temp_dir(
cookies, extra_context={"use_release_to_test_pypi_with_tags": "y"}
) as result:

test_pypi_with_files = [
f.basename for f in result.project.join(".github/workflows").listdir()
]
assert "semantic_release_test_pypi.yaml" in test_pypi_with_files


def test_bake_without_release_test_pypi(cookies):
"""
Test cookiecutter created the package without release to test pypi.
"""
with bake_in_temp_dir(
cookies, extra_context={"use_release_to_test_pypi_with_tags": "n"}
) as result:

test_pypi_without_files = [
f.basename for f in result.project.join(".github/workflows").listdir()
]
assert "semantic_release_test_pypi.yaml" not in test_pypi_without_files
@@ -0,0 +1,62 @@
name: Semantic Release Test Pypi

on:
tags:
- dev*

workflow_dispatch:

concurrency:
group: Semantic Release

jobs:
test_contribs:
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9"]
os: [macos-latest, ubuntu-latest, windows-latest]

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox
run: tox

release:
needs: test_contribs
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
token: ${{ secrets.SEM_VER }}
fetch-depth: 0

- name: Python Semantic Release
uses: relekang/python-semantic-release@master
with:
github_token: ${{ secrets.SEM_VER }}


publish:
name: Publish to Test PyPi
needs: release
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.TEST_PYPI_TOKEN}}
repository_url: https://test.pypi.org/legacy/
skip_existing: true

0 comments on commit f0fe67f

Please sign in to comment.