Skip to content

Commit

Permalink
Merge pull request #31 from skatsaounis/add-ci
Browse files Browse the repository at this point in the history
Add CI and fix detected issues
  • Loading branch information
skatsaounis committed Dec 8, 2023
2 parents 11c6eca + 6d6b134 commit d14f7d3
Show file tree
Hide file tree
Showing 94 changed files with 1,545 additions and 937 deletions.
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# See GitHub's documentation for more information on this file:
# https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/configuration-options-for-dependency-updates
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Terraform Provider release workflow.
name: Release

# This GitHub action creates a release when a tag that matches the pattern
# "v*" (e.g. v0.1.0) is created.
on:
push:
tags:
- 'v*'

# Releases need permissions to read and write the repository contents.
# GitHub considers creating releases and uploading assets as writing contents.
permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# Allow goreleaser to access older tag information.
fetch-depth: 0
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache: true
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
id: import_gpg
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
args: release --rm-dist
env:
# GitHub sets the GITHUB_TOKEN secret automatically.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
65 changes: 65 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# gomaasclient testing workflow.
name: Tests

# This GitHub action runs your tests for each pull request and push.
# Optionally, you can turn it on using a schedule for regular testing.
on:
pull_request:
paths-ignore:
- 'README.md'
push:
branches:
- "master"
paths-ignore:
- 'README.md'

# Testing only needs permissions to read the repository contents.
permissions:
contents: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.20'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.55
# Note: By default, the `.golangci.yml` file should be at the root of the repository.
# The location of the configuration file can be changed by using `--config=`
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0
skip-cache: true
install-mode: binary

# Ensure project builds before running testing matrix
build:
name: Build
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache: true
- run: go mod download
- run: go build -v .

# Run unit tests
test:
name: gomaasclient Unit Tests
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
cache: true
- run: make test
239 changes: 239 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
# This file contains all available configuration options
# https://golangci-lint.run/usage/linters/

run:
timeout: 5m
issues-exit-code: 1
tests: true
# Enables skipping of directories:
# - vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true

# Which files to skip: they will be analyzed, but issues from them won't be reported.
# Default value is empty list,
# but there is no need to include all autogenerated files,
# we confidently recognize autogenerated files.
# If it's not please let us know.
# "/" will be replaced by current OS file path separator to properly work on Windows.
skip-files:
- ".*\\.my\\.go$"
- lib/bad.go

# If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
# to go.mod are needed. This setting is most useful to check that go.mod does
# not need updates, such as in a continuous integration and testing system.
# If invoked with -mod=vendor, the go command assumes that the vendor
# directory holds the correct copies of dependencies and ignores
# the dependency descriptions in go.mod.
#
# Allowed values: readonly|vendor|mod
# By default, it isn't set.
modules-download-mode: readonly

# Allow multiple parallel golangci-lint instances running.
# If false (default) - golangci-lint acquires file lock on start.
allow-parallel-runners: false

# output configuration options
output:
# Format: colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions|teamcity
#
# Multiple can be specified by separating them by comma, output can be provided
# for each of them by separating format name and path by colon symbol.
# Output path can be either `stdout`, `stderr` or path to the file to write to.
# Example: "checkstyle:report.xml,json:stdout,colored-line-number"
#
# Default: colored-line-number
format: colored-line-number

# Print lines of code with issue.
# Default: true
print-issued-lines: true

# Print linter name in the end of issue text.
# Default: true
print-linter-name: true

# Make issues output unique by line.
# Default: true
uniq-by-line: true

# Add a prefix to the output file references.
# Default is no prefix.
path-prefix: ""

# Sort results by: filepath, line and column.
sort-results: false

linters:
disable-all: true
enable:
- dupl
- errcheck
- exportloopref
- gocritic
- gofmt
- goimports
- gosec
- gosimple
- govet
- nilerr
- nilnil
- noctx
- nolintlint
- nonamedreturns
- revive
- staticcheck
- stylecheck
- tagliatelle
- unused
- whitespace
- wsl
- zerologlint

linters-settings:
errcheck:
check-type-assertions: true
check-blank: true
gosimple:
checks: ["all"]
govet:
enable-all: true
nolintlint:
require-explanation: true
require-specific: true
revive:
ignore-generated-header: true
rules:
- name: time-equal
severity: warning
disabled: false
- name: errorf
severity: warning
disabled: false
- name: context-as-argument
severity: warning
disabled: false
- name: error-return
severity: warning
disabled: false
- name: datarace
severity: warning
disabled: false
staticcheck:
checks: ["all"]
stylecheck:
checks: ["all"]
tagliatelle:
case:
rules:
json: snake
yaml: snake

