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: introduce Cookiecutter #13

Merged
merged 10 commits into from
Aug 13, 2024
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
48 changes: 18 additions & 30 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,21 @@ on:
jobs:
example-cxx:
runs-on: ubuntu-latest
env:
CXX_PROJECT_NAME: example-cxx
steps:
- uses: actions/checkout@v4
- name: Setup CookieCutter
run: pipx install cookiecutter

- name: Generate cxx example from template/cxx
uses: cargo-generate/[email protected]
with:
name: ${{ env.CXX_PROJECT_NAME }}
template: template/cxx
arguments: "--template-values-file .github/workflows/template_values.toml --verbose"
- name: Generate cxx example
run: cookiecutter --no-input --config-file .github/workflows/template_inputs_cxx.yml ./template/cxx

- name: Deploy
uses: peaceiris/actions-gh-pages@v4
with:
deploy_key: ${{ secrets.GH_EXAMPLE_DEPLOY_SECRET }}
external_repository: x-pt/${{ env.CXX_PROJECT_NAME }}
external_repository: x-pt/example-cxx
publish_branch: main
publish_dir: ./${{ env.CXX_PROJECT_NAME }}
publish_dir: ./my-awesome-cxx-project
# Set exclude_assets to empty for including the .github directory to deployment assets.
exclude_assets: ''
enable_jekyll: true
Expand All @@ -34,25 +30,21 @@ jobs:
force_orphan: true
example-go:
runs-on: ubuntu-latest
env:
GO_PROJECT_NAME: example-go
steps:
- uses: actions/checkout@v4
- name: Setup CookieCutter
run: pipx install cookiecutter

- name: Generate go example from template/go
uses: cargo-generate/[email protected]
with:
name: ${{ env.GO_PROJECT_NAME }}
template: template/go
arguments: "--template-values-file .github/workflows/template_values.toml --verbose"
- name: Generate go example
run: cookiecutter --no-input --config-file .github/workflows/template_inputs_go.yml ./template/go

- name: Deploy
uses: peaceiris/actions-gh-pages@v4
with:
deploy_key: ${{ secrets.GH_EXAMPLE_DEPLOY_SECRET }}
external_repository: x-pt/${{ env.GO_PROJECT_NAME }}
external_repository: x-pt/example-go
publish_branch: main
publish_dir: ./${{ env.GO_PROJECT_NAME }}
publish_dir: ./my-awesome-go-project
# Set exclude_assets to empty for including the .github directory to deployment assets.
exclude_assets: ''
enable_jekyll: true
Expand All @@ -62,25 +54,21 @@ jobs:
force_orphan: true
example-py:
runs-on: ubuntu-latest
env:
PY_PROJECT_NAME: example-py
steps:
- uses: actions/checkout@v4
- name: Setup CookieCutter
run: pipx install cookiecutter

- name: Generate python example from template/py
uses: cargo-generate/[email protected]
with:
name: ${{ env.PY_PROJECT_NAME }}
template: template/py
arguments: "--template-values-file .github/workflows/template_values.toml --verbose"
- name: Generate py example
run: cookiecutter --no-input --config-file .github/workflows/template_inputs_py.yml ./template/py

- name: Deploy
uses: peaceiris/actions-gh-pages@v4
with:
deploy_key: ${{ secrets.GH_EXAMPLE_DEPLOY_SECRET }}
external_repository: x-pt/${{ env.PY_PROJECT_NAME }}
external_repository: x-pt/example-py
publish_branch: main
publish_dir: ./${{ env.PY_PROJECT_NAME }}
publish_dir: ./my-awesome-python-project
# Set exclude_assets to empty for including the .github directory to deployment assets.
exclude_assets: ''
enable_jekyll: true
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/template_inputs_cxx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
default_context:
full_name: X Author Name
email: [email protected]
github_username: x-pt
project_name: My Awesome Cxx Project
project_slug: my-awesome-cxx-project
package_name: my_awesome_cxx_project
project_desc: A nice example project

# C++
cxx_cmake_version: 3.28
cxx_standard_version: 20
cxx_standard_required: true
cxx_extensions_required: false
cxx_project_type: [ "binary", "library" ]
cxx_share_enabled: false
11 changes: 11 additions & 0 deletions .github/workflows/template_inputs_go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
default_context:
full_name: X Author Name
email: [email protected]
github_username: x-pt
project_name: My Awesome Go Project
project_slug: my-awesome-go-project
package_name: my_awesome_go_project
project_desc: A nice example project

