diff --git a/README.rst b/README.rst index 4a088a5..87b9ce6 100644 --- a/README.rst +++ b/README.rst @@ -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:: diff --git a/cookiecutter.json b/cookiecutter.json index e65f308..f401336 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -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" ] } diff --git a/docs/source/prompts.rst b/docs/source/prompts.rst index c98a527..f5ea6b7 100644 --- a/docs/source/prompts.rst +++ b/docs/source/prompts.rst @@ -232,6 +232,7 @@ project. be one way to use the test PyPi releases. + **open_source_license** *default = MIT* diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 5675f61..43e94ee 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -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") diff --git a/tests/test_bake_project.py b/tests/test_bake_project.py index 92b608e..e299646 100644 --- a/tests/test_bake_project.py +++ b/tests/test_bake_project.py @@ -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 diff --git a/{{cookiecutter.project_slug}}/.github/workflows/semantic_release_test_pypi.yaml b/{{cookiecutter.project_slug}}/.github/workflows/semantic_release_test_pypi.yaml new file mode 100644 index 0000000..b73b2d9 --- /dev/null +++ b/{{cookiecutter.project_slug}}/.github/workflows/semantic_release_test_pypi.yaml @@ -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