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

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

jobs:
end-to-end:
runs-on: ubuntu-latest
env:
GIT_AUTHOR_NAME: CI User
GIT_AUTHOR_EMAIL: ci@example.com
GIT_COMMITTER_NAME: CI User
GIT_COMMITTER_EMAIL: ci@example.com
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install cookiecutter
run: pip install cookiecutter
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.26"
cache: false
- name: Generate project
run: cookiecutter --no-input --verbose .
Comment thread
ankurs marked this conversation as resolved.
- name: Build
run: make build
working-directory: myapp
- name: Test
run: make test
working-directory: myapp
- name: Lint
run: make lint
working-directory: myapp
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.

14 changes: 7 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ You can contribute in many ways:

### Report Bugs

Report bugs at https://github.com/lacion/cookiecutter-golang/issues.
Report bugs at https://github.com/go-coldbrew/cookiecutter-coldbrew/issues.

If you are reporting a bug, please include:

Expand All @@ -28,13 +28,13 @@ is open to whoever wants to implement it.

### Write Documentation

cookiecutter-golang could always use more documentation, whether as part of the
official cookiecutter-golang docs, in docstrings, or even on the web in blog posts,
cookiecutter-coldbrew could always use more documentation, whether as part of the
official cookiecutter-coldbrew docs, in docstrings, or even on the web in blog posts,
articles, and such.

### Submit Feedback

The best way to send feedback is to file an issue at https://github.com/lacion/cookiecutter-golang/issues.
The best way to send feedback is to file an issue at https://github.com/go-coldbrew/cookiecutter-coldbrew/issues.

If you are proposing a feature:

Expand All @@ -45,12 +45,12 @@ If you are proposing a feature:

## Get Started!

Ready to contribute? Here's how to set up `cookiecutter-golang` for local development.
Ready to contribute? Here's how to set up `cookiecutter-coldbrew` for local development.

1. Fork the `cookiecutter-golang` repo on GitHub.
1. Fork the `cookiecutter-coldbrew` repo on GitHub.
2. Clone your fork locally::
```bash
$ git clone git@github.com:your_name_here/cookiecutter-golang.git
$ git clone git@github.com:your_name_here/cookiecutter-coldbrew.git
Comment thread
ankurs marked this conversation as resolved.
```

3. Create a branch for local development::
Expand Down
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.PHONY: install test test-e2e test-all

install:
pip install -r requirements.txt

test: install
pytest tests/ -v

test-e2e:
bash scripts/test-e2e.sh

test-all: test test-e2e
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
29 changes: 29 additions & 0 deletions scripts/test-e2e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -euxo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
TMPDIR="$(mktemp -d)"

cleanup() {
echo "Cleaning up $TMPDIR"
rm -rf "$TMPDIR"
}
trap cleanup EXIT

echo "=== Generating project in $TMPDIR ==="
cookiecutter --no-input --verbose --output-dir "$TMPDIR" "$REPO_DIR"
Comment thread
ankurs marked this conversation as resolved.

PROJECT_DIR="$TMPDIR/myapp"
cd "$PROJECT_DIR"

echo "=== make build ==="
make build

echo "=== make test ==="
make test

echo "=== make lint ==="
make lint

echo "=== All checks passed ==="
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