Skip to content

Commit

Permalink
chore: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsimonemms committed Jun 11, 2023
0 parents commit d9d4e7d
Show file tree
Hide file tree
Showing 23 changed files with 882 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .cobra.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
author: Simon Emms <simon@simonemms.com>
license: Apache-2.0
useViper: false
27 changes: 27 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "devcontainer",
"image": "ghcr.io/mrsimonemms/devcontainers/full",
"features": {},
"customizations": {
"vscode": {
"settings": {},
"extensions": [
"donjayamanne.git-extension-pack",
"EditorConfig.EditorConfig",
"waderyan.gitblame",
"GitHub.vscode-github-actions",
"golang.go"
]
}
},
"postStartCommand": {
"copy-cobra": "ln -s $PWD/.cobra.yaml $HOME/.cobra.yaml",
"cobra-install": "go install github.com/spf13/cobra-cli@latest",
"golangci-lint": "go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest",
"errcheck": "go install github.com/kisielk/errcheck@latest",
"gofumpt": "go install mvdan.cc/gofumpt@latest",
"staticcheck": "go install honnef.co/go/tools/cmd/staticcheck@latest",
"goimports": "go install golang.org/x/tools/cmd/goimports@latest",
"pre-commit": "pre-commit install --install-hooks -t pre-commit -t commit-msg"
}
}
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.go]
indent_style = tab
indent_size = 4

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
indent_size = 4
158 changes: 158 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
name: Build
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
permissions:
contents: write
packages: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '>=1.19.0'

- name: Go install
run: go install ./...

- name: golangci-lint
uses: golangci/golangci-lint-action@v3

- name: go-fmt-import
uses: Jerome1337/goimports-action@v1.0.2

- name: go-vet
run: go vet -v ./...

- name: gofumpt
run: |
go install mvdan.cc/gofumpt@latest
LIST_OF_FILES=$(gofumpt -l .)
echo "$LIST_OF_FILES"
if [ -n "$LIST_OF_FILES" ]; then
exit 1
fi
- name: go-err-check
run: |
go install github.com/kisielk/errcheck@latest
errcheck ./...
- name: go-static-check
uses: dominikh/staticcheck-action@v1.2.0
with:
install-go: false

- uses: actions/setup-python@v3

- uses: pre-commit/action@v3.0.0

build:
runs-on: ubuntu-latest
needs:
- test
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '>=1.19.0'

- run: go version

- name: Install Go dependencies
run: go install ./...

- name: Lint Go
uses: golangci/golangci-lint-action@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get branch names
id: branch-name
uses: tj-actions/branch-names@v6
with:
strip_tag_prefix: v

- name: Generate Docker tag
id: docker
run: |
if [ "${{ steps.branch-name.outputs.is_tag }}" = "true" ];
then
# Latest tag
IMG_NAME="ghcr.io/${GITHUB_REPOSITORY,,}:latest"
# Tag name (usually vX.Y.Z)
IMG_NAME="${IMG_NAME},ghcr.io/${GITHUB_REPOSITORY,,}:${{ steps.branch-name.outputs.tag }}"
echo "image_name=${IMG_NAME}" >> "$GITHUB_OUTPUT"
echo "platforms=linux/amd64,linux/arm64,linux/arm/v7" >> "$GITHUB_OUTPUT"
else
# Use branch naming convention
TAG="branch-${{ steps.branch-name.outputs.current_branch }}"
# Change "/" for "-"
TAG="${TAG//\//-}"
# Set to lowercase
TAG="${TAG,,}"
echo "image_name=ghcr.io/${GITHUB_REPOSITORY,,}:${TAG}" >> "$GITHUB_OUTPUT"
echo "platforms=linux/amd64" >> "$GITHUB_OUTPUT"
fi
if [ "${{ steps.branch-name.outputs.is_tag }}" = "true" ];
then
echo "version=${{ steps.branch-name.outputs.tag }}" >> "$GITHUB_OUTPUT"
else
echo "version=development" >> "$GITHUB_OUTPUT"
fi
echo "commit_id=${GITHUB_SHA}" >> "$GITHUB_OUTPUT"
echo "gitRepo=github.com/${GITHUB_REPOSITORY}" >> "$GITHUB_OUTPUT"
- name: Build and push
uses: docker/build-push-action@v3
with:
context: .
build-args: |
GIT_COMMIT=${{ steps.docker.outputs.commit_id }}
GIT_REPO=${{ steps.docker.outputs.gitRepo }}
VERSION=${{ steps.docker.outputs.version }}
platforms: ${{ steps.docker.outputs.platforms }}
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{ steps.docker.outputs.image_name }}

