Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
25 changes: 25 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Test

on:
push:
branches: ["main", "master"]
pull_request:
branches: ["main", "master"]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run tests
run: pytest tests/ -v
21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"project_short_description": "{{cookiecutter.name}} is a Golang project.",
"docker_image": "alpine:latest",
"docker_build_image": "golang",
"docker_build_image_version": ["1.25", "1.24"],
"docker_build_image_version": ["1.26", "1.25"],
"_copy_without_render": [
"third_party/OpenAPI/swagger-ui*",
"third_party/*js.map",
Expand Down
25 changes: 15 additions & 10 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,25 @@ def init_git():

def init_proto():
print("Starting proto initialization...")
print("Step 1/5: Fetching Go modules (this might take a few minutes)...")
print("Step 1/4: Fetching Go modules (this might take a few minutes)...")
code = Popen(["go", "mod", "download", "all"], cwd=PROJECT_DIRECTORY).wait()
if code != 0:
print("Error: Failed to fetch Go modules.")
sys.exit(code)

print("Step 2/5: Running 'make install'...")
code = Popen(["make", "install"], cwd=PROJECT_DIRECTORY).wait()
if code != 0:
print("Error: 'make install' failed.")
sys.exit(code)

print("Step 3/5: Running 'make generate'...")
print("Step 2/4: Running 'make generate'...")
code = Popen(["make", "generate"], cwd=PROJECT_DIRECTORY).wait()
if code != 0:
print("Error: 'make generate' failed.")
sys.exit(code)

print("Step 4/5: Tidying Go modules...")
print("Step 3/4: Tidying Go modules...")
code = Popen(["go", "mod", "tidy"], cwd=PROJECT_DIRECTORY).wait()
if code != 0:
print("Error: 'go mod tidy' failed.")
sys.exit(code)

print("Step 5/5: Running 'make mock'...")
print("Step 4/4: Running 'make mock'...")
code = Popen(["make", "mock"], cwd=PROJECT_DIRECTORY).wait()
if code != 0:
print("Error: 'make mock' failed.")
Expand All @@ -79,5 +73,16 @@ def remove_docker_files():
PROJECT_DIRECTORY, filename
))

def setup_local_env():
"""
Copies local.env.example to local.env for local development
"""
import shutil
example = os.path.join(PROJECT_DIRECTORY, "local.env.example")
local = os.path.join(PROJECT_DIRECTORY, "local.env")
if os.path.exists(example) and not os.path.exists(local):
shutil.copy2(example, local)

init_proto()
setup_local_env()
init_git()
12 changes: 5 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
cookiecutter==2.1.1
cookiecutter>=2.6.0

# Testing
pytest==3.0.5
tox==2.5.0
sh==1.12.8
pytest-cookies==0.2.0
binaryornot==0.4.0
tox==2.5.0
pytest>=8.0.0
tox>=4.0.0
pytest-cookies>=0.7.0
binaryornot>=0.4.4
54 changes: 54 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
from pathlib import Path

import pytest
from cookiecutter.main import cookiecutter


@pytest.fixture
def template_dir():
"""Path to the cookiecutter template root."""
return str(Path(__file__).parent.parent.resolve())


@pytest.fixture
def default_context():
"""Default context for baking the template."""
return {
"source_path": "github.com/testorg",
"name": "TestService",
"app_name": "testservice",
"grpc_package": "com.github.testorg",
"service_name": "TestSvc",
"project_short_description": "A test service.",
"docker_image": "alpine:latest",
"docker_build_image": "golang",
"docker_build_image_version": "1.26",
}


@pytest.fixture
def bake_project(tmp_path, template_dir, default_context):
"""Factory fixture that bakes a project without running hooks.

Returns a function that accepts optional context overrides and
returns a pathlib.Path to the generated project directory.
"""
def _bake(extra_context=None, full_context=None):
if full_context is not None:
ctx = full_context
else:
ctx = {**default_context}
if extra_context:
ctx.update(extra_context)

project_dir = cookiecutter(
template_dir,
output_dir=str(tmp_path),
no_input=True,
extra_context=ctx,
accept_hooks=False,
)
return Path(project_dir)

return _bake
Loading
Loading