Skip to content

Commit

Permalink
Merge pull request #52 from notsatan/feature/private-repo
Browse files Browse the repository at this point in the history
Primarly focuses around ensuring private repositories can be generated
via `go-template`, also includes some less-related, tangential changes

Signed-off-by: notsatan <git@notsatan.me>
  • Loading branch information
notsatan committed Jan 5, 2024
2 parents cb51ccf + 711dfab commit 2620736
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 26 deletions.
48 changes: 29 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

![A gif displaying `go-template` in action][demo-gif]

[![Build status](https://img.shields.io/github/workflow/status/notsatan/go-template/Black?style=for-the-badge&logo=github)][black-action]
[![Build status](https://img.shields.io/github/actions/workflow/status/notsatan/go-template/black.yml?style=for-the-badge&logo=github)][black-action]
[![No Dependencies](https://img.shields.io/badge/Dependencies-None-green?style=for-the-badge&logo=dependabot)][gomod-file]
[![MIT License](https://img.shields.io/github/license/notsatan/go-template?color=red&style=for-the-badge)][project-license]
[![Pre-Commit Enabled](https://img.shields.io/badge/Pre--Commit-Enabled-blue?style=for-the-badge&logo=pre-commit)][project-precommit]
[![Go v1.16+](https://img.shields.io/badge/Go-%20v1.16-black?style=for-the-badge&logo=go)][go-releases]
[![Go v1.19+](https://img.shields.io/badge/Go-%20v1.19+-black?style=for-the-badge&logo=go)][go-releases]
[![Makefile Included](https://img.shields.io/badge/Makefile-Supported%20🚀-red?style=for-the-badge&logo=probot)][makefile-file]

A bleeding-edge Go project generator for your next project :wink:
Expand All @@ -32,12 +32,12 @@ directly for quick setup instructions ;)

## :boom: Features

This is a battries-included [cookiecutter :cookie:][cookiecutter-link] template to get
This is a batteries-included [cookiecutter :cookie:][cookiecutter-link] template to get
you started with the essentials you'll need for your next Go project ;)

### Development

- Supports Go `v1.16`, `v1.17` and `v1.18`
- Supports Go `v1.19`, `v1.20` and `v1.21`
- Automated code formatting with [gofmt][gofmt-link] and [gofumpt][gofumpt-link]
- Sort imports with [goimports][goimports-link] and [gci][gci-link]
- Ready to use [pre-commit][precommit-link] setup, complete with a ton of hooks
Expand Down Expand Up @@ -120,19 +120,20 @@ values, and what they are used for
> These defaults **must** be filled with actual values during the setup!
<br>
| Parameter | Default Value | Usage |
|----------------------------|-------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `project_name` | `example-project` | Name of the project. A directory of this name will be created in the current working directory |
| `project_description` | Based on `project_name` | A small description of the project, used to generate `GNU` license file, and default readme |
| `go_module_path` | Based on `project_name` | Complete Go module path for the generated project, use a valid Github URL to enable Github specific features |
| `license_owner` | example | Used in `LICENSE` and other files. Can be the name of a person or an organization. |
| `base_branch` | `master` | The stable/base branch. Used for build status badges and release-drafter (if you enable Github specific features) |
| `contact_email` | `""` | Email to get in touch with project stakeholders. `CODE_OF_CONDUCT.md` and `SECURITY.md` will be removed if empty. [Why is this needed?](#why-is-my-email-id-needed) |
| `github_specific_features` | **y** | Yes or No (`y` or `n`). Dictates if Github-specific features should be included in the project (issue templates, pipeline, etc). [More Info](#what-does-the-github_specific_features-field-do) |
| `use_codecov` | **y** | Yes or No (`y` or `n`). Decides if [Codecov](http://codecov.com) is to be used in the project or not. Checkout [Setting up codecov](#how-to-integrate-codecov-for-automated-code-analysis) |
| `use_precommit` | **y** | Yes or No (`y` or `n`). Decides if [*pre-commit*](https://pre-commit.com) configs should be included with the generated templates |
| `go_version` | `1.17` | The version of Go to use in the project. Can be either `1.16`, `1.17` or `1.18` |
| `license` | `MIT` | The license you want to use in the generated project. One of `MIT`, `BSD-3`, `GNU GPL v3.0` and `Apache Software License 2.0` |
| Parameter | Default Value | Usage |
|----------------------------|-------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `project_name` | `example-project` | Name of the project. A directory of this name will be created in the current working directory |
| `project_description` | Based on `project_name` | A small description of the project, used to generate `GNU` license file, and default readme |
| `go_module_path` | Based on `project_name` | Complete Go module path for the generated project, use a valid Github URL to enable Github specific features |
| `license_owner` | example | Used in `LICENSE` and other files. Can be the name of a person or an organization. |
| `base_branch` | `master` | The stable/base branch. Used for build status badges and release-drafter (if you enable Github specific features) |
| `contact_email` | `""` | Email to get in touch with project stakeholders. `CODE_OF_CONDUCT.md` and `SECURITY.md` will be removed if empty. [Why is this needed?](#why-is-my-email-id-needed) |
| `github_specific_features` | **y** | Yes or No (`y` or `n`). Dictates if Github-specific features should be included in the project (issue templates, pipeline, etc). [More Info](#what-does-the-github_specific_features-field-do) |
| `private_project` | **n** | Yes or No (`y` or `n`). Inquires if the project repository generated will be publicly accessible, or private. [Why is this needed?](#why-do-i-need-to-inform-if-the-generated-project-will-be-public) |
| `use_codecov` | **y** | Yes or No (`y` or `n`). Decides if [Codecov](http://codecov.com) is to be used in the project or not. Checkout [Setting up codecov](#how-to-integrate-codecov-for-automated-code-analysis) |
| `use_precommit` | **y** | Yes or No (`y` or `n`). Decides if [*pre-commit*](https://pre-commit.com) configs should be included with the generated templates |
| `go_version` | `1.17` | The version of Go to use in the project. Can be either `1.16`, `1.17` or `1.18` |
| `license` | `MIT` | The license you want to use in the generated project. One of `MIT`, `BSD-3`, `GNU GPL v3.0` and `Apache Software License 2.0` |

All values entered while setting up the Cookiecutter template will be saved in
`cookiecutter-config-file.yml`, you can refer to them in the generated project :wink:
Expand Down Expand Up @@ -225,6 +226,15 @@ can use this field to ensure the generated project is free of Github-specific fi
> should be a path to a Github repository (does not matter if it exists). This would be
> used for `dependabot.yml`
#### Why do I need to inform if the generated project will be public?

As of now, the only change(s) being made based on this are all restricted to the README
file of generated projects. This is required as some badges used in the README require
the project to be accessible by `shields.io` — the service behind these badges!

For private projects, these badges will either be removed or modified, to prevent cases
where badges break down for private repositories!

#### How to integrate Codecov for automated code analysis?

[Codecov][codecov-link] is a code analysis tool, `go-template` can generate a project
Expand Down Expand Up @@ -296,9 +306,9 @@ you start working (especially if you're picking up one of these tasks);
- [ ] Add [Earthly][earthly-link]? Not sure if this is needed in the first place.
- [ ] Customize [build-script.sh][build-script-file] to generate binaries/executables
for selective OSes
- [ ] Option to generate private projects - Shield badges and *<more stuff>* need the
- [x] ~~Option to generate private projects~~ - Shield badges and *<more stuff>* need the
project to be public. It would be great to have an option to generate private
projects using *go-template*!
projects using *go-template*! (Accomplished via notsatan/go-template#52)

## :trophy: Acknowledgements

Expand Down
1 change: 1 addition & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"base_branch": "master",
"contact_email": "",
"github_specific_features": "y",
"private_project": "n",
"use_codecov": "y",
"use_precommit": "y",
"go_version": [
Expand Down
4 changes: 2 additions & 2 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
]


def lincese_generator():
def license_generator():
"""
Generates the appropriate license for the template from the given options
"""
Expand Down Expand Up @@ -177,7 +177,7 @@ def print_final_instructions():


runners: Callable[[Optional[Any]], None] = [
lincese_generator,
license_generator,
create_temp_directories,
remove_codecov,
disable_github_features,
Expand Down
4 changes: 0 additions & 4 deletions {{ cookiecutter.project_name.strip() }}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ PROJECTNAME="{{ cookiecutter.project_name.strip() }}"
# List of all Go-files to be processed
GOFILES=$(wildcard *.go)

# Redirecting error output to a file, acts as logs that can
# be referenced if needed
STDERR=/tmp/$(PROJECTNAME)-stderr.txt

# Docker image variables
IMAGE := $(PROJECTNAME)
VERSION := latest
Expand Down
8 changes: 7 additions & 1 deletion {{ cookiecutter.project_name.strip() }}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
{% if cookiecutter.github_specific_features.lower() == 'y' -%}
<div align="center">

{% if cookiecutter.private_project.lower() == "n" -%}
[![Build Status](https://img.shields.io/github/checks-status/{{ cookiecutter.go_module_path.strip('/').replace('github.com/', '') }}/{{ cookiecutter.base_branch.strip() }}?color=black&style=for-the-badge&logo=github)][github-actions]
{% endif -%}
{% if cookiecutter.use_codecov.lower() == 'y' -%}
[![Code Coverage](https://img.shields.io/codecov/c/{{ cookiecutter.go_module_path.strip('/').replace('.com', '') }}?color=blue&logo=codecov&style=for-the-badge)][github-actions-tests]
{% endif -%}
[![Security: GoSec](https://img.shields.io/badge/Security-GoSec-lightgrey?style=for-the-badge&logo=springsecurity)](https://github.com/securego/gosec)
[![Dependencies Status](https://img.shields.io/badge/Dependencies-Up%20to%20Date-brightgreen?style=for-the-badge&logo=dependabot)][dependabot-pulls]
[![Semantic Versioning](https://img.shields.io/badge/versioning-semantic-black?style=for-the-badge&logo=semver)][github-releases]
[![Pre-Commit Enabled](https://img.shields.io/badge/Pre--Commit-Enabled-blue?style=for-the-badge&logo=pre-commit)][precommit-config]
[![License](https://img.shields.io/github/license/{{ cookiecutter.go_module_path.strip('/').replace('github.com/', '') }}?color=red&style=for-the-badge)][project-license]
{% if cookiecutter.private_project.lower() == "n" -%}
[![License](https://img.shields.io/github/license/{{ cookiecutter.go_module_path.strip('/').replace('github.com/', '') }}?color=red&style=for-the-badge&logo=unlicense)][project-license]
{% else -%}
[![License](https://img.shields.io/badge/License-{{ cookiecutter.license.replace('-', '--').replace('Software License ', '').replace(' ', '%20') }}-lightgrey?color=red&style=for-the-badge&logo=unlicense)][project-license]
{% endif -%}
[![Go v{{ cookiecutter.go_version }}](https://img.shields.io/badge/Go-%20v{{ cookiecutter.go_version }}-black?style=for-the-badge&logo=go)][gomod-file]

{{ cookiecutter.project_description }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cookiecutter_inputs:
contact_email: "{{ cookiecutter.contact_email }}"
project_description: "{{ cookiecutter.project_description }}"
github_specific_features: "{{ cookiecutter.github_specific_features }}"
private_project: "{{ cookiecutter.private_project }}"
use_codecov: "{{ cookiecutter.use_codecov }}"
use_precommit: "{{ cookiecutter.use_precommit }}"
go_version: "{{ cookiecutter.go_version }}"
Expand Down

0 comments on commit 2620736

Please sign in to comment.