Skip to content

Commit

Permalink
Merge pull request #2 from rog-golang-buddies/update-from-template
Browse files Browse the repository at this point in the history
Update from template
  • Loading branch information
ldmi3i authored Jul 31, 2022
2 parents 8f4552a + 924a1df commit 6f7c37a
Show file tree
Hide file tree
Showing 23 changed files with 687 additions and 38 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: gomod
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 5
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"
45 changes: 45 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Description

_Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change_

Fixes # (issue)
Dependent # (issue)
## Current status

- [ ] Waiting for review
- [ ] Waiting for comment resolution
- [ ] Waiting for merge
- [ ] Draft
- [ ] Trivial PR (nominal cosmetic/typo/whitespace changes)

## Semantic Versioning
Please delete options that are not relevant. Ensure same has been covered in the commit message as well.

- This is a `fix` change
- This is a `feat` change
- This is a `BREAKING CHANGE`

## Type of change

Please delete options that are not relevant.

- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing functionality to not work as expected)
- This change requires a documentation update

## How Has This Been Tested?

_Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration_

### Automated

### Manual

## Checklist:
- [ ] My commit message mentions fix, feat, BREAKING CHANGE accordingly to increase the semantic versioning
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] I have checked my code/docs and corrected any misspellings
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
19 changes: 19 additions & 0 deletions .github/workflows/mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: mkdocs
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: 3.x
- name: Install mkdocs-material
run: pip install mkdocs-material
- name: Publish to gh-pages
run: mkdocs gh-deploy --force
36 changes: 32 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,49 @@
name: Release Package
name: release
on:
push:
branches:
- main
jobs:
build:
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: semantic-release
steps:
-
name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
-
name: Setup Go
uses: actions/setup-go@v3
with:
go-version: "1.18.0"
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
args: release -f .goreleaser.yaml --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
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
47 changes: 47 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

# The project name is used in the name of the Brew formula, archives, etc. If none is given, it will be inferred
# from the name of the GitHub, GitLab, or Gitea release.
# project_name: golang-template-repository
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
builds:
- env: [CGO_ENABLED=0]
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
# ID of the build.
# Defaults to the binary name, uncomment line below if needed
# id: "golang-template-repository"
dir: .
main: ./cmd
# uncomment this line to build binary at specific location# Binary name.
# Can be a path (e.g. `bin/app`) to wrap the binary in a directory.
# Default is the name of the project directory.
# binary: ./bin/app
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ repos:
rev: v1.47.2
hooks:
- id: golangci-lint
- repo: https://github.com/zricethezav/gitleaks
rev: v8.8.12
hooks:
- id: gitleaks

ci:
autofix_commit_msg: |
Expand Down
22 changes: 16 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +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 . .
RUN mkdir -p /go/bin && 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
Loading

0 comments on commit 6f7c37a

Please sign in to comment.