diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 161bdfd5..2d5a5fa7 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -25,11 +25,42 @@ jobs: - uses: actions/checkout@v2 - name: shellcheck uses: fkautz/shell-linter@v1.0.1 + build: + name: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v1 + with: + go-version: 1.13.4 + - run: | + go build -race ./... + build-win: + name: build-win + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v1 + with: + go-version: 1.13.4 + - run: | + go build -race ./... + build-osx: + name: build-osx + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v1 + with: + go-version: 1.13.4 + - run: | + go build -race ./... golangci-lint: name: golangci-lint runs-on: ubuntu-latest env: - GOLANGCI_LINT_CONTAINER: golangci/golangci-lint:v1.28.1 + GOLANGCI_LINT_CONTAINER: golangci/golangci-lint:v1.28.3 + if: github.repository != 'networkservicemesh/cmd-template' steps: - name: Check out code into the Go module directory uses: actions/checkout@v2 @@ -58,7 +89,7 @@ jobs: - name: Restrict dependencies on github.com/networkservicemesh/* run: | for i in $(grep github.com/networkservicemesh/ go.mod |grep -v '^module' | sed 's;.*\(github.com\/networkservicemesh\/[a-zA-z\/]*\).*;\1;g' | sort -u);do - if [ "${i}" != "github.com/networkservicemesh/sdk-vppagent" ] && [ "${i}" != "github.com/networkservicemesh/sdk" ] && [ "${i}" != "github.com/networkservicemesh/api" ]; then + if [ "${i}" != "github.com/networkservicemesh/sdk" ] && [ "${i}" != "github.com/networkservicemesh/api" ]; then echo Dependency on "${i}" is forbidden exit 1 fi @@ -77,20 +108,29 @@ jobs: 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 ) - license: - name: license header check + + 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.13.4 - - name: Install go-header - run: 'go get github.com/denis-tingajkin/go-header@v0.2.2' - - name: Run go-header + go-version: 1.13 + - name: Install proto-gen-go + run: go get -u github.com/golang/protobuf/protoc-gen-go@v1.3.3 + - name: Install proto-gen-go + 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: | - eval $(go env) - ${GOPATH}/bin/go-header + git diff -- '*.pb.go' || ( echo "Rerun go generate ./... locally and resubmit" && false ) + git diff -- '*.gen.go' || ( echo "Rerun go generate ./... locally and resubmit" && false ) + excludereplace: name: Exclude Replace in go.mod runs-on: ubuntu-latest @@ -106,26 +146,19 @@ jobs: runs-on: ubuntu-latest steps: - run: printenv - gogenerate: - name: gogenerate + docker: + name: Docker Build & Test runs-on: ubuntu-latest + if: github.repository != 'networkservicemesh/cmd-template' steps: - uses: actions/checkout@v2 - uses: actions/setup-go@v1 with: go-version: 1.13.4 - - name: Generate files - run: go generate ./... - - name: Check for changes in generated code - run: | - git diff -- internal/imports/imports.go || ( echo "Rerun go generate ./... locally and resubmit" && false ) - docker: - name: Docker Build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - run: docker build . - - run: docker run --rm $(docker build -q --target test .) + - name: Build container + run: docker build . + - name: Run tests + run: docker run --rm $(docker build -q . --target test) - name: Find merged PR if: github.event_name == 'push' && github.ref == 'refs/heads/master' uses: jwalton/gh-find-current-pr@v1 @@ -142,11 +175,37 @@ jobs: pr-${{ steps.findPr.outputs.pr }} commit-${{ github.sha }} latest + pushImage: + name: Push docker image + runs-on: ubuntu-latest + env: + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + DOCKER_USER: ${{ secrets.DOCKER_LOGIN }} + TAG: master + ORG: networkservicemeshci + CGO_ENABLED: 0 + NAME: ${{ github.event.repository.name }} + needs: + - automerge + if: github.actor == 'nsmbot' && github.base_ref == 'master' && github.event_name == 'pull_request' && github.repository != 'networkservicemesh/cmd-template' + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v1 + with: + go-version: 1.13.4 + - name: Build ${NAME} image + run: docker build . -t "${ORG}/${NAME}:${TAG}" --target runtime + - name: Push ${NAME} image + run: | + docker login -u $DOCKER_USER -p $DOCKER_PASSWORD + docker push "${ORG}/${NAME}:${TAG}" + docker image rm "${ORG}/${NAME}:${TAG}" automerge: name: automerge runs-on: ubuntu-latest needs: + - build - docker if: github.actor == 'nsmbot' && github.base_ref == 'master' && github.event_name == 'pull_request' steps: @@ -156,9 +215,8 @@ jobs: run: | git remote -v git fetch --depth=1 origin master - - name: Only allow go.mod and go.sum changes - run: | - find . -type f ! -name 'go.mod' ! -name 'go.sum' -exec git diff --exit-code origin/master -- {} + + - name: NSMBot should update only config files + run: find . -type f ! -name 'go.mod' ! -name 'go.sum' ! -name '*.yaml' ! -name '*.yml' ! -name '*.txt' ! -name '*.md' ! -name '*.conf' -exec git diff --exit-code origin/master -- {} + - name: Automerge nsmbot PR uses: ridedott/merge-me-action@master with: diff --git a/.github/workflows/docker-push.yaml b/.github/workflows/docker-push.yaml new file mode 100644 index 00000000..3f35b8a2 --- /dev/null +++ b/.github/workflows/docker-push.yaml @@ -0,0 +1,30 @@ +--- +name: push +on: + push: + branches: + - master +jobs: + pushImage: + name: Push docker image + runs-on: ubuntu-latest + env: + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + DOCKER_USER: ${{ secrets.DOCKER_LOGIN }} + TAG: master + ORG: networkservicemeshci + CGO_ENABLED: 0 + NAME: ${{ github.event.repository.name }} + if: github.repository != 'networkservicemesh/cmd-template' + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v1 + with: + go-version: 1.13.4 + - name: Build ${NAME} image + run: docker build . -t "${ORG}/${NAME}:${TAG}" --target runtime + - name: Push ${NAME} image + run: | + docker login -u $DOCKER_USER -p $DOCKER_PASSWORD + docker push "${ORG}/${NAME}:${TAG}" + docker image rm "${ORG}/${NAME}:${TAG}" diff --git a/.github/workflows/update-cmd-repositories.yaml b/.github/workflows/update-cmd-repositories.yaml new file mode 100644 index 00000000..d11bbb9f --- /dev/null +++ b/.github/workflows/update-cmd-repositories.yaml @@ -0,0 +1,61 @@ +--- +name: Update dependent repositories +on: + push: + branches: + - master + +jobs: + update-dependent-repositories: + strategy: + matrix: + repository: [cmd-registry-proxy-dns, cmd-nsc, cmd-registry-memory, cmd-nsmgr] + name: Update ${{ matrix.repository }} + runs-on: ubuntu-latest + if: github.repository == 'networkservicemesh/cmd-template' + steps: + - name: Checkout ${{ github.repository }} + uses: actions/checkout@v2 + with: + path: ${{ github.repository }} + repository: ${{ github.repository }} + token: ${{ secrets.NSM_BOT_GITHUB_TOKEN }} + - name: Find merged PR + uses: jwalton/gh-find-current-pr@v1 + id: findPr + with: + github-token: ${{ github.token }} + - name: Create commit message + working-directory: ${{ github.repository }} + run: | + echo "Update common CI files to latest version from ${{ github.repository }}@master ${{ github.repository }}#${{ steps.findPr.outputs.pr }}" >> /tmp/commit-message + echo "" >> /tmp/commit-message + echo "${{ github.repository }} PR link: https://github.com/${{ github.repository }}/pull/${{ steps.findPr.outputs.pr }}" >> /tmp/commit-message + echo "" >> /tmp/commit-message + echo "${{ github.repository }} commit message:" >> /tmp/commit-message + git log -1 >> /tmp/commit-message + echo "Commit Message:" + cat /tmp/commit-message + - name: Checkout networkservicemesh/${{ matrix.repository }} + uses: actions/checkout@v2 + with: + path: networkservicemesh/${{ matrix.repository }} + repository: networkservicemesh/${{ matrix.repository }} + token: ${{ secrets.NSM_BOT_GITHUB_TOKEN }} + - uses: actions/setup-go@v1 + with: + go-version: 1.13.4 + - name: Push update to the ${{ matrix.repository }} + working-directory: networkservicemesh/${{ matrix.repository }} + run: | + echo Starting to update repositotry ${{ matrix.repository }} + git config --global user.email "nsmbot@networkservicmesh.io" + git config --global user.name "NSMBot" + git remote add cmd_template https://github.com/networkservicemesh/cmd-template.git + git fetch cmd_template + git diff cmd_template/master -R | git apply + git add $(git ls-tree --name-only -r cmd_template/master | grep ".*\.yml\|.*\.yaml\|.*\.md\|.*\.txt\|.*.\.conf") + git reset -- $(cat exclude.patch.conf) + git commit -s -F /tmp/commit-message + git checkout -b update/${{ github.repository }} + git push -f origin update/${{ github.repository }} diff --git a/.golangci.yml b/.golangci.yml index ba671f35..4f3e400a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,10 +1,20 @@ --- run: # concurrency: 6 - timeout: 1m + timeout: 2m issues-exit-code: 1 tests: true linters-settings: + goheader: + template-path: ".license/template.txt" + values: + const: + year: 2020 + regexp: + year-range: ((\d\d\d\d-{{year}})|({{year}})) + company: .* + copyright-holder: Copyright \(c\) {{year-range}} {{company}}\n\n + copyright-holders: ({{copyright-holder}})+ errcheck: check-type-assertions: false check-blank: false @@ -20,13 +30,16 @@ linters-settings: golint: min-confidence: 0.8 goimports: - local-prefixes: github.com/networkservicemesh/cmd-forwarder-vppagent + local-prefixes: github.com/networkservicemesh gocyclo: min-complexity: 15 maligned: suggest-new: true dupl: threshold: 150 + funlen: + Lines: 100 + Statements: 50 goconst: min-len: 2 min-occurrences: 2 @@ -93,7 +106,6 @@ linters-settings: - octalLiteral - offBy1 - paramTypeCombine - - ptrToRefParam - rangeExprCopy - rangeValCopy - regexpMust @@ -120,6 +132,7 @@ linters: disable-all: true enable: # - rowserrcheck + - goheader - bodyclose - deadcode - depguard diff --git a/.license/template.txt b/.license/template.txt index 7cbffa8a..cc3feeb2 100644 --- a/.license/template.txt +++ b/.license/template.txt @@ -1,15 +1,13 @@ -// {NSM 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. \ No newline at end of file +{{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. \ No newline at end of file diff --git a/exclude.patch.conf b/exclude.patch.conf new file mode 100644 index 00000000..a4bbffe1 --- /dev/null +++ b/exclude.patch.conf @@ -0,0 +1,2 @@ +## Put here paths to files which should be ignored on updating from depended repository +README.md \ No newline at end of file