Skip to content

Commit 1c8caff

Browse files
committed
feat: add ci
1 parent 74a1aa7 commit 1c8caff

File tree

9 files changed

+418
-3
lines changed

9 files changed

+418
-3
lines changed

.editorconfig

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = LF
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
indent_style = space
9+
indent_size = 4
10+
11+
[Makefile]
12+
indent_style = tab
13+
14+
[*.md]
15+
trim_trailing_whitespace = false
16+
17+
[*.go]
18+
indent_style = tab
19+
20+
[*.yml]
21+
indent_size = 2
22+
23+
[*.yaml]
24+
indent_size = 2
25+
26+
[*.yml.dist]
27+
indent_size = 2

.github/dependabot.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: gomod
4+
directory: "/"
5+
schedule:
6+
interval: weekly
7+
time: "04:00"
8+
open-pull-requests-limit: 10
9+
assignees:
10+
- euskadi31
11+
- package-ecosystem: "github-actions"
12+
directory: "/"
13+
schedule:
14+
interval: weekly
15+
assignees:
16+
- euskadi31

.github/workflows/codeql-analysis.yml

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ master ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ master ]
20+
schedule:
21+
- cron: '20 20 * * 6'
22+
23+
jobs:
24+
analyze:
25+
name: Analyze
26+
runs-on: ubuntu-latest
27+
permissions:
28+
actions: read
29+
contents: read
30+
security-events: write
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
language: [ 'go' ]
36+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
37+
# Learn more about CodeQL language support at https://git.io/codeql-language-support
38+
39+
steps:
40+
- name: Checkout repository
41+
uses: actions/checkout@v4
42+
43+
# Initializes the CodeQL tools for scanning.
44+
- name: Initialize CodeQL
45+
uses: github/codeql-action/init@v3
46+
with:
47+
languages: ${{ matrix.language }}
48+
# If you wish to specify custom queries, you can do so here or in a config file.
49+
# By default, queries listed here will override any specified in a config file.
50+
# Prefix the list here with "+" to use these queries and those in the config file.
51+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
52+
53+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
54+
# If this step fails, then you should remove it and run the build manually (see below)
55+
- name: Autobuild
56+
uses: github/codeql-action/autobuild@v3
57+
58+
# ℹ️ Command-line programs to run using the OS shell.
59+
# 📚 https://git.io/JvXDl
60+
61+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
62+
# and modify them (or add more) to build your code if your project
63+
# uses a compiled language
64+
65+
#- run: |
66+
# make bootstrap
67+
# make release
68+
69+
- name: Perform CodeQL Analysis
70+
uses: github/codeql-action/analyze@v3

.github/workflows/go.yml

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
name: Go
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
build:
11+
name: Build
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Check out code into the Go module directory
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Go 1.x
18+
uses: actions/setup-go@v5
19+
with:
20+
go-version: "1.x"
21+
id: go
22+
23+
- name: Build
24+
run: go build -race -v ./...
25+
26+
- name: Test
27+
run: go test -race -cover -coverprofile ./coverage.out ./...
28+
29+
- name: Coverage
30+
id: coverage
31+
run: |
32+
go tool cover -func ./coverage.out | tee -a coverage.txt
33+
echo "COVERAGE_CONTENT<<EOF" >> $GITHUB_ENV
34+
cat coverage.txt >> $GITHUB_ENV
35+
echo "EOF" >> $GITHUB_ENV
36+
37+
- uses: actions/github-script@v4
38+
if: github.event_name == 'pull_request'
39+
continue-on-error: true
40+
env:
41+
COVERAGE_CONTENT: "${{ env.COVERAGE_CONTENT }}"
42+
with:
43+
github-token: ${{ secrets.GITHUB_TOKEN }}
44+
script: |
45+
const output = `Code Coverage\n
46+
\`\`\`\n
47+
${process.env.COVERAGE_CONTENT}
48+
\`\`\`
49+
50+
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`;
51+
52+
const response = await github.issues.listComments({
53+
owner: context.repo.owner,
54+
repo: context.repo.repo,
55+
issue_number: context.issue.number,
56+
});
57+
58+
var comments = response.data;
59+
60+
console.log(comments);
61+
62+
if (comments.length > 0) {
63+
comments = comments.filter(comment => comment.body.includes('Code Coverage') && comment.user.type === 'Bot');
64+
}
65+
66+
if (comments.length > 0) {
67+
const comment = comments.shift();
68+
69+
github.issues.updateComment({
70+
issue_number: context.issue.number,
71+
owner: context.repo.owner,
72+
repo: context.repo.repo,
73+
comment_id: comment.id,
74+
body: output
75+
})
76+
} else {
77+
github.issues.createComment({
78+
issue_number: context.issue.number,
79+
owner: context.repo.owner,
80+
repo: context.repo.repo,
81+
body: output
82+
})
83+
}
84+
85+
- name: Benchmark
86+
id: benchmark
87+
run: |
88+
go test -benchmem -bench . | tee -a benchmark.txt
89+
echo "BENCHMARK_CONTENT<<EOF" >> $GITHUB_ENV
90+
cat benchmark.txt >> $GITHUB_ENV
91+
echo "EOF" >> $GITHUB_ENV
92+
93+
- uses: actions/github-script@v4
94+
if: github.event_name == 'pull_request'
95+
continue-on-error: true
96+
env:
97+
BENCHMARK_CONTENT: "${{ env.BENCHMARK_CONTENT }}"
98+
with:
99+
github-token: ${{ secrets.GITHUB_TOKEN }}
100+
script: |
101+
const output = `Benchmark\n
102+
\`\`\`\n
103+
${process.env.BENCHMARK_CONTENT}
104+
\`\`\`
105+
106+
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`;
107+
108+
const response = await github.issues.listComments({
109+
owner: context.repo.owner,
110+
repo: context.repo.repo,
111+
issue_number: context.issue.number,
112+
});
113+
114+
var comments = response.data;
115+
116+
console.log(comments);
117+
118+
if (comments.length > 0) {
119+
comments = comments.filter(comment => comment.body.includes('Benchmark') && comment.user.type === 'Bot');
120+
}
121+
122+
if (comments.length > 0) {
123+
const comment = comments.shift();
124+
125+
github.issues.updateComment({
126+
issue_number: context.issue.number,
127+
owner: context.repo.owner,
128+
repo: context.repo.repo,
129+
comment_id: comment.id,
130+
body: output
131+
})
132+
} else {
133+
github.issues.createComment({
134+
issue_number: context.issue.number,
135+
owner: context.repo.owner,
136+
repo: context.repo.repo,
137+
body: output
138+
})
139+
}
140+
141+
- name: Run golangci-lint
142+
uses: golangci/[email protected]
143+
with:
144+
version: v1.62.0
145+
skip-cache: true
146+
147+
- name: Coveralls
148+
uses: shogo82148/actions-goveralls@v1
149+
with:
150+
path-to-profile: coverage.out