# Go
go_version: 1.22
11 changes: 11 additions & 0 deletions .github/workflows/template_inputs_py.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
default_context:
full_name: X Author Name
email: [email protected]
github_username: x-pt
project_name: My Awesome Python Project
project_slug: my-awesome-python-project
package_name: my_awesome_python_project
project_desc: A nice example project

# Python
python_version: 3.11
20 changes: 0 additions & 20 deletions .github/workflows/template_values.toml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# X Project Template

A template for [cargo generate](https://github.com/cargo-generate/cargo-generate)
A template using [CookieCutter](https://github.com/cookiecutter/cookiecutter)
that aims to be a starting point suitable for
the vast majority of startup projects that will be hosted on GitHub.

Expand Down
19 changes: 19 additions & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"templates": {
"cxx": {
"path": "./template/cxx",
"title": "C++ Project",
"description": "A cookiecutter template for a cxx project"
},
"go": {
"path": "./template/go",
"title": "Go Project",
"description": "A cookiecutter template for a go project"
},
"python": {
"path": "./template/py",
"title": "Python Project",
"description": "A cookiecutter template for a python project"
}
}
}
41 changes: 0 additions & 41 deletions template/cxx/CMakeLists.txt

This file was deleted.

57 changes: 0 additions & 57 deletions template/cxx/cargo-generate.toml

This file was deleted.

29 changes: 29 additions & 0 deletions template/cxx/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"project_name": "My Awesome Project",
"project_slug": "{{ cookiecutter.project_name | slugify }}",
"package_name": "{{ cookiecutter.project_slug | replace('-', '_') }}",
"project_desc": "A nice cxx project",
"full_name": "Firstname Lastname",
"email": "[email protected]",
"github_username": "your-org-or-username",


"cxx_cmake_version": "3.28",
"cxx_standard_version": "20",
"cxx_standard_required": true,
"cxx_extensions_required": false,
"cxx_project_type": ["binary", "library"],
"cxx_share_enabled": false,


"__gh_slug": "{{ cookiecutter.github_username }}/{{ cookiecutter.project_slug }}",
"__prompts__": {
"project_name": "Enter your project name",
"project_slug": "Generated project identifier (slug)",
"package_name": "Generated package/module name",
"project_desc": "Brief project description",
"github_username": "GitHub username or organization",
"full_name": "Author's full name",
"email": "Author's email address"
}
}
6 changes: 0 additions & 6 deletions template/cxx/src/library.h

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Steps to reproduce the behavior:
<!-- Please fill the following information. -->

- OS: [e.g. Ubuntu 20.04]
- {{project-name}} version: [e.g. 0.1.0]
- {{cookiecutter.project_slug}} version: [e.g. 0.1.0]

## Additional context

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!--
Please make sure:
- you have read the contributing guidelines:
https://github.com/{{gh_uname}}/{{project-name}}/blob/main/docs/CONTRIBUTING.md
https://github.com/{{cookiecutter.__gh_slug}}/blob/main/docs/CONTRIBUTING.md
- you have updated the changelog (if needed):
https://github.com/{{gh_uname}}/{{project-name}}/blob/main/CHANGELOG.md
https://github.com/{{cookiecutter.__gh_slug}}/blob/main/CHANGELOG.md
-->
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@ jobs:
password: {{ "${{ secrets.GITHUB_TOKEN }}" }}
-
name: Build and Export to Docker
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: .
load: true
tags: |
ghcr.io/{{gh_uname}}/{{project-name}}:latest
ghcr.io/{{gh_uname}}/{{project-name}}:${GITHUB_REF_NAME:1}
ghcr.io/{{cookiecutter.__gh_slug}}:latest
ghcr.io/{{cookiecutter.__gh_slug}}:${GITHUB_REF_NAME:1}
-
name: Test it before Push
run: |
docker run --rm ghcr.io/{{gh_uname}}/{{project-name}}:latest
docker run --rm ghcr.io/{{gh_uname}}/{{project-name}}:${GITHUB_REF_NAME:1}
docker run --rm ghcr.io/{{cookiecutter.__gh_slug}}:latest
docker run --rm ghcr.io/{{cookiecutter.__gh_slug}}:${GITHUB_REF_NAME:1}
-
name: Build and Push
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/{{gh_uname}}/{{project-name}}:latest
ghcr.io/{{gh_uname}}/{{project-name}}:${GITHUB_REF_NAME:1}
ghcr.io/{{cookiecutter.__gh_slug}}:latest
ghcr.io/{{cookiecutter.__gh_slug}}:${GITHUB_REF_NAME:1}
File renamed without changes.
File renamed without changes.
Loading