Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/workflows/code-health-foas-lib.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: 'Code Health Foas Library'
on:
push:
branches:
- main
paths:
- 'tools/foas/**'
- '.github/workflows/code-health-foas-lib.yml'
pull_request:
branches:
- main
paths:
- 'tools/foas/**'
- '.github/workflows/code-health-foas-lib.yml'
workflow_dispatch: {}
workflow_call: {}

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
- name: Install Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c
with:
go-version-file: 'tools/foas/go.mod'
- name: Build library
working-directory: tools/foas
run: make build
unit-tests:
needs: build
env:
COVERAGE: coverage.out
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
- name: Install Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c
with:
go-version-file: 'tools/foas/go.mod'
- name: Run unit tests
working-directory: tools/foas
run: make unit-test
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
with:
sparse-checkout: |
.github
tools
- name: Install Go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c
with:
go-version-file: 'tools/foas/go.mod'
cache: false # see https://github.com/golangci/golangci-lint-action/issues/807
- name: golangci-lint
uses: golangci/golangci-lint-action@82606bf257cbaff209d206a39f5134f0cfbfd2ee
with:
version: v2.10.1
working-directory: tools/foas
137 changes: 137 additions & 0 deletions tools/foas/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
version: "2"
run:
modules-download-mode: readonly
tests: true
linters:
default: none
enable:
- copyloopvar
- dogsled
- errcheck
- errorlint
- exhaustive
- funlen
- gocritic
- godot
- goprintffuncname
- gosec
- govet
- ineffassign
- lll
- makezero
- misspell
- nakedret
- noctx
- nolintlint
- perfsprint
- prealloc
- predeclared
- revive
- rowserrcheck
- staticcheck
- testifylint
- thelper
- unconvert
- unused
- whitespace
# don't enable:
# - deadcode
# - varcheck
# - structcheck
# - depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
# - gocyclo # we already have funlen lint
# - dupl # we have a lot of duplicate test cases
# - gochecknoinits # we need the init function for the provider
# - gochecknoglobals # we need some global variables
# - unparam # Forces to create global variables when one variable is repeated in different functions
# - goerr113 # It does not allow you to return an error, you need to save the error in a variable to do it
# - goconst
# - gocognit
settings:
funlen:
lines: 360
statements: 120
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
govet:
enable:
- shadow
lll:
line-length: 150
misspell:
locale: US
nestif:
min-complexity: 7
revive:
severity: warning
rules:
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: defer
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: early-return
- name: errorf
- name: exported
- name: import-shadowing
- name: indent-error-flow
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: struct-tag
- name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
- name: unused-receiver
- name: constant-logical-expr
- name: confusing-naming
- name: unnecessary-stmt
- name: use-any
- name: imports-blocklist
arguments:
- github.com/pkg/errors
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
enable:
- gci
- gofmt
- goimports
settings:
gci:
sections:
- standard
- default
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
37 changes: 37 additions & 0 deletions tools/foas/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# A Self-Documenting Makefile: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html

GOLANGCI_VERSION=v2.10.1
TEST_CMD?=go test
COVERAGE=coverage.out

export GO111MODULE := on

.PHONY: deps
deps: ## Download go module dependencies
@echo "==> Installing go.mod dependencies..."
go mod download
go mod tidy

.PHONY: devtools
devtools: ## Install dev tools
@echo "==> Installing dev tools..."
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin $(GOLANGCI_VERSION)

.PHONY: fmt
fmt: ### Format all go files with goimports and gofmt
find . -name "*.go" -exec gofmt -w "{}" \;
find . -name "*.go" -exec goimports -l -w "{}" \;

.PHONY: build
build: ## Build all packages in the library
@echo "==> Building foas library"
go build ./...

.PHONY: lint
lint: ## Run linter
golangci-lint run

.PHONY: unit-test
unit-test: ## Run unit-tests
@echo "==> Running unit tests..."
$(TEST_CMD) -race -cover ./...
6 changes: 6 additions & 0 deletions tools/foas/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Package foas is the root of the MongoDB OpenAPI FOAS library module.
//
// Reusable Go packages extracted from tools/cli live under this module
// (github.com/mongodb/openapi/tools/foas) and are consumed by tools/cli via
// the go.work workspace and by external repositories via published version tags.
package foas
5 changes: 5 additions & 0 deletions tools/foas/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/mongodb/openapi/tools/foas

go 1.26

toolchain go1.26.0
6 changes: 6 additions & 0 deletions tools/go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go 1.26

use (
./cli
./foas
)
Loading