.gitignore

+9-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
build/
1+
.DS_Store
2+
*.out
3+
4+
.vscode/
5+
vendor/
6+
coverage/
7+
build/
8+
9+
*.swp

.golangci.yml

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
run:
2+
concurrency: 4
3+
timeout: 1m
4+
issues-exit-code: 1
5+
tests: false
6+
7+
output:
8+
formats:
9+
- format: colored-line-number
10+
print-issued-lines: true
11+
print-linter-name: true
12+
13+
issues:
14+
exclude-use-default: true
15+
exclude-case-sensitive: false
16+
exclude-dirs-use-default: true
17+
max-issues-per-linter: 50
18+
exclude-generated: strict
19+
exclude-files:
20+
- .*_mock\.go
21+
- mock_.*\.go
22+
- .*/pkg/mod/.*$
23+
- .*/go/src/.*\.go
24+
25+
linters-settings:
26+
errcheck:
27+
check-type-assertions: false
28+
check-blank: false
29+
govet:
30+
disable:
31+
- shadow
32+
revive:
33+
ignore-generated-header: true
34+
severity: warning
35+
gofmt:
36+
simplify: true
37+
gocyclo:
38+
min-complexity: 18
39+
dupl:
40+
threshold: 99
41+
goconst:
42+
min-len: 3
43+
min-occurrences: 2
44+
depguard:
45+
rules:
46+
main:
47+
allow:
48+
- $all
49+
50+
misspell:
51+
locale: US
52+
ignore-words:
53+
- cancelled
54+
goimports:
55+
local-prefixes: go.opentelemetry.io
56+
57+
58+
linters:
59+
disable-all: true
60+
enable:
61+
- errcheck
62+
- goconst
63+
- gocyclo
64+
- gofmt
65+
- revive
66+
- govet
67+
- ineffassign
68+
- misspell
69+
- typecheck
70+
- unconvert
71+
- gosimple
72+
- staticcheck
73+
- unused
74+
- asciicheck
75+
- bodyclose
76+
- dogsled
77+
- durationcheck
78+
- errorlint
79+
- exhaustive
80+
- forbidigo
81+
- forcetypeassert
82+
- gocritic
83+
- godot
84+
- gosec
85+
- nestif
86+
- nilerr
87+
- nlreturn
88+
- noctx
89+
- prealloc
90+
- predeclared
91+
- sqlclosecheck
92+
- whitespace
93+
- wrapcheck
94+
- wsl
95+
fast: false

Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.PHONY: all
2+
all: test
3+
4+
.PHONY: clean
5+
clean:
6+
@go clean -i ./...
7+
8+
.PHONY: test
9+
test:
10+
@go test -race -cover -coverprofile ./coverage.out ./...
11+
12+
.PHONY: cover
13+
cover: test
14+
@echo ""
15+
@go tool cover -func ./coverage.out
16+
17+
.PHONY: bench
18+
bench:
19+
@go test -benchmem -bench=. ./...
20+

0 commit comments

Comments
 (0)