Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-auto-release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ci-dev-release-auto
name: ci-auto-release

on:
push:
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/ci-tagged-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: ci-tagged-release
on:
push:
tags:
- "v*"
- "v*.*.*"

jobs:
tagged-release:
Expand All @@ -14,7 +14,11 @@ jobs:

steps:

- uses: marvinpinto/action-automatic-releases@latest
- name: Release
uses: softprops/action-gh-release@v1
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
prerelease: false
generate_release_notes: true
files: |
${{ github.workspace }}/CHANGELOG.md
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### Added

- Action for auto releases in pushes to master. Release tag is set to 'latest' automatically.
- Template action for python's tagged release.
- Template action for python's auto release.

### Changed

-
- Interface and variable selection.

### Fixed

Expand Down
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,24 @@ you will be prompted to fill in the following values:
folder.
- **add_PR_template:** this flags controls wether or not to add a PR template in the generated
folder.
- **project_language:** This variable choice serves to select the main project language, and it is
aligned with the actions that will be later opt to be created.
- **add_ci_action_unit_tests_runner:** this variable controls whether or not to create an action to
run unit tests in the repository. The available actions (per project_language variable) are:
- **add_ci_action_unit_tests:** this variable controls whether or not to create an action to
run unit tests in the repository. The available actions are:
- cpp, which creates an action for Catch2 based unit tests, built using CMake.
- python, which creates an action for Python code unit tests, executed with pytest over a
project built with Poetry.
- other, which does not generate any action.
- none, which does not generate any action.
- **add_ci_action_auto_release:** this variable controls whether or not to create an action to
generate dev releases (pre-releases, tagged with "latest" tag), triggered on pushes to master
branch. The available actions are:
- python, which creates an action for Python releases, building assets after pytest test
execution in a project built with Poetry.
- none, which does not generate any action.
- **add_ci_action_tagged_release:** this variable controls whether or not to create an action to
generate tagged releases (releases, semver tagged), triggered on "v*.*.*" tags pushed. The
available actions are:
- python, which creates an action for Python releases, building assets after pytest test
execution in a project built with Poetry.
- none, which does not generate any action.

