Skip to content

Commit 14fe918

Browse files
Merge pull request #30 from rog-golang-buddies/gen-docs
Add mkdocs-material docs gen and include CI docs (review)
2 parents ac9a3f5 + e9f756f commit 14fe918

File tree

12 files changed

+403
-0
lines changed

12 files changed

+403
-0
lines changed

.github/workflows/mkdocs.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: gen-docs
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- main
7+
jobs:
8+
deploy:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: actions/setup-python@v2
13+
with:
14+
python-version: 3.x
15+
- run: pip install mkdocs-material
16+
- run: mkdocs gh-deploy --force

docs/.DS_Store

6 KB
Binary file not shown.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# gitleaks
2+
3+
## What
4+
5+
[gitleaks](https://github.com/zricethezav/gitleak) is a SAST tool for detecting and preventing hardcoded secrets like passwords, api keys, and tokens in git repos. Gitleaks is an easy-to-use, all-in-one solution for detecting secrets, past or present, in your code.
6+
7+
## Why
8+
9+
Raise security incidents early by detecting secret leaks and raising Github security code scanning alerts.
10+
11+
## How
12+
13+
The mechanism to detect secrets and protect (undo commit with a secret) is described [here](https://github.com/zricethezav/gitleaks#commands).
14+
15+
## CI setup
16+
17+
!!! summary
18+
19+
No configuration required.
20+
21+
22+
A `gitleaks detect` command is run via a gitleaks Github workflow in `.github/workflows/gitleaks.yml`.
23+
24+
!!! info
25+
26+
The [gitleaks Github action](https://github.com/marketplace/actions/gitleaks) has a paid license restriction, therefore a custom workflow has been setup instead. It will fail the secret scan if secrets are detected and push alerts to Github security.
27+
28+
## Local setup
29+
30+
!!! done
31+
32+
This is already configured for you via [pre-commit](pre-commit.md#local-setup).
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# golangci-lint
2+
3+
## What
4+
5+
[golangci-lint](https://golangci-lint.run/) is a Go linters aggregator. It runs linters in parallel, uses caching, supports yaml config, has integrations with all major IDE and has dozens of linters included.
6+
7+
## Why
8+
9+
Provides Secure Application Security Testing, error, style etc. checks for your codebase.
10+
11+
!!! tip
12+
13+
See supported linters [here](https://golangci-lint.run/usage/linters).
14+
15+
## How
16+
17+
Linters can be configured via command-line options or a [configuration file](https://golangci-lint.run/usage/configuration/#config-file).
18+
19+
20+
## CI setup
21+
22+
!!! summary
23+
24+
No configuration required.
25+
26+
`golangci-lint` will be executed via the pre-commit Github workflow in `.github/workflows/pre-commit.yml`.
27+
28+
## Local setup
29+
30+
!!! done
31+
32+
This is already configured for you via [pre-commit](pre-commit.md#local-setup).
33+
34+
For custom configurations to modify how `golangci-lint` runs see the [configuration guide](https://golangci-lint.run/usage/configuration/).
35+
36+
You may want to disable linters that might be too strict (e.g: [exhaustivestruct](https://github.com/mbilski/exhaustivestruct)) or add some rules around how it should behave. This can be done via [linter configuration](https://golangci-lint.run/usage/linters/#linters-configuration).
82.7 KB
Loading
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# mkdocs-material
2+
3+
## What
4+
5+
[mkdocs-material](https://squidfunk.github.io/mkdocs-material/) provides documentation in Markdown to create a professional static site in minutes – searchable, customizable, for all devices.
6+
7+
## Why
8+
9+
From a developer experience perspective, it is easier to clone and have everything you need to reference locally rather than having to externally reference something i.e Github wiki, Confluence etc.
10+
11+
This minimises context switching and aids the practice of keeping documentation updated as it is closer to the codebase.
12+
13+
## How
14+
15+
The repository is preconfigured with a `./docs` directory and renders all markdown files to generate a `github-pages` site.
16+
17+
`mkdocs-material` is customizable via the `mkdocs.yml` configuration file available in the repository root directory. The configuration present is not exhaustive and can be further [customized](https://squidfunk.github.io/mkdocs-material/reference/).
18+
19+
20+
## CI setup
21+
22+
### Github pages
23+
24+
A gen-docs workflow is configured to automatically run on the `main` branch however it requires github-pages to be enabled in the repository settings.
25+
26+
See the screenshot below:
27+
28+
![gh-pages-settting](img/mkdocs-gh-pages.png)
29+
30+
The documentation contained within the `./docs` directory will be automatically published and accessible via `<org>.github.io/<repository>.`
31+
32+
### Site name
33+
34+
Update `site_name` field in `./mkdocs.yml` file to set the main title for the project documentation.
35+
36+
37+
## Local setup
38+
39+
```bash
40+
pip install mkdocs-material
41+
```
42+
43+
For more installtion options see [here](https://squidfunk.github.io/mkdocs-material/getting-started/).
44+
45+
Run a local server to preview docs:
46+
47+
```bash
48+
mkdocs serve
49+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# pre-commit
2+
3+
## What
4+
5+
[pre-commit](https://pre-commit.com/) is a wrapper for git hook scripts that are useful for identifying simple issues before submission to code review. Git hooks are run on every commit to automatically point out issues in code such as missing semicolons, trailing whitespace, and debug statements and integrate with a variety of third-party tooling.
6+
7+
## Why
8+
9+
Eliminates the effort of initializing and managing git hooks locally. `pre-commit` also integrates with a large range of (hooks)[https://pre-commit.com/hooks.html] enabling a consistent developer experience.
10+
11+
## How
12+
13+
A `.pre-commit-config.yaml` config file is configured with common and useful hoooks. This is available at the root of your repository. Each time you make a commit the pre-commit hooks run. If a hook supports applying auto-fixes (e.g: hook `trailing-whitespace` support fixing trailing whitespaces), it will proceed to fix it.
14+
Any detected failures will abort the commit.
15+
16+
!!! tip
17+
18+
See supported hooks [here](https://pre-commit.com/hooks.html).
19+
20+
## CI setup
21+
22+
!!! summary
23+
24+
No configuration required.
25+
26+
All hooks in `.pre-commit-config.yaml` will be executed via the pre-commit Github workflow in `.github/workflows/pre-commit.yml`.
27+
28+
## Local setup
29+
30+
```bash
31+
pip install -u pre-commit
32+
```
33+
34+
For more installtion options see [here](https://commitizen-tools.github.io/commitizen/#installation).
35+
36+
Install the hooks configured in `.pre-commit-config.yaml`:
37+
38+
```bash
39+
pre-commit install
40+
```
41+
42+
Running against all files instead of only stages files:
43+
44+
```
45+
pre-commit run --all-files
46+
```
47+
48+
## FAQ
49+
50+
1. Do I have to run `pre-commit install` everytime I clone a repository?
51+
52+
Yes. However, you can automatically enable `pre-commit` to run when you clone a repository via [this](https://pre-commit.com/#automatically-enabling-pre-commit-on-repositories) link.
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# semantic-release
2+
3+
## What
4+
5+
[semantic-release](https://github.com/semantic-release/semantic-release) automates the whole package release workflow including determining the next version number, generating the release notes, and publishing the package.
6+
7+
semantic-release uses the commit messages to determine the consumer impact of changes in the codebase. Following formalized conventions for commit messages, `semantic-release` automatically determines the next semantic version number, generates a changelog and publishes the release.
8+
9+
## Why
10+
11+
Follow a well-established [commit message convention](https://github.com/angular/angular/blob/main/CONTRIBUTING.md#commit) that encourages your team to have structured commits and provides the controls via commits to automatically version your codebase & publish a release.
12+
13+
14+
## How
15+
16+
### Commit message convention
17+
18+
The formalized convention is as follows for commit messages:
19+
20+
```
21+
<type>(<scope>): <short summary>
22+
│ │ │
23+
│ │ └─⫸ Summary in present tense. Not capitalized. No period at the end.
24+
│ │
25+
│ └─⫸ Commit Scope: A scope MUST consist of a noun describing a section of the codebase surrounded by parenthesis
26+
27+
└─⫸ Commit Type: build|ci|docs|feat|fix|perf|refactor|test
28+
```
29+
30+
### Example
31+
32+
33+
| Commit message | Release type |
34+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------- |
35+
| `fix(pencil): stop graphite breaking when too much pressure applied` | Fix Release |
36+
| `feat(pencil): add 'graphiteWidth' option` | Feature Release |
37+
| `perf(pencil): remove graphiteWidth option`<br><br>`BREAKING CHANGE: The graphiteWidth option has been removed.`<br>`The default graphite width of 10mm is always used for performance reasons.` | Breaking Release <br /> (Note that the `BREAKING CHANGE: ` token must be in the footer of the commit) |
38+
39+
40+
For a base version of `0.1.0`, the following will apply:
41+
42+
| Type | Release type example | Notes |
43+
|---------------------------|---------------------------|----------------------------------------------------------------|
44+
| `fix` | increments to `0.1.1` | |
45+
| `feat` | increments to `0.1.0` | Resets any existing patch fixes e.g: `0.1.3` will be `0.2.0` |
46+
| `BREAKING CHANGE` | Increments to `1.0.0` | Can be added to any type |
47+
| All others | No version increment | |
48+
49+
50+
## CI setup
51+
52+
!!! warning
53+
54+
This section covers important implications of setting up a base tag/release version (or lack of) in your repo before using `semantic-release`.
55+
56+
### Base release version
57+
58+
A semantic-release workflow is configured to run on the `main` branch and technically no further setup is required. However, the semantic-release initial version is set at `v1.0.0` (with pre-release options) instead of the generally accepted version `v0.1.0`. This may not be desirable for your project so a workaround is described below.
59+
60+
!!! info
61+
62+
As per the semantic versioning [spec](https://semver.org/#how-should-i-deal-with-revisions-in-the-0yz-initial-development-phase), the initial development release should be `v0.1.0`. Optionally you can set it to `v0.0.0` if there is only an initial commit in the repo.
63+
64+
65+
<u>In the Github repo page:</u>
66+
67+
1. Click on the **Create a new release** link on the right-hand panel
68+
69+
2. Click on **Choose a tag**, type in your base version (e.g: `v0.1.0`) and hit enter
70+
71+
3. Enter desired release title e.g: Pre-release
72+
73+
4. Tick **This is a pre-release** checkbox
74+
75+
5. Click the **Publish** button
76+
77+
If you don't want to create a release and the steps above are one too many, you can create a tag via the command line:
78+
79+
```bash
80+
# Within the `main` branch in your git repo
81+
git tag -a v0.1.0 -m "Pre-release"
82+
git push origin v0.1.0
83+
```
84+
85+
## Local setup
86+
87+
### Commitizen
88+
89+
Use [commitzen](https://commitizen-tools.github.io/commitizen/) to ease following the commit message convention described [above](semantic-release.md#how).
90+
91+
```
92+
pip install -U commitizen
93+
```
94+
95+
For more installtion options see [here](https://commitizen-tools.github.io/commitizen/#installation).
96+
97+
!!! info
98+
99+
Stage some files in your repo and type `cz commit` and you're ready to go!
100+
101+
102+
!!! tip
103+
104+
Decide on the commit convention scope in advance. This will keep it consistent and provide a coherent semantic mapping.
105+
106+
107+
## FAQ
108+
109+
1. I have many `feat` type commits to be added to `main` but I don't want to trigger a release
110+
111+
For a Continous Deployment methodology, it is not uncommon to release small features frequently in isolation. This will undoubtedly increment your minor version but it is acceptable as it reflects the rapid changes in your project.
112+
113+
Alternatively, if you wish to batch features to trigger a release here are some options:
114+
115+
- **Release branch (recommended)**
116+
117+
Create a release branch and merge multiple `feat` type commits to it. When the release branch is ready and merged to `main`, it will condense the numerous `feat` type commits to generate a singular increment in the release version/tag.
118+
119+
- **Non-standard commit type**
120+
121+
Use a custom commit type such as:
122+
123+
```bash
124+
# Feature no release (featnr) denotes a feature but is not release ready
125+
featnr(pencil): add 'graphiteWidth' option
126+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Sonarqube
2+
3+
## What
4+
5+
## Why
6+
7+
## How
8+
9+
## CI setup
10+
11+
## Local setup
12+
13+
N/A.

docs/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
!!! note
2+
3+
This is your project's home page.
4+
5+
!!! to-do
6+
7+
Update the `site_name` config in the `mkdocs.yml` file within the root directory.

0 commit comments

Comments
 (0)