Skip to content

Commit

Permalink
feat: add ci
Browse files Browse the repository at this point in the history
  • Loading branch information
euskadi31 committed Nov 13, 2024
1 parent 74a1aa7 commit 1c8caff
Show file tree
Hide file tree
Showing 9 changed files with 418 additions and 3 deletions.
27 changes: 27 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
root = true

[*]
charset = utf-8
end_of_line = LF
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4

[Makefile]
indent_style = tab

[*.md]
trim_trailing_whitespace = false

[*.go]
indent_style = tab

[*.yml]
indent_size = 2

[*.yaml]
indent_size = 2

[*.yml.dist]
indent_size = 2
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2
updates:
- package-ecosystem: gomod
directory: "/"
schedule:
interval: weekly
time: "04:00"
open-pull-requests-limit: 10
assignees:
- euskadi31
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: weekly
assignees:
- euskadi31
70 changes: 70 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
- cron: '20 20 * * 6'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
150 changes: 150 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
name: Go

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Set up Go 1.x
uses: actions/setup-go@v5
with:
go-version: "1.x"
id: go

- name: Build
run: go build -race -v ./...

- name: Test
run: go test -race -cover -coverprofile ./coverage.out ./...

- name: Coverage
id: coverage
run: |
go tool cover -func ./coverage.out | tee -a coverage.txt
echo "COVERAGE_CONTENT<<EOF" >> $GITHUB_ENV
cat coverage.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- uses: actions/github-script@v4
if: github.event_name == 'pull_request'
continue-on-error: true
env:
COVERAGE_CONTENT: "${{ env.COVERAGE_CONTENT }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `Code Coverage\n
\`\`\`\n
${process.env.COVERAGE_CONTENT}
\`\`\`
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`;
const response = await github.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
var comments = response.data;
console.log(comments);
if (comments.length > 0) {
comments = comments.filter(comment => comment.body.includes('Code Coverage') && comment.user.type === 'Bot');
}
if (comments.length > 0) {
const comment = comments.shift();
github.issues.updateComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id,
body: output
})
} else {
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
}
- name: Benchmark
id: benchmark
run: |
go test -benchmem -bench . | tee -a benchmark.txt
echo "BENCHMARK_CONTENT<<EOF" >> $GITHUB_ENV
cat benchmark.txt >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- uses: actions/github-script@v4
if: github.event_name == 'pull_request'
continue-on-error: true
env:
BENCHMARK_CONTENT: "${{ env.BENCHMARK_CONTENT }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `Benchmark\n
\`\`\`\n
${process.env.BENCHMARK_CONTENT}
\`\`\`
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`;
const response = await github.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
var comments = response.data;
console.log(comments);
if (comments.length > 0) {
comments = comments.filter(comment => comment.body.includes('Benchmark') && comment.user.type === 'Bot');
}
if (comments.length > 0) {
const comment = comments.shift();
github.issues.updateComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id,
body: output
})
} else {
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
}
- name: Run golangci-lint
uses: golangci/[email protected]
with:
version: v1.62.0
skip-cache: true

- name: Coveralls
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: coverage.out
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
build/
.DS_Store
*.out

.vscode/
vendor/
coverage/
build/

*.swp
95 changes: 95 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
run:
concurrency: 4
timeout: 1m
issues-exit-code: 1
tests: false

output:
formats:
- format: colored-line-number
print-issued-lines: true
print-linter-name: true

issues:
exclude-use-default: true
exclude-case-sensitive: false
exclude-dirs-use-default: true
max-issues-per-linter: 50
exclude-generated: strict
exclude-files:
- .*_mock\.go
- mock_.*\.go
- .*/pkg/mod/.*$
- .*/go/src/.*\.go

linters-settings:
errcheck:
check-type-assertions: false
check-blank: false
govet:
disable:
- shadow
revive:
ignore-generated-header: true
severity: warning
gofmt:
simplify: true
gocyclo:
min-complexity: 18
dupl:
threshold: 99
goconst:
min-len: 3
min-occurrences: 2
depguard:
rules:
main:
allow:
- $all

misspell:
locale: US
ignore-words:
- cancelled
goimports:
local-prefixes: go.opentelemetry.io


linters:
disable-all: true
enable:
- errcheck
- goconst
- gocyclo
- gofmt
- revive
- govet
- ineffassign
- misspell
- typecheck
- unconvert
- gosimple
- staticcheck
- unused
- asciicheck
- bodyclose
- dogsled
- durationcheck
- errorlint
- exhaustive
- forbidigo
- forcetypeassert
- gocritic
- godot
- gosec
- nestif
- nilerr
- nlreturn
- noctx
- prealloc
- predeclared
- sqlclosecheck
- whitespace
- wrapcheck
- wsl
fast: false
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.PHONY: all
all: test

.PHONY: clean
clean:
@go clean -i ./...

.PHONY: test
test:
@go test -race -cover -coverprofile ./coverage.out ./...

.PHONY: cover
cover: test
@echo ""
@go tool cover -func ./coverage.out

.PHONY: bench
bench:
@go test -benchmem -bench=. ./...

Loading

0 comments on commit 1c8caff

Please sign in to comment.