Skip to content

Commit d535b5f

Browse files
authored
feat: add log utility also setup github workflow (#1)
1 parent a5bfd3b commit d535b5f

16 files changed

+1553
-2
lines changed

Diff for: .github/workflows/cla.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: "CLA Assistant"
2+
on:
3+
issue_comment:
4+
types: [created]
5+
pull_request_target:
6+
types: [opened,closed,synchronize]
7+
8+
jobs:
9+
CLAssistant:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: "CLA Assistant"
13+
if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target'
14+
uses: contributor-assistant/[email protected]
15+
env:
16+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17+
# the below token should have repo scope and must be manually added by you in the repository's secret
18+
PERSONAL_ACCESS_TOKEN : ${{ secrets.KUSIONSTACK_BOT_TOKEN }}
19+
with:
20+
path-to-document: 'https://github.com/KusionStack/.github/blob/main/CLA.md' # e.g. a CLA or a DCO document
21+
22+
# branch should not be protected
23+
lock-pullrequest-aftermerge: True
24+
path-to-signatures: 'signatures/version1/cla.json'
25+
remote-organization-name: KusionStack
26+
remote-repository-name: cla.db
27+
branch: 'main'
28+
allowlist: bot*
29+
30+
#below are the optional inputs - If the optional inputs are not given, then default values will be taken
31+
#remote-organization-name: enter the remote organization name where the signatures should be stored (Default is storing the signatures in the same repository)
32+
#remote-repository-name: enter the remote repository name where the signatures should be stored (Default is storing the signatures in the same repository)
33+
#create-file-commit-message: 'For example: Creating file for storing CLA Signatures'
34+
#signed-commit-message: 'For example: $contributorName has signed the CLA in #$pullRequestNo'
35+
#custom-notsigned-prcomment: 'pull request comment with Introductory message to ask new contributors to sign'
36+
#custom-pr-sign-comment: 'The signature to be committed in order to sign the CLA'
37+
#custom-allsigned-prcomment: 'pull request comment when all contributors has signed, defaults to **CLA Assistant Lite bot** All Contributors have signed the CLA.'
38+
#lock-pullrequest-aftermerge: false - if you don't want this bot to automatically lock the pull request after merging (default - true)
39+
#use-dco-flag: true - If you are using DCO instead of CLA
40+

Diff for: .github/workflows/constraint.yaml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Reference from:
2+
# https://github.com/c-bata/go-prompt/blob/master/.github/workflows/test.yml
3+
name: Constraints
4+
on:
5+
pull_request:
6+
types: [opened, edited, synchronize, reopened]
7+
jobs:
8+
# Lints Pull Request commits with commitlint.
9+
#
10+
# Rules can be referenced:
11+
# https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional
12+
CommitLint:
13+
name: Commit Lint
14+
runs-on: ubuntu-latest
15+
if: contains(fromJSON('["pull_request"]'), github.event_name)
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v3
19+
with:
20+
fetch-depth: 0
21+
- uses: wagoid/commitlint-github-action@v5
22+
23+
# Lints Pull Request title, because the title will be used as the
24+
# commit message in branch main.
25+
#
26+
# Configuration detail can be referenced:
27+
# https://github.com/marketplace/actions/pull-request-title-rules
28+
PullRequestTitleLint:
29+
name: Pull Request Title Lint
30+
runs-on: ubuntu-latest
31+
if: contains(fromJSON('["pull_request"]'), github.event_name)
32+
steps:
33+
- uses: deepakputhraya/action-pr-title@master
34+
with:
35+
allowed_prefixes: 'build,chore,ci,docs,feat,fix,perf,refactor,revert,style,test' # title should start with the given prefix
36+
disallowed_prefixes: 'WIP,[WIP]' # title should not start with the given prefix
37+
prefix_case_sensitive: false # title prefix are case insensitive
38+
min_length: 5 # Min length of the title
39+
max_length: 256 # Max length of the title
40+
github_token: ${{ github.token }} # Default: ${{ github.token }}
41+

Diff for: .github/workflows/test.yaml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Reference from:
2+
# https://github.com/c-bata/go-prompt/blob/master/.github/workflows/test.yml
3+
name: Test
4+
on:
5+
pull_request:
6+
branches:
7+
- main
8+
push:
9+
branches:
10+
- main
11+
jobs:
12+
Test:
13+
name: Unit tests with coverage
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
20+
- name: Set up Go 1.22
21+
uses: actions/setup-go@v2
22+
with:
23+
go-version: 1.22.x
24+
cache-dependency-path: |
25+
**/go.sum
26+
**/go.mod
27+
- name: Run tests
28+
env:
29+
GO111MODULE: on
30+
run: make test
31+
- name: Send coverage
32+
uses: shogo82148/[email protected]
33+
with:
34+
path-to-profile: coverage.out
35+
36+
GolangLint:
37+
name: Golang Lint
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v3
42+
with:
43+
fetch-depth: 0
44+
- name: Set up Go 1.22
45+
uses: actions/setup-go@v2
46+
with:
47+
go-version: 1.22.x
48+
- name: golangci-lint
49+
uses: golangci/golangci-lint-action@v3
50+
with:
51+
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
52+
version: v1.56.2

Diff for: .gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
*.out
1616

1717
# Dependency directories (remove the comment below to include it)
18-
# vendor/
18+
vendor/
1919

2020
# Go workspace file
2121
go.work
22+
23+
# IDE workspace file
24+
.idea/

Diff for: .golangci.yml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# This file contains all available configuration options
2+
# with their default values.
3+
# For complete .golangci.yml configuration, reference: https://golangci-lint.run/usage/configuration/#config-file
4+
5+
# options for analysis running
6+
run:
7+
timeout: 10m
8+
9+
linters:
10+
disable-all: true
11+
enable: # please keep this alphabetized
12+
# Don't use soon to deprecated[1] linters that lead to false
13+
# https://github.com/golangci/golangci-lint/issues/1841
14+
# - deadcode
15+
# - structcheck
16+
# - varcheck
17+
- ineffassign
18+
- staticcheck
19+
- unused
20+
- gosimple
21+
- govet
22+
- gofumpt
23+
- bodyclose
24+
# - depguard
25+
- dogsled
26+
- dupl
27+
- exportloopref
28+
- gocritic
29+
# - misspell
30+
- nolintlint
31+
- prealloc
32+
- predeclared
33+
- stylecheck
34+
- tparallel
35+
- typecheck
36+
- unconvert
37+
- whitespace
38+
# - wsl
39+
# - revive
40+
# - unparam
41+
# - gomnd
42+
# - gosec
43+
# - exhaustive
44+
# - thelper
45+
# - goconst
46+
# - errcheck
47+
48+
linters-settings:
49+
gofumpt:
50+
# Select the Go version to target. The default is `1.15`.
51+
lang-version: "1.22"
52+
# Choose whether or not to use the extra rules that are disabled
53+
# by default
54+
extra-rules: false
55+
56+
issues:
57+
exclude:
58+
- "G306: Expect WriteFile permissions to be 0600 or less"
59+
- "ST1018: string literal contains Unicode control characters, consider using escape sequences instead"
60+
- "ifElseChain: rewrite if-else to switch statement"
61+
- "S1000: should use for range instead of for { select {} }"
62+
- "SA4004: the surrounding loop is unconditionally terminated"
63+
- "copylocks: call of c\\.Post copies lock value: kcl-lang\\.io/kcl-go/pkg/spec/gpyrpc\\.Ping_Args contains google\\.golang\\.org/protobuf/internal/impl\\.MessageState contains sync\\.Mutex"

Diff for: Makefile

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Copyright 2024 KusionStack Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# It's necessary to set this because some environments don't link sh -> bash.
16+
SHELL := /usr/bin/env bash
17+
18+
# Define variables so `make --warn-undefined-variables` works.
19+
PRINT_HELP ?=
20+
21+
define VET_HELP_INFO
22+
# Run 'go vet' command to vet Go code.
23+
#
24+
# Example:
25+
# make vet
26+
endef
27+
.PHONY: vet
28+
ifeq ($(PRINT_HELP),y)
29+
vet:
30+
@echo "$$VET_HELP_INFO"
31+
else
32+
vet:
33+
go vet ./...
34+
endif
35+
36+
define FMT_HELP_INFO
37+
# Run 'go fmt' command to format Go code.
38+
#
39+
# Example:
40+
# make fmt
41+
endef
42+
.PHONY: fmt
43+
ifeq ($(PRINT_HELP),y)
44+
fmt:
45+
@echo "$$FMT_HELP_INFO"
46+
else
47+
fmt:
48+
go fmt ./...
49+
endif
50+
51+
define TEST_HELP_INFO
52+
# Build and run tests.
53+
#
54+
# Example:
55+
# make test
56+
endef
57+
.PHONY: test
58+
ifeq ($(PRINT_HELP),y)
59+
test:
60+
@echo "$$TEST_HELP_INFO"
61+
else
62+
test: fmt vet
63+
go test ./... -coverprofile coverage.out
64+
endif

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# component-base
2-
Shared code for KusionStack core components.
2+
3+
This repo contains common code shared by all KusionStack core components.

Diff for: commitlint.config.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This file is the configuration file of [commitlint](https://commitlint.js.org/#/).
2+
//
3+
// Rules can be referenced:
4+
// https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional
5+
const Configuration = {
6+
extends: ['@commitlint/config-conventional'],
7+
8+
rules: {
9+
'body-max-line-length': [2, 'always', 500],
10+
},
11+
};
12+
13+
module.exports = Configuration;

Diff for: go.mod

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module kusionstack.io/component-base
2+
3+
go 1.22.1
4+
5+
require (
6+
github.com/spf13/cobra v1.8.0
7+
go.uber.org/zap v1.27.0
8+
gopkg.in/natefinch/lumberjack.v2 v2.2.1
9+
)
10+
11+
require (
12+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
13+
github.com/spf13/pflag v1.0.5 // indirect
14+
go.uber.org/multierr v1.10.0 // indirect
15+
)

Diff for: go.sum

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
2+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
5+
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
6+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
7+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
8+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
9+
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
10+
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
11+
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
12+
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
13+
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
14+
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
15+
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
16+
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
17+
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
18+
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
19+
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
20+
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
21+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
22+
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
23+
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
24+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
25+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)