Skip to content

Commit

Permalink
add ci and golangci-lint
Browse files Browse the repository at this point in the history
Signed-off-by: Periyasamy Palanisamy <[email protected]>
  • Loading branch information
pperiyasamy committed May 31, 2021
1 parent 14c620e commit 5d8b487
Show file tree
Hide file tree
Showing 18 changed files with 692 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .ci/license/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## Copyright headers for source code
This folder contains the copyright templates for source files of NSM project.

Below is an example of valid copyright header for `.go` files:
```
// Copyright (c) 2020 Doc.ai and/or its affiliates.
//
// Copyright (c) 2020 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
```
Note you can use your company name instead of `Cisco and/or its affiliates`.
Also, source code files can have multi copyright holders, for example:
```
// Copyright (c) 2020 Doc.ai and/or its affiliates.
//
// Copyright (c) 2020 Cisco and/or its affiliates.
//
// Copyright (c) 2020 Red Hat Inc. and/or its affiliates.
//
// Copyright (c) 2020 VMware, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
```
13 changes: 13 additions & 0 deletions .ci/license/template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{copyright-holders}}SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
15 changes: 15 additions & 0 deletions .ci/yamllint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
extends: default

yaml-files:
- '*.yaml'
- '*.yml'

rules:
truthy: disable
# 80 chars should be enough, but don't fail if a line is longer
line-length: disable
comments-indentation:
ignore: .circleci/config.yml

ignore: scripts/aws/aws-k8s-cni.yaml
9 changes: 9 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Please switch to **Preview** and select one of the following links depending on your use-case:

* [Feature](?template=spec.md)
* [Bug](?template=bug.md)
* [Question](?template=question.md)

Once switched to the correct template, keep in mind that switching templates will remove all already entered data within this issue.

Thank you for reaching out!
30 changes: 30 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Expected Behavior

<!--- Please describe the behavior you are expecting -->

## Current Behavior

<!--- What is the current behavior? -->

## Failure Information (for bugs)

<!--- Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template. -->

## Steps to Reproduce

<!--- Please provide detailed steps for reproducing the issue: -->

1. Step 1
2. Step 2
3. You get the idea...

## Context

<!--- Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions. -->

* Kubernetes Version:
* etc.

## Failure Logs

<!--- Please include any relevant log snippets or files here. -->
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Question

<!--- Please describe the behavior you are expecting -->


## Examaples

<!--- Please provide examples related to provided question -->


## Context

<!--- Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions. -->

* Kubernetes Version:
* etc.

## Other artifacts/Logs

<!--- Please include any relevant log snippets or files here. -->
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Overview

<!--- Try to give a general description (optional if it overlaps with the content from the Google Docs file) -->

## Link to the Google Docs document

<!--- Please provide the link to the Google Docs document -->

## References

<!--- If present, you can share links to issues, PRs, etc. -->
26 changes: 26 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!--- Put an `x` in all the boxes that this PR applies -->

## Description
<!--- Provide a general summary of your changes in the Title above -->


## Issue link
<!--- Please link to the issue here. -->


## How Has This Been Tested?
<!--- Provide information on how these changes are testing -->
- [ ] Added unit testing to cover
- [ ] Tested manually
- [ ] Tested by integration testing
- [ ] Have not tested

<!--- Add additional comments about testing if needed. -->

## Types of changes
<!--- What types of changes does your code introduce -->
- [ ] Bug fix
- [ ] New functionallity
- [ ] Documentation
- [ ] Refactoring
- [ ] CI
30 changes: 30 additions & 0 deletions .github/workflows/automerge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: automerge
on:
workflow_run:
types:
- completed
workflows:
- 'ci'
jobs:
automerge:
name: Automerge
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' && github.actor == 'nsmbot' }}
steps:
- name: Check out the code
uses: actions/checkout@v2
- name: Fetch main
run: |
git remote -v
git fetch --depth=1 origin main
- name: Only allow go.mod, go.sum, *.gen.go files
run: |
find . -type f ! -name 'go.mod' ! -name 'go.sum' -exec git diff --exit-code origin/main -- {} +
- name: Merge PR
uses: ridedott/merge-me-action@master
with:
GITHUB_LOGIN: nsmbot
ENABLED_FOR_MANUAL_CHANGES: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MAXIMUM_RETRIES: 25
119 changes: 119 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
name: ci
on: pull_request
jobs:
yamllint:
name: yamllint
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: yaml-lint
uses: ibiqlik/action-yamllint@v1
with:
config_file: .ci/yamllint.yml
strict: true
build-and-test:
name: build and test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v1
with:
go-version: 1.16
- name: Build
run: go build -race ./...
- name: Test
run: go test -race ./...
golangci-lint:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.35.0
excludeFmtErrorf:
name: exclude fmt.Errorf
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Exclude fmt.Errorf
run: |
if grep -r --include=*.go --exclude=*.pb.go fmt.Errorf . ; then
echo "Please use errors.Errorf (or errors.New or errors.Wrap or errors.Wrapf) as appropriate rather than fmt.Errorf"
exit 1
fi
restrictNSMDeps:
name: Restrict dependencies on github.com/networkservicemesh/*
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Restrict dependencies on github.com/networkservicemesh/*
env:
ALLOWED_REPOSITORIES: "sdk, api, sdk-k8s, sdk-sriov, sdk-kernel"
run: |
for i in $(grep github.com/networkservicemesh/ go.mod | grep -v '^module' | sed 's;.*\(github.com\/networkservicemesh\/[^ ]*\).*;\1;g');do
if ! [ "$(echo ${ALLOWED_REPOSITORIES} | grep ${i#github.com/networkservicemesh/})" ]; then
echo Dependency on "${i}" is forbidden
exit 1
fi
done
checkgomod:
name: check go.mod and go.sum
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v1
with:
go-version: 1.16
- run: go mod tidy
- name: Check for changes in go.mod or go.sum
run: |
git diff --name-only --exit-code go.mod || ( echo "Run go tidy" && false )
git diff --name-only --exit-code go.sum || ( echo "Run go tidy" && false )
gogenerate:
name: Check generated files
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: arduino/setup-protoc@master
with:
version: '3.8.0'
- uses: actions/setup-go@v1
with:
go-version: 1.16
- name: Install proto-gen-go
run: go get -u github.com/golang/protobuf/[email protected]
- name: Install go-syncmap
run: go get github.com/searKing/golang/tools/cmd/go-syncmap
- name: Generate files
run: go generate ./...
- name: Check for changes in generated code
run: |
if [[ $(git diff -- '*.gen.go') ]]; then
echo "Run go generate ./..." locally and commit changes
exit 1
fi
excludereplace:
name: Exclude Replace in go.mod
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v2
- name: Exclude replace in go.mod
run: |
grep ^replace go.mod || exit 0
exit 1
Loading

0 comments on commit 5d8b487

Please sign in to comment.