From 8baf29a6b93f3a4d48a1a452b28beb4fc981eb96 Mon Sep 17 00:00:00 2001 From: ccoVeille <3875889+ccoVeille@users.noreply.github.com> Date: Thu, 5 Sep 2024 22:59:17 +0200 Subject: [PATCH] ci: add everything for CI --- .editorconfig | 25 +++++ .github/dependabot.yml | 16 +++ .github/workflows/actions-lint.yaml | 12 +++ .github/workflows/ci.yml | 37 +++++++ .golangci.yml | 156 ++++++++++++++++++++++++++++ .ls-lint.yml | 19 ++++ .markdownlint.yml | 14 +++ .yamllint.yml | 14 +++ 8 files changed, 293 insertions(+) create mode 100644 .editorconfig create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/actions-lint.yaml create mode 100644 .github/workflows/ci.yml create mode 100644 .golangci.yml create mode 100644 .ls-lint.yml create mode 100644 .markdownlint.yml create mode 100644 .yamllint.yml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..f32456b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,25 @@ +# More information about this file +# https://editorconfig.org +root = true + +[*] +charset = utf-8 +end_of_line = lf + +[*.md] +tab_width = 2 +trim_trailing_whitespace = false # can be used for indentation with double spaces +# Not enforced, markdownlint already reports it +#insert_final_newline = true + +[*.{yml,yaml}] +tab_width = 2 +trim_trailing_whitespace = true +# Not enforced, markdownlint already reports it +#insert_final_newline = true + +[*.toml,.ini] +tab_width = 2 +trim_trailing_whitespace = true +insert_final_newline = true + diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..2416fad --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,16 @@ +--- +version: 2 +updates: + # Maintain dependencies for GitHub Actions + # These would open PR, these PR would be tested with the CI + # They will have to be merged manually by a maintainer + - package-ecosystem: github-actions + directory: / + open-pull-requests-limit: 10 # avoid spam, if no one reacts + schedule: + interval: weekly + time: '11:00' + groups: + all: + patterns: + - "*" # Group all updates into a single larger pull request. diff --git a/.github/workflows/actions-lint.yaml b/.github/workflows/actions-lint.yaml new file mode 100644 index 0000000..c2fbe36 --- /dev/null +++ b/.github/workflows/actions-lint.yaml @@ -0,0 +1,12 @@ +--- +name: github-actions-lint +on: push + +jobs: + action-lint: + runs-on: ubuntu-latest + steps: + - name: checkout-action + uses: actions/checkout@v4.1.7 + - name: actionlint + uses: raven-actions/actionlint@v2.0.0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..95aa24a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +--- +name: CI +on: + pull_request: +jobs: + ci-lint: + runs-on: ubuntu-latest + strategy: + # if one fails continues running the others + fail-fast: false + steps: + - name: checkout-action + uses: actions/checkout@v4.1.7 + + - name: yamllint + uses: ibiqlik/action-yamllint@v3 + + - name: typos-action + uses: crate-ci/typos@v1.21.0 + + - name: markdownlint-cli2-action + uses: DavidAnson/markdownlint-cli2-action@v16.0.0 + + - name: editorconfig-checker-action + uses: editorconfig-checker/action-editorconfig-checker@v2 + + go-test: + runs-on: ubuntu-latest + steps: + - name: checkout-action + uses: actions/checkout@v4.1.7 + + - name: Set up Go + uses: actions/setup-go@v5 + + - name: Run go test + run: go test -v ./... \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..55c9e8c --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,156 @@ +--- +# golangci-lint configuration file made by @ccoVeille +# Source: https://github.com/ccoVeille/golangci-lint-config-examples/ +# Author: @ccoVeille +# License: MIT +# Variant: 03-safe +# Version: v1.0.0 +# +linters: + # some linters are enabled by default + # https://golangci-lint.run/usage/linters/ + # + # enable some extra linters + enable: + # Errcheck is a program for checking for unchecked errors in Go code. + - errcheck + + # Linter for Go source code that specializes in simplifying code. + - gosimple + + # Vet examines Go source code and reports suspicious constructs. + - govet + + # Detects when assignments to existing variables are not used. + - ineffassign + + # It's a set of rules from staticcheck. See https://staticcheck.io/ + - staticcheck + + # Fast, configurable, extensible, flexible, and beautiful linter for Go. + # Drop-in replacement of golint. + - revive + + # check imports order and makes it always deterministic. + - gci + + # make sure to use t.Helper() when needed + - thelper + + # mirror suggests rewrites to avoid unnecessary []byte/string conversion + - mirror + + # detect the possibility to use variables/constants from the Go standard library. + - usestdlibvars + + # Finds commonly misspelled English words. + - misspell + + # Checks for duplicate words in the source code. + - dupword + +linters-settings: + gci: # define the section orders for imports + sections: + # Standard section: captures all standard packages. + - standard + # Default section: catchall that is not standard or custom + - default + # linters that related to local tool, so they should be separated + - localmodule + + revive: + rules: + # these are the default revive rules + # you can remove the whole "rules" node if you want + # BUT + # ! /!\ they all need to be present when you want to add more rules than the default ones + # otherwise, you won't have the default rules, but only the ones you define in the "rules" node + + # Blank import should be only in a main or test package, or have a comment justifying it. + - name: blank-imports + + # context.Context() should be the first parameter of a function when provided as argument. + - name: context-as-argument + arguments: + - allowTypesBefore: "*testing.T" + + # Basic types should not be used as a key in `context.WithValue` + - name: context-keys-type + + # Importing with `.` makes the programs much harder to understand + - name: dot-imports + + # Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring. + - name: empty-block + + # for better readability, variables of type `error` must be named with the prefix `err`. + - name: error-naming + + # for better readability, the errors should be last in the list of returned values by a function. + - name: error-return + + # for better readability, error messages should not be capitalized or end with punctuation or a newline. + - name: error-strings + + # report when replacing `errors.New(fmt.Sprintf())` with `fmt.Errorf()` is possible + - name: errorf + + # incrementing an integer variable by 1 is recommended to be done using the `++` operator + - name: increment-decrement + + # highlights redundant else-blocks that can be eliminated from the code + - name: indent-error-flow + + # This rule suggests a shorter way of writing ranges that do not use the second value. + - name: range + + # receiver names in a method should reflect the struct name (p for Person, for example) + - name: receiver-naming + + # redefining built in names (true, false, append, make) can lead to bugs very difficult to detect. + - name: redefines-builtin-id + + # redundant else-blocks that can be eliminated from the code. + - name: superfluous-else + + # prevent confusing name for variables when using `time` package + - name: time-naming + + # warns when an exported function or method returns a value of an un-exported type. + - name: unexported-return + + # spots and proposes to remove unreachable code. also helps to spot errors + - name: unreachable-code + + # Functions or methods with unused parameters can be a symptom of an unfinished refactoring or a bug. + - name: unused-parameter + + # report when a variable declaration can be simplified + - name: var-declaration + + # warns when initialism, variable or package naming conventions are not followed. + - name: var-naming + + dupword: + # Keywords used to ignore detection. + # Default: [] + ignore: + # - "blah" # this will accept "blah blah …" as a valid duplicate word + + misspell: + # Correct spellings using locale preferences for US or UK. + # Setting locale to US will correct the British spelling of 'colour' to 'color'. + # Default ("") is to use a neutral variety of English. + locale: US + + # List of words to ignore + # among the one defined in https://github.com/golangci/misspell/blob/master/words.go + ignore-words: + # - valor + # - and + + # Extra word corrections. + extra-words: + # - typo: "whattever" + # correction: "whatever" diff --git a/.ls-lint.yml b/.ls-lint.yml new file mode 100644 index 0000000..cd4636e --- /dev/null +++ b/.ls-lint.yml @@ -0,0 +1,19 @@ +--- +# ls-lint configuration file. More information on the file format can be found on https://ls-lint.org/ +ls: + .md: screamingsnakecase # README.md or CODE_OF_CONDUCT.md + .OLD: screamingsnakecase # LICENSE.OLD + .good.txt: pascalcase + .bad.txt: pascalcase + .yml: pascalcase + .yaml: pascalcase + +ignore: + # .git folder cannot be linted + - .git + # .github folder contains configuration files with specific name, and should not be linted + - .github + # dot files are usually configuration files with specific name + - .ls-lint.yml + - .markdownlint.yml + - .yamllint.yml diff --git a/.markdownlint.yml b/.markdownlint.yml new file mode 100644 index 0000000..fe687e0 --- /dev/null +++ b/.markdownlint.yml @@ -0,0 +1,14 @@ +--- + +# Default state for all rules +default: true + +MD013: + # Overload the default value (120) + line_length: 200 + +MD033: + allowed_elements: + #
are useful for spoilers + - summary + - details diff --git a/.yamllint.yml b/.yamllint.yml new file mode 100644 index 0000000..f67627c --- /dev/null +++ b/.yamllint.yml @@ -0,0 +1,14 @@ +--- +extends: default +ignore: + # These files are imported by vale from an external repository + .vale/styles/RedHat/ +rules: + line-length: + max: 200 + allow-non-breakable-words: true + allow-non-breakable-inline-mappings: true + truthy: + # the node "on:" present in each GitHub Actions workflow file + ignore: | + .github/