**NOTE:** Each added action will be accompanied of a markdown checklist, stating the changes /
configuration required to fine tune it.
Expand Down
14 changes: 9 additions & 5 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
true,
false
],
"project_language": [
"add_ci_action_unit_tests": [
"python",
"cpp",
"none"
],
"add_ci_auto_release": [
"python",
"other"
"none"
],
"add_ci_action_unit_tests_runner": [
true,
false
"add_ci_tagged_release": [
"python",
"none"
],
"__github_folder": ".github"
}
107 changes: 76 additions & 31 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@

class color:
"""Simple colors for print without external libraries."""
PURPLE = '\033[95m'
CYAN = '\033[96m'
DARK_CYAN = '\033[36m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
END = '\033[0m'

PURPLE = "\033[95m"
CYAN = "\033[96m"
DARK_CYAN = "\033[36m"
BLUE = "\033[94m"
GREEN = "\033[92m"
YELLOW = "\033[93m"
RED = "\033[91m"
BOLD = "\033[1m"
UNDERLINE = "\033[4m"
END = "\033[0m"


def change_line_endings_crlf_to_lf():
Expand All @@ -28,44 +29,87 @@ def change_line_endings_crlf_to_lf():


def remove_unwanted_templates():

if not {{ cookiecutter.add_issue_templates }}:
if not {{cookiecutter.add_issue_templates}}:
LOG.info("Skipping issue templates files generation ...")
path = Path("./ISSUE_TEMPLATE")
rmtree(path)

if not {{ cookiecutter.add_PR_template }}:
if not {{cookiecutter.add_PR_template}}:
LOG.info("Skipping PR templates file generation ...")
path = Path("./pull_request_template.md")
path.unlink()


def add_ci_action_unit_tests_runner():
def add_ci_action_unit_tests():
"""Adds a CI action for running unit tests, if applicable"""

target_language = "{{cookiecutter.project_language}}"
target_language = "{{cookiecutter.add_ci_action_unit_tests}}"

if target_language.lower() != "none":
LOG.info(
"Adding action for running unit tests (workflows folder) with default config..."
)

if {{cookiecutter.add_ci_action_unit_tests_runner}}:
destination = Path("workflows")
ci_test_workflow_files_path = Path("_", "workflows", "ci-unit", target_language)
copytree(ci_test_workflow_files_path, destination, dirs_exist_ok=True)

if target_language.lower() != "other":
print("\n\n######################################################################")
print("# #")
print(f"# {color.BOLD}{color.BLUE}Please review gen. checklist in order to adjust CI UT basic action{color.END} #")
print("# #")
print("######################################################################\n\n")

LOG.info("Adding action for running unit tests (workflows folder) with default config...")
else:
LOG.info("Skipping CI action for running unit tests file generation")

destination = Path("workflows")
ci_test_workflow_files_path = Path("_", "workflows", target_language)
copytree(ci_test_workflow_files_path, destination)

print("\n\n######################################################################")
print("# #")
print(f"# {color.BOLD}{color.BLUE}Please review gen. checklist in order to adjust CI UT basic action{color.END} #")
print("# #")
print("######################################################################\n\n")
def add_ci_action_auto_release():
"""Adds a CI action for generating auto releases, if applicable"""

else:
LOG.info("CI action for running unit tests file generation is not defined for %s language. Skipping...", target_language)
target_language = "{{cookiecutter.add_ci_auto_release}}"

if target_language.lower() != "none":
LOG.info(
"Adding action for running auto releases (workflows folder) with default config..."
)

destination = Path("workflows")
ci_auto_release_workflow_files_path = Path("_", "workflows", "ci-auto-release", target_language)
copytree(ci_auto_release_workflow_files_path, destination, dirs_exist_ok=True)

print("\n\n################################################################################")
print("# #")
print(f"# {color.BOLD}{color.BLUE}Please review gen. checklist in order to adjust CI auto release basic action{color.END} #")
print("# #")
print("################################################################################\n\n")

else:
LOG.info("Skipping CI action for running unit tests file generation")
LOG.info("Skipping CI action for generating auto releases file generation")


def add_ci_action_tagged_release():
"""Adds a CI action for generating auto releases, if applicable"""

target_language = "{{cookiecutter.add_ci_auto_release}}"

if target_language.lower() != "none":
LOG.info(
"Adding action for running tagged releases (workflows folder) with default config..."
)

destination = Path("workflows")
ci_tagged_release_workflow_files_path = Path("_", "workflows", "ci-tagged-release", target_language)
copytree(ci_tagged_release_workflow_files_path, destination, dirs_exist_ok=True)

print("\n\n###################################################################################")
print("# #")
print(f"# {color.BOLD}{color.BLUE}Please review gen. checklist in order to adjust CI tagged basic action{color.END} #")
print("# #")
print("###################################################################################\n\n")

else:
LOG.info("Skipping CI action for generating tagged releases file generation")


def clean():
Expand All @@ -75,10 +119,11 @@ def clean():


if __name__ == "__main__":

logging.basicConfig(level=logging.DEBUG, format="%(message)s")
LOG = logging.getLogger("post_gen_project")
remove_unwanted_templates()
add_ci_action_unit_tests_runner()
add_ci_action_unit_tests()
add_ci_action_auto_release()
add_ci_action_tagged_release()
clean()
change_line_endings_crlf_to_lf()
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: ci-auto-release-python

on:
push:
branches:
- master

env:
##############################################################################
# Please fill in:
# Ref. https://docs.github.com/en/github-ae@latest/actions/learn-github-actions/variables
##############################################################################
# Target python version intended to use to run tests into. Defaults to 3.10.2
##############################################################################
TARGET_PYTHON_VERSION: 3.10.2
##############################################################################
##############################################################################
# Target folder where tests reside. Defaults to "tests"
##############################################################################
TESTS_DIRECTORY: tests
##############################################################################
##############################################################################
# Please fill in with the Runner(s) in which to execute this action
# Ref. https://docs.github.com/en/actions/hosting-your-own-runners/using-self-hosted-runners-in-a-workflow
# Ref. https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners
############################################################################
RUNNER: ubuntu-20.04
############################################################################


jobs:

pre-release:

name: Pre-Release
runs-on: {{ '${{ env.RUNNER }}' }}

############################################################################
# Minimum permissions required by EnricoMi/publish-unit-test-result-action@v2
# Ref. https://github.com/EnricoMi/publish-unit-test-result-action#support-fork-repositories-and-dependabot-branches
############################################################################
permissions:
contents: write # For tags
issues: read
checks: write
pull-requests: write

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: {{ '${{ env.TARGET_PYTHON_VERSION }}' }}

- name: Install poetry
run: |
python -m pip install pipx && python -m pipx install poetry

- name: Configure poetry
run: |
poetry config virtualenvs.in-project true

- name: Cache the virtualenv
uses: actions/cache@v3
with:
path: ./.venv
key: {{ '${{ runner.os }}' }}-venv-{{ '${{ hashFiles(\'**/poetry.lock\') }}' }}

- name: Run tests
run: |
poetry run python -m pytest {{ '${{ env.TESTS_DIRECTORY }}' }} --doctest-modules --junit-xml=junit/ci-result-junit.xml

- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: success()
with:
files: junit/ci-result-junit.xml
action_fail: true
action_fail_on_inconclusive: true

- name: Package application
run: |
rm -rf dist
poetry build

- name: Delete latest tag
uses: cb80/delrel@latest
with:
tag: latest

- name: do-Prerelease
uses: softprops/action-gh-release@v1
with:
token: {{ '${{ secrets.GITHUB_TOKEN }}' }}
tag_name: latest
prerelease: true
name: Pre-release (dev build)
generate_release_notes: true
files: |
{{ '${{ github.workspace }}' }}/CHANGELOG.md
{{ '${{ github.workspace }}' }}/dist/*
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Auto Release GH Action configuration checklist (python)

Be sure to properly fine-tune the generated action (ci-auto-release-python.yml) before committing
it to the remote repository.

## Checklist

- [ ] The intended branch and triggers are correct (default: *on push to master*).
- [ ] The target python version has been configured (defaults to *3.10.2*).
- [ ] The target test directory where tests live has been defined (defaults to *tests*).
- [ ] The target runner(s) in which to run the CI Unit Testing workflow have been configured
(defaults to *ubuntu-20.04*, hosted by GH).
Loading