Skip to content
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
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ updates:
schedule:
interval: weekly
open-pull-requests-limit: 5
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"
14 changes: 5 additions & 9 deletions .github/workflows/gitleaks.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
name: Gitleaks

on: [pull_request, push, workflow_dispatch]

name: gitleaks
on: [push]
jobs:
gitleaks:
name: Secret Scan
runs-on: ubuntu-latest
steps:
- name: Check out the repo
- name: Checkout
uses: actions/checkout@v2
- name: Run gitleaks
run: docker run -v ${{ github.workspace }}:/path zricethezav/gitleaks:latest detect -v --source="/path" --redact

run-if-failed:
name: Github Security Report (if gitleaks job fails)
name: gen-report (if gitleaks fails)
runs-on: ubuntu-latest
needs: [gitleaks]
if: always() && (needs.gitleaks.result == 'failure')
permissions:
security-events: write
steps:
- name: Check out the repo
- name: Checkout
uses: actions/checkout@v2
- name: Generate gitleaks SARIF file
# Exit 0 so we can get the failed report results from this step.
Expand Down
12 changes: 5 additions & 7 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
name: golangci-lint
on:
push:
pull_request:
on: [push]
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
golangci:
name: lint
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.17
- uses: actions/checkout@v3
- name: golangci-lint
- name: Checkout
uses: actions/checkout@v3
- name: Run linters
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
name: gen-docs
name: mkdocs
on:
push:
branches:
- master
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: Checkout
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.x
- run: pip install mkdocs-material
- run: mkdocs gh-deploy --force
- name: Install mkdocs-material
run: pip install mkdocs-material
- name: Publish to gh-pages
run: mkdocs gh-deploy --force
11 changes: 6 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
name: release

on:
push:
branches:
- main
jobs:
tag:
semantic-release:
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- 16.x
steps:
- name: Checkout
-
name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Release
-
name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx semantic-release
goreleaser:
runs-on: ubuntu-latest
needs: tag
needs: semantic-release
steps:
-
name: Checkout
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: tests
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.18
- name: Go Test
run: go test -v ./...
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*.dll
*.so
*.dylib
bin/

# Test binary, built with `go test -c`
*.test
Expand All @@ -14,4 +15,9 @@
# Dependency directories (remove the comment below to include it)
# vendor/

bin/
# Code editor personal settings
.vscode/
.idea/

# Other
.DS_Store
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/golangci/golangci-lint
rev: v1.47.0
rev: v1.47.2
hooks:
- id: golangci-lint
- repo: https://github.com/zricethezav/gitleaks
Expand Down
23 changes: 16 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
FROM golang:1.18 as build
WORKDIR /go/src/app
FROM golang:1.18-alpine as builder

RUN apk update && apk upgrade && \
apk add --no-cache make bash

WORKDIR /src
COPY . .
# Static build requires CGO_ENABLED=0
RUN mkdir -p /go/bin && CGO_ENABLED=0 go build -ldflags="-w -s" -o /go/bin/app ./...

# Build executable
RUN make build

# Using a distroless image from https://github.com/GoogleContainerTools/distroless
# Image sourced from https://console.cloud.google.com/gcr/images/distroless/global/static
FROM gcr.io/distroless/static:nonroot
COPY --from=build /go/bin/app /
# numeric version of user nonroot:nonroot provided in image

# Copy executable from builder image
COPY --from=builder /src/bin/app /

# Numeric version of user nonroot:nonroot provided in image
USER 65532:65532

# Run the executable
CMD ["/app"]
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
SHELL=/bin/bash -e -o pipefail
PWD = $(shell pwd)
GO_BUILD= go build
GOFLAGS= CGO_ENABLED=0

## help: Print this help message
.PHONY: help
Expand Down Expand Up @@ -37,4 +39,4 @@ fmt:
## build: Build binary into bin/ directory
.PHONY: build
build:
go build -ldflags="-w -s" -o bin/app ./...
$(GOFLAGS) $(GO_BUILD) -a -v -ldflags="-w -s" -o bin/app cmd/main.go
31 changes: 31 additions & 0 deletions docs/continuous-integration/goreleaser.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# GoReleaser

## What

[GoReleaser](https://goreleaser.com/) builds Go binaries for several platforms. The goal is to simplify the build, release and publish steps while providing variant customization options for all steps.

## Why

Simplifies the build and packing process of your app's Go binaries.

## How

The entire release process can be customized through a `.goreleaser.yml` file. Once you set it up, every time you want to create a new release, all you need to do is create a git tag that conforms to [semantic versioning](https://goreleaser.com/limitations/semver/) and run `goreleaser release`.


## CI setup

!!! summary

No configuration required.

GoReleaser is configured to run on the `main` branch and is executed via the release Github workflow in `.github/workflows/release.yml`.


!!! info

Binaries are only created if a tag exists. This is controlled via [semantic-release](semantic-release.md).

## Local setup

The [quickstart](https://goreleaser.com/quick-start/) provides detailed steps to run GoReleaser locally.
2 changes: 1 addition & 1 deletion docs/continuous-integration/mkdocs-material.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The repository is preconfigured with a `./docs` directory and renders all markdo

### Github pages

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.
`mkdocs` is configured to automatically run on the `main` branch and is executed via the mkdocs Github workflow in `.github/workflows/mkdocs.yml`. However, it requires github-pages to be enabled in the repository settings.

See the screenshot below:

Expand Down
12 changes: 11 additions & 1 deletion docs/continuous-integration/pre-commit.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ Any detected failures will abort the commit.

No configuration required.

All hooks in `.pre-commit-config.yaml` will be executed via the pre-commit Github workflow in `.github/workflows/pre-commit.yml`.
All hooks in `.pre-commit-config.yaml` will be executed via the automatic integration provided from [pre-commit ci](https://pre-commit.ci/).

`pre-commit ci` runs automatically on pull request commits.

### Auto fixing pull requests

If tools (configured in `.pre-commit-config.yaml`) make changes to files during a pull request, pre-commit.ci will automatically fix the pull request.

pre-commit.ci will run on all pull request commits, but will not push for commits made by bots.

The impact of this means developers will need to fetch the latest changes if further work must be done on the PR branch.

## Local setup

Expand Down
6 changes: 4 additions & 2 deletions docs/continuous-integration/semantic-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[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.

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.
`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.

## Why

Expand Down Expand Up @@ -53,9 +53,11 @@ For a base version of `0.1.0`, the following will apply:

This section covers important implications of setting up a base tag/release version (or lack of) in your repo before using `semantic-release`.



### Base release version

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.
`semantic-release` is configured to run on the `main` branch and is executed via the release Github workflow in `.github/workflows/release.yml`. Technically, no further setup is required. However, the initial version is set at `v1.0.0` (with optional pre-release settings) instead of the generally accepted version `v0.1.0`. This may not be desirable for your project so a workaround is described below.

!!! info

Expand Down