Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(version): Add pkg GH action sem-ver opt #14 #74

Merged
merged 1 commit into from
Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 9 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

**Checkout the** Projects_ **page to see what is planned.**

**We are aiming for Continuous Delivery, also,
Keeping it automated and straightforward.**
**We are aiming for your new package to use a Continuous Delivery workflow,
keeping it automated and straightforward.**

.. .. image:: https://pyup.io/repos/github/audreyfeldroy/cookiecutter-pypackage/shield.svg
.. :target: https://pyup.io/repos/github/audreyfeldroy/cookiecutter-pypackage/
Expand Down Expand Up @@ -63,14 +63,17 @@ Cookiecutter_ template for a Python package.
pull request to the main branch starts.
#. Tox configuration for your package now includes an OS and Python test matrix.
OS includes Linux, macOS and Windows. Python 3.6 - 3.9.
#. Added an optional GitHub action to automatically update semantic version and
publish assets to your package repository when a pull request merge is
closed or manually.
#. Semantic versioning and publishing are also available locally, bypassing
the need for a GitHub action if that is your preferred workflow.

Features
--------

* Tox_ testing: Setup to easily test for Python 3.6, 3.7, 3.8 and 3.9.
* Sphinx_ docs: Documentation ready for generation with, for example, `Read the Docs`_.
* bump2version_: Pre-configured version bumping with a single command.
* Auto-release to PyPI_ when you push a new tag to master (optional).
* Auto-release to PyPI_ when you push a new tag to main (optional). Coming soon.
* Use commit tags to release to Test-PyPi_. Coming soon.
* Command line interface using Click (optional).

Expand All @@ -84,7 +87,7 @@ Features
.. Build Status
.. -------------

Linux:
.. Linux:

.. .. image:: https://img.shields.io/travis/audreyfeldroy/cookiecutter-pypackage.svg
.. :target: https://travis-ci.org/audreyfeldroy/cookiecutter-pypackage
Expand Down
7 changes: 5 additions & 2 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
"create_conventional_commits_edit_message": "y",
"create_repo_auto_test_workflow": "y",
"create_auto_CHANGELOG": "y",
"github_access_token": ["secrets.GITHUB_TOKEN", "secrets.CHANGELOG_UPDATE"],
"github_CHANGELOG_access_token": ["secrets.GITHUB_TOKEN", "secrets.CHANGELOG_UPDATE"],
"use_GH_action_semantic_version": "y",
"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"
".github/workflows/test_contribution.yaml",
".github/workflows/semantic_release.yaml"

]
}
12 changes: 10 additions & 2 deletions docs/source/prompts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,13 @@ project.
See `Issue 72 <https://github.com/imAsparky/cookiecutter-py3-package/issues/72>`_.



**create_auto_CHANGELOG**
*default = y*

create_auto_CHANGELOG will use GitHub actions to generate a changelog using
a cron job, scheduled daily.

**github_access_token**
**github_CHANGELOG_access_token**
*default = secrets.GITHUB_TOKEN*

For new or small repositories, select `secrets.GITHUB_TOKEN`.
Expand All @@ -136,6 +135,15 @@ project.
See `Encrypted Secrets <https://docs.github.com/en/actions/reference/encrypted-secrets>`_
for more information on generating secrets and repository security.

**use_GH_action_semantic-version**
*default = y*

A GitHub action workflow will check your git commit message's information,
update the semantic version, and publish assets to your package repository.

A GitHub PAT is required, and the repository secret is named `SEM_VER`
for this feature to work.

**open_source_license**
*default = MIT*

Expand Down
4 changes: 4 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ def remove_file(filepath):

if "{{ cookiecutter.create_repo_auto_test_workflow }}" != "y":
remove_file(".github/workflows/test_contribution.yaml")

