Skip to content

Commit

Permalink
bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
nieomylnieja committed Aug 2, 2024
1 parent 02ce352 commit 89a2ca6
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 299 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ linters-settings:
goimports:
# Put imports beginning with prefix after 3rd-party packages;
# it's a comma-separated list of prefixes.
local-prefixes: github.com/nobl9/your-module-name
local-prefixes: github.com/nobl9/govy
govet:
# False positives and reporting on error shadowing (which is intended).
# Quoting Robi Pike:
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
MAKEFLAGS += --silent --no-print-directory

BIN_DIR := ./bin
APP_NAME := your-module-name
APP_NAME := govy
LDFLAGS += -s -w

# renovate datasource=github-releases depName=securego/gosec
Expand Down Expand Up @@ -35,7 +35,7 @@ define _print_check_step
endef

.PHONY: build
## Build your-module-name binary.
## Build govy binary.
build:
go build -ldflags="$(LDFLAGS)" -o $(BIN_DIR)/$(APP_NAME) ./cmd

Expand Down Expand Up @@ -117,7 +117,7 @@ format/go:
echo "Formatting Go files..."
$(call _ensure_installed,binary,goimports)
go fmt ./...
$(BIN_DIR)/goimports -local=github.com/nobl9/your-module-name -w .
$(BIN_DIR)/goimports -local=github.com/nobl9/govy -w .

## Format cspell config file.
format/cspell:
Expand Down
114 changes: 2 additions & 112 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,113 +1,3 @@
# go-repo-template
# govy

Repository [template](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template)
for new Go projects.

## Bootstrap

Click `Use this template` button:
![image](https://github.com/nobl9/go-repo-template/assets/48822818/a5edc131-00c8-46f5-8ae6-1b593cbb4714)

After you're done, you can run the following command to bootstrap the project
and make it ready to run:

```shell
export MODULE_NAME=<YOUR_NAME> # Example: replace <YOUR_NAME> with "sloctl".
grep -rl your-module-name | xargs sed -i "s/your-module-name/$MODULE_NAME/g"
rm -rf bootstrap
rm gitsync.json
```

In order for some automations to work, like
[Release Drafter](https://github.com/release-drafter/release-drafter),
we need a predefined set of labels.
If you create a new repository from this template, the labels will be
automatically transferred for you.
However, if you want to use these automations in an existing repository,
you'll need to create these labels.
We've provided a convenience script for that, located [here](./bootstrap/add-labels.sh).
Run the following:

```shell
./bootstrap/add-labels.sh <you-existing-repo-name>
```

If you wish to update existing labels, add `--force` to the `gh label create`
invocation in the script.

## Project structure

The existing folders such as `cmd`, `pkg` and `internal` serve as examples on
how to structure your project.
You should remove them and change their contents to your liking, but adhere to
the structure defined
in [golang standards](https://github.com/golang-standards/project-layout).

## Makefile

Makefile is used as the utility
You can quickly inspect the targets of Makefile by running:

```shell
make help
```

When writing new targets, make sure you document them with double `#` character
and place the comment directly above the target, like so:

```makefile
## Document me!
new-target:
echo "Hello"
```

Want to include PlantUML diagrams in your project?
You can add these targets to Makefile:

```makefile
PLANTUML_JAR_URL := https://sourceforge.net/projects/plantuml/files/plantuml.jar/download
PLANTUML_JAR := $(BIN_DIR)/plantuml.jar
DIAGRAMS_PATH ?= .

## Generate PNG diagrams from PlantUML files.
generate/plantuml: $(PLANTUML_JAR)
for path in $$(find $(DIAGRAMS_PATH) -name "*.puml" -type f); do \
echo "Generating PNG file(s) for $$path"; \
java -jar $(PLANTUML_JAR) -tpng $$path; \
done

# If the plantuml.jar file isn't already present, download it.
$(PLANTUML_JAR):
echo "Downloading PlantUML JAR..."
curl -sSfL $(PLANTUML_JAR_URL) -o $(PLANTUML_JAR)
```

## Releasing

If you wish to ship binaries for your project, we recommend using [Goreleaser](https://goreleaser.com/).
Sloctl repository has some good examples on how to define Goreleaser
[config file](https://github.com/nobl9/sloctl/blob/main/.goreleaser.yml) and also,
how to use the tool in a [GitHub action](https://github.com/nobl9/sloctl/blob/main/.github/workflows/release.yml).

Sloctl also has examples of publishing Docker images to DockerHub.

## Gitsync

This repository is also used as a staple/root for other repositories to follow.
This means things like linter configs or CI/CD workflows in these repositories
are supposed to be kept in sync with this repository (with some variations).

This is achieved with a tool called [gitsync](https://github.com/nieomylnieja/gitsync).
Configuration file for the tool is [gitsync.json](./gitsync.json).

In order to see the diff between managed repositories run:

```shell
gitsync -c gitsync.json diff
```

In order to sync the changes for managed repositores run:

```shell
gitsync -c gitsync.json sync
```
TODO
23 changes: 0 additions & 23 deletions bootstrap/add-labels.sh

This file was deleted.

13 changes: 0 additions & 13 deletions bootstrap/labels.csv

This file was deleted.

29 changes: 0 additions & 29 deletions cmd/main.go

This file was deleted.

73 changes: 0 additions & 73 deletions gitsync.json

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/nobl9/your-module-name
module github.com/nobl9/govy

go 1.22
20 changes: 0 additions & 20 deletions internal/internal.go

This file was deleted.

24 changes: 0 additions & 24 deletions pkg/pkg.go

This file was deleted.

0 comments on commit 89a2ca6

Please sign in to comment.