Skip to content

Commit

Permalink
[orc8r][ci] Enforce go fmt on PRs (magma#4149)
Browse files Browse the repository at this point in the history
Signed-off-by: Hunter Gatewood <[email protected]>
  • Loading branch information
hcgatewood authored Jan 20, 2021
1 parent b83f748 commit 51843e3
Show file tree
Hide file tree
Showing 181 changed files with 759 additions and 447 deletions.
64 changes: 46 additions & 18 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,27 @@ executors:
orbs:
artifactory: circleci/[email protected]

python:
commands:
set_version:
parameters:
python_version:
description: Valid Python version to set
type: string
default: "3.7.0"
steps:
- run:
name: Set Python version
command: pyenv global <<parameters.python_version>>

docker:
commands:
install-dc:
parameters:
compose_version:
description: Docker-compose version to install
type: string
default: '1.25.4'
default: "1.25.4"
steps:
- run:
name: Install Docker Compose
Expand Down Expand Up @@ -268,9 +281,7 @@ commands:
echo export AWS_DEFAULT_REGION="us-east-1" >> $BASH_ENV
echo export AWS_ACCESS_KEY_ID="$(printenv MAGMA_DEPLOY_AWS_ACCESS_KEY_ID)" >> $BASH_ENV
echo export AWS_SECRET_ACCESS_KEY="$(printenv MAGMA_DEPLOY_AWS_SECRET_ACCESS_KEY)" >> $BASH_ENV
- run:
name: Select python 3.7.0
command: pyenv global 3.7.0
- python/set_version
- run:
name: Install python prerequisites
command: pip3 install fabric3 jsonpickle requests PyYAML awscli
Expand Down Expand Up @@ -444,16 +455,35 @@ jobs:
- build/determinator:
<<: *all_gateways_build_verify
- docker/install-dc
- run:
name: "Set Python Version"
command: pyenv global 3.7.0
- python/set_version
- run:
command: |
cd ${MAGMA_ROOT}/orc8r/cloud/docker
python3 build.py -t -l
python3 build.py --tests --up
no_output_timeout: 15m
- magma_slack_notify

# Fail if code doesn't pass formatting requirements.
cloud_lint:
machine:
image: ubuntu-1604:201903-01
docker_layer_caching: true
environment:
MAGMA_ROOT: /home/circleci/project
steps:
- checkout
- build/determinator:
<<: *all_gateways_build_verify
- python/set_version
- run:
name: Lint cloud Go code
command: |
cd ${MAGMA_ROOT}/orc8r/cloud/docker
python3 build.py --lint
- magma_slack_notify

# Fail if checked-in generated code doesn't match output from
# generation command.
insync-checkin:
machine:
image: ubuntu-1604:201903-01
Expand All @@ -466,13 +496,11 @@ jobs:
<<: *all_gateways_build_verify
- docker/install-dc
- run: sudo apt-get update
- run:
name: "Set Python Version"
command: pyenv global 3.7.0
- python/set_version
- run:
command: |
cd ${MAGMA_ROOT}/orc8r/cloud/docker
python3 build.py -g
python3 build.py --generate
- run: sudo chown -R circleci $MAGMA_ROOT/*
- run: git add .
- run: git status
Expand All @@ -492,13 +520,11 @@ jobs:
<<: *all_gateways_build_verify
- docker/install-dc
- run: sudo apt-get update
- run:
name: "Set Python Version"
command: pyenv global 3.7.0
- python/set_version
- run:
command: |
cd ${MAGMA_ROOT}/orc8r/cloud/docker
python3 build.py -a --nocache --parallel
python3 build.py --all --nocache --parallel
- tag-push-docker:
project: orc8r
images: "nginx|controller"
Expand Down Expand Up @@ -987,12 +1013,14 @@ workflows:

cloud:
jobs:
- cloud-test
- insync-checkin
- cloud_lint
- cloud-test
- orc8r-build:
requires:
- cloud-test
- insync-checkin
- cloud_lint
- cloud-test

lib_gateway:
jobs:
Expand Down
30 changes: 30 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Ref: https://editorconfig.org/
# IntelliJ-specific: https://blog.jetbrains.com/idea/2019/06/managing-code-style-on-a-directory-level-with-editorconfig/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
ij_visual_guides = 79,140

[{*.go,*.go2}]
indent_style = tab
ij_go_add_leading_space_to_comments = true
ij_go_add_parentheses_for_single_import = true
ij_go_call_parameters_new_line_after_left_paren = true
ij_go_call_parameters_right_paren_on_new_line = true
ij_go_group_current_project_imports = true
ij_go_group_stdlib_imports = true
ij_go_import_sorting = goimports
ij_go_keep_indents_on_empty_lines = false
ij_go_move_all_imports_in_one_declaration = true
ij_go_move_all_stdlib_imports_in_one_group = true
ij_go_remove_redundant_import_aliases = true
ij_go_use_back_quotes_for_imports = false
ij_go_wrap_func_params_newline_after_lparen = true
ij_go_wrap_func_params_newline_before_rparen = true
ij_go_wrap_func_result_newline_after_lparen = true
ij_go_wrap_func_result_newline_before_rparen = true
4 changes: 2 additions & 2 deletions .github/workflows/dco-check.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: DCO check
on:
on:
pull_request:
types:
- opened
Expand All @@ -19,4 +19,4 @@ jobs:
- name: DCO Check
uses: tim-actions/dco@master
with:
commits: ${{ steps.get-pr-commits.outputs.commits }}
commits: ${{ steps.get-pr-commits.outputs.commits }}
16 changes: 8 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
### vagrant ###
# Vagrant
.vagrant
*.retry

### vim ###
# Vim
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
*.un~
Session.vim
.netrwhist
*~

### python ###
# Byte-compiled / optimized / DLL files
# Python: byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# Virtual environments

# Python: virtual environments
.env/
.coverage
.python-version
Expand Down Expand Up @@ -81,15 +81,15 @@ devmand/gateway/cmake-build-debug/
cscope.*
tags

#CI files
# CI files
archives/
test_results_magma_converged_mme.html

#intellij
# IntelliJ
.idea/

# Internal
fb

#MacOS artifacts
# MacOS artifacts
.DS_Store
40 changes: 40 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# golangci-lint settings.
# Ref: https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml

run:
timeout: 7m
skip-dirs:
- '.*/migrations/.*'

linters-settings:
gofmt:
simplify: true
misspell:
locale: US

issues:
exclude-rules:
- linters:
- staticcheck
# Ignore:
# - deprecation warnings
# - unconditional loop termination
text: "SA1019:|SA4004:"

# Ref: https://golangci-lint.run/usage/linters/
linters:
# Whitelist-only (disable default set of linters)
disable-all: true
enable:
- exportloopref
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- misspell
- predeclared
- rowserrcheck
- staticcheck
- typecheck
- unconvert
73 changes: 73 additions & 0 deletions .idea.shared/watcherTasks.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectTasksOptions">
<TaskOptions isEnabled="true">
<option name="arguments" value="-s -w $FilePath$" />
<option name="checkSyntaxErrors" value="true" />
<option name="description" />
<option name="exitCodeBehavior" value="ERROR" />
<option name="fileExtension" value="go" />
<option name="immediateSync" value="false" />
<option name="name" value="gofmt" />
<option name="output" value="$FilePath$" />
<option name="outputFilters">
<array />
</option>
<option name="outputFromStdout" value="false" />
<option name="program" value="gofmt" />
<option name="runOnExternalChanges" value="false" />
<option name="scopeName" value="Project Files" />
<option name="trackOnlyRoot" value="true" />
<option name="workingDir" value="$ProjectFileDir$" />
<envs>
<env name="GOROOT" value="$GOROOT$" />
<env name="GOPATH" value="$GOPATH$" />
<env name="PATH" value="$GoBinDirs$" />
</envs>
</TaskOptions>
<TaskOptions isEnabled="true">
<option name="arguments" value="-w $FilePath$" />
<option name="checkSyntaxErrors" value="true" />
<option name="description" />
<option name="exitCodeBehavior" value="ERROR" />
<option name="fileExtension" value="go" />
<option name="immediateSync" value="false" />
<option name="name" value="goimports" />
<option name="output" value="$FilePath$" />
<option name="outputFilters">
<array />
</option>
<option name="outputFromStdout" value="false" />
<option name="program" value="goimports" />
<option name="runOnExternalChanges" value="false" />
<option name="scopeName" value="Project Files" />
<option name="trackOnlyRoot" value="true" />
<option name="workingDir" value="$ProjectFileDir$" />
<envs>
<env name="GOROOT" value="$GOROOT$" />
<env name="GOPATH" value="$GOPATH$" />
<env name="PATH" value="$GoBinDirs$" />
</envs>
</TaskOptions>
<TaskOptions isEnabled="true">
<option name="arguments" value="fmt $FilePath$" />
<option name="checkSyntaxErrors" value="true" />
<option name="description" />
<option name="exitCodeBehavior" value="ERROR" />
<option name="fileExtension" value="tf" />
<option name="immediateSync" value="false" />
<option name="name" value="terraform fmt" />
<option name="output" value="$FilePath$" />
<option name="outputFilters">
<array />
</option>
<option name="outputFromStdout" value="false" />
<option name="program" value="$TerraformExecPath$" />
<option name="runOnExternalChanges" value="false" />
<option name="scopeName" value="Project Files" />
<option name="trackOnlyRoot" value="true" />
<option name="workingDir" value="" />
<envs />
</TaskOptions>
</component>
</project>
3 changes: 2 additions & 1 deletion .run/go test all.run.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="go test all" type="Multirun" factoryName="Multirun" singleton="false" separateTabs="true" reuseTabsWithFailures="false" startOneByOne="true" markFailedProcess="true" hideSuccessProcess="true" delayTime="3.0">
<configuration default="false" name="go test all" type="Multirun" factoryName="Multirun" singleton="false" separateTabs="true" reuseTabsWithFailures="false" startOneByOne="true" markFailedProcess="true" hideSuccessProcess="true" delayTime="4.0">
<runConfiguration name="go test orc8r" type="Go Test" />
<runConfiguration name="go test orc8r/lib" type="Go Test" />
<runConfiguration name="go test lte" type="Go Test" />
<runConfiguration name="go test feg" type="Go Test" />
<runConfiguration name="go test cwf" type="Go Test" />
Expand Down
11 changes: 11 additions & 0 deletions .run/go test orc8r_lib.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="go test orc8r/lib" type="GoTestRunConfiguration" factoryName="Go Test">
<module name="magma" />
<working_directory value="$PROJECT_DIR$/orc8r/lib/go" />
<framework value="gotest" />
<kind value="DIRECTORY" />
<directory value="$PROJECT_DIR$/orc8r/lib/go" />
<filePath value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
</component>
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ circleci/ @tmdzk @mattymo @119Vik
ci-scripts/ @rdefosse @tmdzk @mattymo @119Vik

*/cloud/ @mpgermano @hcgatewood
.golangci.yml @mpgermano @hcgatewood

orc8r/ @mpgermano @hcgatewood @emakeev
orc8r/tools/packer/ @tmdzk @mattymo @119Vik
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"magma/orc8r/lib/go/metrics"

"github.com/golang/glog"
"github.com/prometheus/client_golang/api/prometheus/v1"
v1 "github.com/prometheus/client_golang/api/prometheus/v1"
)

// APNThroughputCalculation APN throughput calc params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (
vectorReturnClient = &mocks.PrometheusAPI{}
)

// Initalize mocked Prometheus clients
// Initialize mocked Prometheus clients
func init() {
// Query returns error
errClient.On("Query", mock.Anything, mock.Anything, mock.Anything).Return(nil, nil, fmt.Errorf("query error"))
Expand Down Expand Up @@ -114,8 +114,7 @@ func TestXAPCalculation(t *testing.T) {
Value: 1,
Timestamp: 123,
}
var vec model.Vector
vec = []*model.Sample{&sample1}
var vec model.Vector = []*model.Sample{&sample1}

successClient := &mocks.PrometheusAPI{}
successClient.On("Query", mock.Anything, mock.Anything, mock.Anything).Return(vec, nil, nil)
Expand Down
Loading

0 comments on commit 51843e3

Please sign in to comment.