This repository has been archived by the owner on Mar 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3af1d58
Showing
88 changed files
with
6,549 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.git | ||
.github | ||
|
||
docs | ||
|
||
.dockerignore | ||
.gitignore | ||
.golangci.yaml | ||
.mockery.yaml | ||
|
||
Dockerfile | ||
README.md | ||
Taskfile.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* @itimky |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- '**' | ||
paths-ignore: | ||
- 'docs/**' | ||
- 'README.md' | ||
|
||
concurrency: | ||
group: ci-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-22.04 | ||
timeout-minutes: 2 | ||
name: Lint | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
|
||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.21' | ||
|
||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
version: v1.54 | ||
skip-cache: true | ||
|
||
test: | ||
runs-on: ubuntu-22.04 | ||
timeout-minutes: 2 | ||
name: Test | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
|
||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.21' | ||
|
||
- name: Run go mod tidy | ||
run: go mod tidy | ||
|
||
- name: Check for changes | ||
run: | | ||
if [ -n "$(git status --porcelain)" ]; then | ||
echo "go.mod and/or go.sum have changes after running go mod tidy. Please tidy your module." | ||
git diff | ||
exit 1 | ||
fi | ||
- name: Run Tests | ||
run: go test -coverprofile=coverage.out -covermode=atomic ./... | ||
|
||
- name: Check coverage | ||
id: coverage | ||
run: | | ||
coverage=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//') | ||
echo "Total coverage: $coverage%" | ||
minimum=99.9 | ||
result=$(echo "$coverage >= $minimum" | bc) | ||
if [ "$result" -eq 0 ]; then | ||
echo "Coverage of $coverage% is below the minimum of $minimum%" | ||
exit 1 | ||
fi | ||
- name: Upload coverage reports to Codecov | ||
uses: codecov/[email protected] | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
slug: itimky/spindle | ||
disable_search: true | ||
file: ./coverage.out | ||
dry_run: ${{ github.ref != 'refs/heads/master' }} | ||
fail_ci_if_error: true | ||
|
||
build: | ||
runs-on: ubuntu-22.04 | ||
timeout-minutes: 5 | ||
name: Build | ||
needs: [ lint, test ] | ||
steps: | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
with: | ||
version: v0.12.1 | ||
platforms: linux/arm64 | ||
driver: docker-container | ||
|
||
- uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
|
||
- name: Cache Docker layers | ||
uses: actions/cache@v3 | ||
id: go-build-cache | ||
with: | ||
path: go-build-cache | ||
key: go-build-cache-${{ hashFiles('go.mod') }} | ||
restore-keys: go-build-cache- | ||
|
||
- name: Inject Docker layers | ||
uses: reproducible-containers/[email protected] | ||
with: | ||
cache-source: go-build-cache | ||
cache-target: /root/.cache/go-build | ||
skip-extraction: ${{ steps.go-build-cache.outputs.cache-hit }} | ||
|
||
- name: Prepare tags | ||
run: | | ||
echo "SHORT_SHA=$(echo ${GITHUB_SHA::7})" >> $GITHUB_ENV | ||
echo "TIMESTAMP=$(date -u +%Y%m%d-%H%M%S)" >> $GITHUB_ENV | ||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v5 | ||
with: | ||
tags: ghcr.io/${{ github.repository_owner }}/spindle:${{ env.SHORT_SHA }}-${{ env.TIMESTAMP }} | ||
platforms: linux/arm64 | ||
provenance: false # disable docker-specific metadata, leave OCI-compatible metadata only | ||
push: false | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# If you prefer the allow list template instead of the deny list, see community template: | ||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore | ||
# | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# Go workspace file | ||
go.work | ||
|
||
bin | ||
tmp | ||
*.log | ||
|
||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
linters: | ||
enable-all: true | ||
disable: | ||
# Disable deprecated linters | ||
- structcheck | ||
- nosnakecase | ||
- maligned | ||
- golint | ||
- interfacer | ||
- varcheck | ||
- exhaustivestruct | ||
- scopelint | ||
- deadcode | ||
- ifshort | ||
# Disable formatting linters except the used one | ||
- gofumpt | ||
issues: | ||
exclude-rules: | ||
# Exclude some linters from running on tests files. | ||
- path: _test\.go | ||
linters: | ||
- depguard | ||
- goerr113 | ||
- exhaustruct | ||
- funlen | ||
linters-settings: | ||
depguard: | ||
rules: | ||
pkg: | ||
files: | ||
- pkg/**/*.go | ||
deny: | ||
- pkg: github.com/itimky/spindle/internal | ||
desc: not allowed, internal imports pkg, not vice versa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# https://vektra.github.io/mockery/latest/configuration/ | ||
|
||
log-level: warn | ||
all: true | ||
dir: 'test/{{ replaceAll .InterfaceDirRelative "github.com/itimky/spindle" "" }}' | ||
outpkg: mocks | ||
packages: | ||
github.com/IBM/sarama: | ||
config: | ||
all: false | ||
interfaces: | ||
ConsumerGroupSession: {} | ||
ConsumerGroupClaim: {} | ||
|
||
github.com/itimky/spindle/pkg/sys/queue: | ||
config: | ||
all: false | ||
interfaces: | ||
router: {} | ||
github.com/itimky/spindle/pkg/sys/queue/adapter: {} | ||
|
||
github.com/itimky/spindle/pkg/storage/answer-processor: {} | ||
|
||
github.com/itimky/spindle/pkg/domain/answer-processor: {} | ||
|
||
github.com/itimky/spindle/pkg/facade/match: {} | ||
github.com/itimky/spindle/pkg/facade/system: {} | ||
|
||
github.com/itimky/spindle/pkg/handler/kafka: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM golang:1.21.6-alpine3.19 AS builder | ||
WORKDIR /src | ||
RUN go env -w GOMODCACHE=/root/.cache/go-build | ||
COPY go.mod go.sum ./ | ||
RUN --mount=type=cache,target=/root/.cache/go-build go mod download | ||
COPY . . | ||
RUN --mount=type=cache,target=/root/.cache/go-build go build -o /go/bin/spindle ./cmd/spindle | ||
|
||
FROM alpine:3.19 | ||
WORKDIR /app | ||
COPY --from=builder /go/bin/spindle /app | ||
CMD ["/app/spindle"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Spindle | ||
|
||
[](https://codecov.io/gh/itimky/spindle) | ||
|
||
Sample go app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# https://taskfile.dev/usage/ | ||
|
||
version: '3' | ||
|
||
silent: true | ||
|
||
vars: | ||
GOLANGCI_LINT_VERSION: v1.54.2 | ||
MOCKERY_VERSION: v2.42.0 | ||
GOLANG_TEST_IMAGE: golang:1.21.6-alpine3.19 | ||
|
||
tasks: | ||
gen: | ||
desc: Generate code | ||
deps: | ||
- gen:mocks | ||
|
||
gen:mocks: | ||
desc: Generate mocks | ||
cmds: | ||
- docker run --rm -v {{.PWD}}:/src -w /src vektra/mockery:{{.MOCKERY_VERSION}} | ||
|
||
fmt: | ||
desc: Format code | ||
cmds: | ||
- docker run --rm -v {{.PWD}}:/src -v ./tmp/golangci-lint/{{.GOLANGCI_LINT_VERSION}}:/root/.cache -w /src golangci/golangci-lint:{{.GOLANGCI_LINT_VERSION}} golangci-lint run --no-config --disable-all --enable gci --fix | ||
|
||
lint: | ||
desc: Lint code | ||
cmds: | ||
- docker run --rm -v {{.PWD}}:/src -v ./tmp/golangci-lint/{{.GOLANGCI_LINT_VERSION}}:/root/.cache -w /src golangci/golangci-lint:{{.GOLANGCI_LINT_VERSION}} golangci-lint run | ||
|
||
test: | ||
desc: Test code | ||
cmds: | ||
- > | ||
docker run --rm | ||
-v {{.PWD}}:/app | ||
-v {{.HOME}}/.cache/go-build:/root/.cache/go-build | ||
-v {{.HOME}}/go/pkg/mod:/go/pkg/mod | ||
-w /app | ||
{{.GOLANG_TEST_IMAGE}} | ||
go test $(go list ./... | | ||
grep -v /cmd/ | | ||
grep -v /pkg/contract/ | | ||
grep -v /pkg/domain$ | | ||
grep -v /pkg/sys$ | | ||
grep -v /pkg/sys/log$ | | ||
grep -v /test/ | ||
) -covermode=atomic | ||
-coverprofile /tmp/cov.out |
Oops, something went wrong.