issues:
# List of regexps of issue texts to exclude.
#
# But independently of this option we use default exclude patterns,
# it can be disabled by `exclude-use-default: false`.
# To list all excluded by default patterns execute `golangci-lint run --help`
#
# Default: https://golangci-lint.run/usage/false-positives/#default-exclusions
exclude: []

# Excluding configuration per-path, per-linter, per-text and per-source
exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go
linters:
- gocyclo
- errcheck
- dupl
- gosec

# Exclude known linters from partially hard-vendored code,
# which is impossible to exclude via `nolint` comments.
# `/` will be replaced by current OS file path separator to properly work on Windows.

# Exclude `lll` issues for long lines with `go:generate`.
- linters:
- lll
source: "^//go:generate "

- path: internal/
text: "ST1000:"
linters:
- stylecheck

- path: internal/
text: "package-comments:"
linters:
- revive

- path: internal/
text: "exported:"
linters:
- revive

- path: main\.go
text: "package-comments:"
linters:
- revive

- path: _test\.go
text: "fieldalignment:"
linters:
- govet
# Independently of option `exclude` we use default exclude patterns,
# it can be disabled by this option.
# To list all excluded by default patterns execute `golangci-lint run --help`.
# Default: true.
exclude-use-default: false

# If set to true exclude and exclude-rules regular expressions become case-sensitive.
# Default: false
exclude-case-sensitive: false

max-same-issues: 0

# Show only new issues: if there are unstaged changes or untracked files,
# only those changes are analyzed, else only changes in HEAD~ are analyzed.
# It's a super-useful option for integration of golangci-lint into existing large codebase.
# It's not practical to fix all existing issues at the moment of integration:
# much better don't allow issues in new code.
#
# Default: false.
new: false

# Fix found issues (if it's supported by the linter).
fix: false

severity:
# Set the default severity for issues.
#
# If severity rules are defined and the issues do not match or no severity is provided to the rule
# this will be the default severity applied.
# Severities should match the supported severity names of the selected out format.
# - Code climate: https://docs.codeclimate.com/docs/issues#issue-severity
# - Checkstyle: https://checkstyle.sourceforge.io/property_types.html#SeverityLevel
# - GitHub: https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message
# - TeamCity: https://www.jetbrains.com/help/teamcity/service-messages.html#Inspection+Instance
#
# Default value is an empty string.
default-severity: error

# If set to true `severity-rules` regular expressions become case-sensitive.
# Default: false
case-sensitive: true

# When a list of severity rules are provided, severity information will be added to lint issues.
# Severity rules have the same filtering capability as exclude rules
# except you are allowed to specify one matcher per severity rule.
# Only affects out formats that support setting severity information.
#
# Default: []
rules:
- linters:
- dupl
severity: info
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,14 @@ TEST?=$$(go list ./... | grep -v 'vendor')
.PHONY: test
test:
go test $(TEST) -v $(TESTARGS) -timeout=5m -parallel=4

.PHONY: lint
lint: lint-go

.PHONY: lint-go
lint-go:
golangci-lint run $(if $(LINT_AUTOFIX),--fix,) ./...

.PHONY: lint-go-fix
lint-go-fix: LINT_AUTOFIX=true
lint-go-fix: lint-go
8 changes: 5 additions & 3 deletions api/api.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/*Package api defines an interface to each MaaS API endpoint.
/*
Package api defines an interface to each MAAS API endpoint.
Each interface correlates to one endpoint, such as Subnets for the Subnets
endpoint (ie /subnets) and Subnet for the Subnet endpoint (eg subnets/<subnet_id>).
API clients are expected to implement these interfaces to provide a normalized way
of accessing the MaaS API with normalized results (eg the types defined in the
of accessing the MAAS API with normalized results (eg the types defined in the
endpoint package).
Some endpoint operations require multiple parameters, such as the Rack Controllers
GET operation, which takes a number of QSP that can be used to filter results. These
parameters are encapsulated in the params subpackage, providing a quick reference
for performing API operations.*/
for performing API operations.
*/
package api
Loading

0 comments on commit d14f7d3

Please sign in to comment.