Skip to content

Commit

Permalink
Code
Browse files Browse the repository at this point in the history
  • Loading branch information
aleskandro committed Aug 28, 2024
1 parent 7fa4b52 commit 7afad5e
Show file tree
Hide file tree
Showing 22 changed files with 1,447 additions and 0 deletions.
128 changes: 128 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: Build and test
on:
push:
branches:
- main
tags:
- v*
workflow_dispatch: { }
pull_request: { }

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.23.x'
cache: true
check-latest: true
- name: lint
run: |
make lint
fmt:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.23.x'
cache: true
check-latest: true
- name: fmt
run: |
make fmt
vet:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.23.x'
cache: true
check-latest: true
- name: vet
run: |
make vet
goimports:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.23.x'
cache: true
check-latest: true
- name: goimports
run: |
make goimports
gosec:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.23.x'
cache: true
check-latest: true
- name: gosec
run: |
make gosec
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.23.x'
cache: true
check-latest: true
- name: unit
run: |
make unit
release:
runs-on: ubuntu-latest
permissions:
contents: write
needs:
- fmt
- goimports
- gosec
- lint
- test
- vet
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.23.x'
cache: true
check-latest: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build image
run: |
make koboroot
- name: Release
if: startsWith(github.ref, 'refs/tags/v')
uses: ncipollo/release-action@v1.14.0
with:
allowUpdates: true
artifacts: _artifacts/KoboRoot.tgz
#generate_release_notes: true
#make_latest: true
102 changes: 102 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
linters:
disable-all: true
# Enable specific linter
# https://golangci-lint.run/usage/linters/#enabled-by-default-linters
enable:
# Default linters
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
# Additional linters
- asciicheck
- bidichk
#- bodyclose
#- contextcheck
#- cyclop
- dogsled
#- dupl
- durationcheck
#- errname
#- errorlint
#- exhaustive
#- exportloopref
#- forcetypeassert
#- funlen
#- gochecknoglobals
#- gocognit
#- goconst
#- gocritic
#- gocyclo
#- godot
#- goerr113
- gofmt
#- goheader
- goimports
- goprintffuncname
#- gosec
- importas
- makezero
#- misspell
#- nakedret
#- nestif
- nilerr
#- nilnil
#- nlreturn
#- noctx
- nolintlint
#- prealloc
#- predeclared
#- revive
#- stylecheck
#- tagliatelle
- tenv
#- unconvert
#- unparam
#- whitespace
#- wrapcheck
#- wsl
linters-settings:
goheader:
template: |-
Copyright {{YEAR}} Red Hat, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
nlreturn:
block-size: 2
revive:
confidence: 0
rules:
- name: exported
severity: warning
disabled: false
arguments:
- "checkPrivateReceivers"
- "disableStutteringCheck"
stylecheck:
# https://staticcheck.io/docs/options#checks
checks: ["all", "-ST1000"]
dot-import-whitelist:
- "github.com/onsi/gomega"
issues:
exclude: []
exclude-use-default: false
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- gocyclo
- dupl
- gosec
- gochecknoglobals
- goerr113
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM golang:1.23 AS builder

WORKDIR /go/src/app
COPY . .
RUN CGO_ENABLED=0 GOARCH=arm go build -a -o manager main.go

FROM scratch

WORKDIR /etc/ssl/certs/
COPY --from=gcr.io/distroless/base /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

WORKDIR /usr/local/nextcloud-kobo/
COPY --from=builder /go/src/app/manager ./nextcloud-kobo

COPY /root/ /
ENTRYPOINT ["/usr/local/nextcloud-kobo/nextcloud-kobo"]
77 changes: 77 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
ifeq ($(shell test -f .env && echo -n yes),yes)
include .env
endif

ARTIFACT_DIR ?= ./_output

#### Tool Versions ####
# https://github.com/golangci/golangci-lint/releases
GOLINT_VERSION = v1.60.1
NO_DOCKER ?= 0

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif

# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

SRC_IMAGE ?= golang:1.23

GO111MODULE = on
export GO111MODULE

ifeq ($(shell command -v podman > /dev/null 2>&1 ; echo $$? ), 0)
ENGINE=podman
else ifeq ($(shell command -v docker > /dev/null 2>&1 ; echo $$? ), 0)
ENGINE=docker
else
NO_DOCKER=1
endif

FORCE_DOCKER ?= 0
ifeq ($(FORCE_DOCKER), 1)
ENGINE=docker
endif

ifeq ($(NO_DOCKER), 1)
DOCKER_CMD =
else
DOCKER_CMD := $(ENGINE) run --env GO111MODULE=$(GO111MODULE) --env GOLINT_VERSION=$(GOLINT_VERSION) --rm -v "$(PWD)":/go/src/github.com/aleskandro/nextcloud-kobo:Z -w /go/src/github.com/aleskandro/nextcloud-kobo $(SRC_IMAGE)
endif

.PHONY: static
static: fmt vet goimports gosec lint

.PHONY: fmt
fmt:
$(DOCKER_CMD) hack/go-fmt.sh ./

.PHONY: vet
vet:
$(DOCKER_CMD) go vet ./...

.PHONY: lint
lint:
GOLINT_VERSION=$(GOLINT_VERSION) $(DOCKER_CMD) hack/golangci-lint.sh ./...

.PHONY: goimports
goimports:
$(DOCKER_CMD) hack/goimports.sh .

.PHONY: gosec
gosec:
$(DOCKER_CMD) hack/gosec.sh ./...

.PHONY: koboroot
koboroot:
hack/package.sh

.PHONY: unit
unit:
$(DOCKER_CMD) go test -v ./...
Loading

0 comments on commit 7afad5e

Please sign in to comment.