Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and CI #2

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
labels:
- "chore"
- "patch"
assignees:
- "eleby"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
labels:
- "chore"
- "patch"
assignees:
- "eleby"
70 changes: 70 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Lint
on:
push:
branches:
- 'main'
- 'master'
pull_request:
types: [opened, synchronize, reopened]
branches:
- '*'
jobs:
build:
strategy:
fail-fast: false
max-parallel: 2
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
name: Lint
steps:
- name: Set up go
uses: actions/setup-go@v2
with:
go-version: '1.16'

- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0
- name: Vet
run: |
make vet

- name: Golangci-lint
uses: golangci/[email protected]
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: latest
# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true

# Optional: if set to true then the action will use pre-installed Go.
skip-go-installation: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
skip-build-cache: true


- name: Install GoReleaser
uses: goreleaser/goreleaser-action@v2
if: success()
with:
version: latest
install-only: true

- name: Run GoReleaser snapshot
if: success()
run: |
make release-local-snapshot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67 changes: 67 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Lint & Test & Build & Release

on:
push:
tags:
- 'v*'
branches:
- "!*"

jobs:
build:
runs-on: ubuntu-latest
name: Lint & Test & Build & Release
steps:
- name: Set up go
uses: actions/setup-go@v2
with:
go-version: '1.16'

- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0

- name: Vet
run: |
make vet
- name: Lint
uses: golangci/[email protected]
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: latest
# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true

# Optional: if set to true then the action will use pre-installed Go.
skip-go-installation: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
skip-build-cache: true

- name: Install GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
install-only: true

- name: Run GoReleaser
if: success()
run: |
make release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Clear
if: always() && startsWith(github.ref, 'refs/tags/v')
run: |
rm -f ${HOME}/.docker/config.json
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Created by .ignore support plugin (hsz.mobi)
### Go template
# 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/
\tools/vendor/

\.idea/

\dist/

\.vscode/
\bin/

.DS_Store
32 changes: 32 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
linters:
disable-all: true
enable:
- errcheck
- gofmt
- golint
- goimports

linters-settings:
errcheck:
check-type-assertions: true
check-blank: true
gofmt:
simplify: true
golint:
min-confidence: 0
goimports:
local-prefixes: github.com/eleby/

run:
issues-exit-code: 0
tests: true
skip-dirs:
- vendor/
skip-files:
- \.pb\.go$

issues:
exclude-use-default: false
exclude:
# for "public interface + private struct implementation" cases only!
- exported func * returns unexported type *, which can be annoying to use
73 changes: 73 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
release:
github:
owner: eleby
name: pixelizer

env:
- GO111MODULE=on
- GOPROXY=https://goproxy.io
before:
hooks:
- go mod tidy -v

builds:
- id: cli
binary: pixelizer
goos:
- linux
- darwin
- windows
goarch:
- 386
- amd64
- arm
- arm64
mod_timestamp: '{{ .CommitTimestamp }}'
env:
- CGO_ENABLED=0
main: ./cmd/pixelizer
flags:
- -trimpath
ldflags:
- -s -w -X main.version={{ .Version }} -X main.commit={{ .FullCommit }} -X main.date={{ .Date }} -X main.goversion={{ .Env.GOVERSION }}

archives:
- id: cli
builds:
- cli
format: tar.gz
wrap_in_directory: true
format_overrides:
- goos: windows
format: zip
replacements:
amd64: 64-bit
386: 32-bit
darwin: macOS
linux: Tux
name_template: "{{ .Binary }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
files:
- LICENSE
- README.md
checksum:
name_template: "{{ .ProjectName }}-{{ .Version }}-checksums.txt"

snapshot:
name_template: SNAPSHOT-{{ .Commit }}

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
- "^dev:"
- "README"
- "^readme"
- "^scripts"
- "scripts:"
- Merge pull request
- Merge branch
- Rebase on master
- "^Makefile"
- "goreleaser"
74 changes: 74 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
NAME=pixelizer

SHELL := env DOCKER_REPO=$(DOCKER_REPO) $(SHELL)
DOCKER_REPO?=eu.gcr.io/melsoft-infra
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know much about dockers and makefiles, but doesn't this mean we won't be able to compile if this docker repo is down someday ? Also, it seems this repo has the name of your company. I don't know if it is relevant to use your company's docker repo here.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mark this as resolved please provide an answer about it so I can know if you will fix it


SHELL := env VERSION=$(VERSION) $(SHELL)
VERSION ?= $(shell date -u +%Y%m%d.%H.%M.%S)


# COLORS
GREEN := $(shell tput -Txterm setaf 2)
YELLOW := $(shell tput -Txterm setaf 3)
WHITE := $(shell tput -Txterm setaf 7)
RESET := $(shell tput -Txterm sgr0)


TARGET_MAX_CHAR_NUM=20


define colored
@echo '${GREEN}$1${RESET}'
endef

## Show help
help:
${call colored, help is running...}
@echo 'link this Makefile from scripts dir to core root'
@echo ''
@echo 'Usage:'
@echo ' ${YELLOW}make${RESET} ${GREEN}<target>${RESET}'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^## (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \
printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)

## vet project
vet:
${call colored, vet is running...}
./scripts/vet.sh
.PHONY: vet

## Compile executable
compile:
${call colored, compile is running...}
./scripts/compile.sh
.PHONY: compile

## Release
release:
./scripts/release.sh
.PHONY: release

## Release local snapshot
release-local-snapshot:
${call colored, release is running...}
./scripts/release-local-snapshot.sh
.PHONY: release-local-snapshot

## Installs tools from vendor.
install-tools: sync-vendor
./scripts/install-tools.sh
.PHONY: install-tools

## Sync vendor of root project and tools.
sync-vendor:
./scripts/sync-vendor.sh
.PHONY: sync-vendor
10 changes: 7 additions & 3 deletions main/console.go → cmd/pixelizer/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import (
)

const (
NONE = iota
DEBUG = iota
INFO = iota
// NONE means no log level set.
NONE = iota
// DEBUG means debug log level.
DEBUG
// INFO means info log level.
INFO
)

// LogLevel is level of log output.
var LogLevel = NONE

func param(index int) int {
Expand Down
Loading