- name: Run GoReleaser
if: steps.branch-name.outputs.is_tag == 'true'
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --clean
env:
GIT_REPO: ${{ steps.docker.outputs.gitRepo }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21 changes: 21 additions & 0 deletions .github/workflows/commitlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Commit lint
permissions: read-all
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
jobs:
commitlint:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # fetch-depth is required

- uses: wagoid/commitlint-github-action@v5
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
dist
tmp

node_modules

.idea
.DS_Store
Thumbs.db
.commit
.envrc
13 changes: 13 additions & 0 deletions .gitpod.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM gitpod/workspace-full

# Gitpod Package Manager
RUN curl -sfL gpm.simonemms.com | bash \
&& gpm install pre-commit

# Golang dependencies
RUN go install github.com/spf13/cobra-cli@latest \
&& go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest \
&& go install github.com/kisielk/errcheck@latest \
&& go install mvdan.cc/gofumpt@latest \
&& go install honnef.co/go/tools/cmd/staticcheck@latest \
&& go install golang.org/x/tools/cmd/goimports@latest
37 changes: 37 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
image:
file: .gitpod.Dockerfile

tasks:
- name: Setup
command: |
pre-commit install --install-hooks -t pre-commit -t commit-msg
gp sync-done pre-commit
exit 0
- init: |
if [ -f "go.mod" ]; then
go install ./...
fi
command: |
# Copy .cobra.yaml to $HOME
cp .cobra.yaml $HOME/.cobra.yaml
export GIT_REPO="${GITPOD_WORKSPACE_CONTEXT_URL/https:\/\//}"
export PROJECT_NAME="${GIT_REPO##*/}"
if [ ! -f "go.mod" ]; then
echo "Creating Go module"
go mod init "$GIT_REPO"
fi
if [ ! -f "main.go" ]; then
echo "Create Cobra project"
cobra-cli init
go mod tidy
fi
vscode:
extensions:
- donjayamanne.git-extension-pack
- EditorConfig.EditorConfig
- golang.go
37 changes: 37 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
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
ldflags:
- -w -s -X {{ .Env.GIT_REPO }}/cmd.Version={{ .Version }} -X {{ .Env.GIT_REPO }}/cmd.GitCommit={{ .Commit }}
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:'
# modelines, feel free to remove those if you don't want/use them:
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
1 change: 1 addition & 0 deletions .mdlrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style 'markdownlint.rb'
33 changes: 33 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/compilerla/conventional-pre-commit
rev: v2.3.0
hooks:
- id: conventional-pre-commit
stages:
- commit-msg
- repo: https://github.com/trussworks/pre-commit-hooks
rev: v1.1.1
hooks:
- id: markdown-toc
- repo: https://github.com/golangci/golangci-lint
rev: v1.53.2
hooks:
- id: golangci-lint
- repo: https://github.com/Bahjat/pre-commit-golang
rev: v1.0.3
hooks:
- id: go-fmt-import
- id: go-vet
- id: gofumpt
- id: go-err-check
- id: go-static-check
- repo: https://github.com/markdownlint/markdownlint
rev: v0.12.0
hooks:
- id: markdownlint
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"yaml.schemas": {
"https://json.schemastore.org/github-workflow.json": [
".github/workflows/*.{yml,yaml}"
]
}
}
Loading

0 comments on commit d9d4e7d

Please sign in to comment.