if "{{ cookiecutter.use_GH_action_semantic_version }}" != "y":
remove_file(".github/workflows/semantic_release.yaml")
remove_file(".github/semantic.yaml")
2 changes: 1 addition & 1 deletion requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ alabaster==0.7.12
cookiecutter==1.4.0
furo==2021.8.11b42
myst-parser==0.15.2
semver==2.13.0
python-semantic-release==7.19.2
Sphinx==4.1.2
pre-commit==2.14.1
pytest==5.3.1
Expand Down
38 changes: 38 additions & 0 deletions tests/test_bake_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,41 @@ def test_bake_without_automatic_CHANGELOG(cookies):
f.basename for f in result.project.join(".github/workflows").listdir()
]
assert "update-changelog.yaml" not in auto_workflow_without_files


def test_bake_with_auto_semantic_version(cookies):
"""
Test cookiecutter created the package with auto semantic versioning.
"""
with bake_in_temp_dir(
cookies, extra_context={"use_GH_action_semantic_version": "y"}
) as result:

sem_ver_with_files = [
f.basename for f in result.project.join(".github").listdir()
]
assert "semantic.yaml" in sem_ver_with_files

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


def test_bake_without_auto_semantic_version(cookies):
"""
Test cookiecutter created the package without auto semantic versioning.
"""
with bake_in_temp_dir(
cookies, extra_context={"use_GH_action_semantic_version": "n"}
) as result:

sem_ver_without_files = [
f.basename for f in result.project.join(".github").listdir()
]
assert "semantic.yaml" not in sem_ver_without_files

sem_ver_workflow_without_files = [
f.basename for f in result.project.join(".github/workflows").listdir()
]
assert "semantic_release.yaml" not in sem_ver_workflow_without_files
32 changes: 32 additions & 0 deletions {{cookiecutter.project_slug}}/.github/semantic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Always validate the PR title AND all the commits
titleAndCommits: true

# A list of valid scopes
# scopes:
# - CHANGELOG
# - scope2

# Allow use of Merge commits (eg on github: "Merge branch 'master'
# into feature/ride-unicorns").
# this is only relevant when using commitsOnly: true (or titleAndCommits: true)
allowMergeCommits: true

# Allow use of Revert commits (eg on github: "Revert "feat: ride unicorns"")
# this is only relevant when using commitsOnly: true (or titleAndCommits: true)
allowRevertCommits: true

# By default types specified in commitizen/conventional-commit-types is used.
# See: https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json
# You can override the valid types
types:
- build
- chore
- ci
- docs
- feat
- fix
- perf
- refactor
- revert
- style
- test
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Semantic Release

on:
pull_request:
branches:
- main
types: [closed]

workflow_dispatch:

concurrency:
group: Semantic Release

jobs:
release:
if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.merged == true }}
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 }}
pypi_token: ${{ secrets.PYPI_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
# push:
# branches:
# - main

# Run workflow manually.
workflow_dispatch:

jobs:
Expand All @@ -22,9 +24,9 @@ jobs:
with:
REPO_NAME: "{{cookiecutter.github_username}}/\
{{cookiecutter.git_project_name}}"
ACCESS_TOKEN: ${{cookiecutter.github_access_token}}
ACCESS_TOKEN: ${{cookiecutter.github_CHANGELOG_access_token}}
PATH: "/CHANGELOG.md"
COMMIT_MESSAGE: "docs(CHANGELOG): update release notes:docs"
COMMIT_MESSAGE: "docs(CHANGELOG): update release notes"
TYPE: "chore:Chore,\
feat:Feature,\
fix:Bug Fixes,\
Expand Down
17 changes: 11 additions & 6 deletions {{cookiecutter.project_slug}}/requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
pip==19.2.3
bump2version==0.5.11
wheel==0.33.6
watchdog==0.9.0
cookiecutter==1.4.0
flake8==3.7.8
furo==2021.8.11b42
myst-parser==0.15.2
pre-commit==2.14.1
pytest==6.2.4
python-semantic-release==7.19.2
Sphinx==4.1.2
tox==3.14.0
coverage==4.5.4
Sphinx==1.8.5
twine==1.14.0
wheel==0.33.6
watchdog==0.9.0


{% if cookiecutter.command_line_interface|lower == 'click' -%}
Click==7.0{% endif %}
{% if cookiecutter.use_pytest == 'y' -%}
Expand Down