Skip to content

Commit

Permalink
Update common CI files to latest version from networkservicemesh/cmd-…
Browse files Browse the repository at this point in the history
…template@master networkservicemesh/cmd-template#33

networkservicemesh/cmd-template PR link: networkservicemesh/cmd-template#33

networkservicemesh/cmd-template commit message:
commit 031508b28a917cb86e6a50eae191fe953fc008c7
Author: Denis Tingaikin <49399980+denis-tingajkin@users.noreply.github.com>
Date:   Mon Nov 9 21:47:12 2020 +0700

    fix: Error "No such file or directory" (#33)

    Signed-off-by: denis-tingajkin <denis.tingajkin@xored.com>

Signed-off-by: NSMBot <nsmbot@networkservicmesh.io>
  • Loading branch information
NSMBot committed Nov 9, 2020
1 parent 5aee008 commit 5b58216
Show file tree
Hide file tree
Showing 10 changed files with 545 additions and 81 deletions.
237 changes: 181 additions & 56 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,47 +1,67 @@
---
name: ci
on: pull_request
on:
push:
branches:
- master
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: Setup Python
uses: actions/setup-python@v1
- name: Install yamllint
run: pip install --user yamllint
- name: Run yamllint
run: ~/.local/bin/yamllint -c .yamllint.yml --strict .
- name: yaml-lint
uses: ibiqlik/action-yamllint@v1
with:
config_file: .yamllint.yml
strict: true

shellcheck:
name: shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: shellcheck
uses: fkautz/shell-linter@v1.0.1

build:
name: build
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.15
- name: Build
run: go build -race ./...

golangci-lint:
name: golangci-lint
runs-on: ubuntu-latest
env:
GOLANGCI_LINT_CONTAINER: golangci/golangci-lint:v1.23.2
if: github.repository != 'networkservicemesh/cmd-template'
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: Pull golangci-lint docker container
run: docker pull ${GOLANGCI_LINT_CONTAINER}
- name: Run golangci-lint
run: docker run --rm -v $(pwd):/app -w /app ${GOLANGCI_LINT_CONTAINER} golangci-lint run
uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.31

excludeFmtErrorf:
name: exclude fmt.Errorf
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- name: Exclude fmt.Errorf
run: |
if grep -r --include=*.go fmt.Errorf . ; then
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
Expand All @@ -50,84 +70,126 @@ jobs:
name: Restrict dependencies on github.com/networkservicemesh/*
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- name: Restrict dependencies on github.com/networkservicemesh/*
env:
ALLOWED_REPOSITORIES: "sdk, api, sdk-k8s, sdk-vppagent, sdk-sriov"
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" ] && [ "${i}" != "github.com/networkservicemesh/api" ]; then
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
fi;
done
checkgomod:
name: check go.mod and go.sum
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions/setup-go@v1
with:
go-version: 1.13.4
go-version: 1.15
- 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 )
license:
name: license header check
gogenerate:
name: Check generated files
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- 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.15
- 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
name: Exclude Replace in go.mod
runs-on: ubuntu-latest
steps:
- name: Check out the code
uses: actions/checkout@v1
uses: actions/checkout@v2
- name: Exclude replace in go.mod
run: |
cat go.mod |
grep -v 'k8s.io/.* => k8s.io/.*' |
grep ^'=>' || exit 0
grep ^replace go.mod || exit 0
exit 1
captureRunEnv:
name: Capture CI Run Env
docker:
name: Docker Build & Test
runs-on: ubuntu-latest
if: github.repository != 'networkservicemesh/cmd-template'
steps:
- run: printenv
gogenerate:
name: gogenerate
- uses: actions/checkout@v2
- uses: actions/setup-go@v1
with:
go-version: 1.15
- name: Build container
run: docker build .
- name: Run tests
run: docker run --privileged --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
id: findPr
with:
github-token: ${{ github.token }}
- name: Publish Image
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && success() && steps.findPr.outputs.number
uses: matootie/github-docker@v3.0.0
with:
accessToken: ${{ github.token }}
tag: |
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 }}
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: Generate files
run: go generate ./...
- name: Check for changes in generated code
go-version: 1.15
- name: Build ${NAME} image
run: docker build . -t "${ORG}/${NAME}:${GITHUB_SHA::8}" --target runtime
- name: Push ${NAME} image
run: |
git diff -- 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 .)
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
docker push "${ORG}/${NAME}:${GITHUB_SHA::8}"
docker image rm "${ORG}/${NAME}:${GITHUB_SHA::8}"
docker push "${ORG}/${NAME}:latest"
docker image rm "${ORG}/${NAME}:latest"
automerge:
name: automerge
runs-on: ubuntu-latest
needs:
- build
- docker
if: github.actor == 'nsmbot' && github.base_ref == 'master' && github.event_name == 'pull_request'
steps:
Expand All @@ -137,11 +199,74 @@ 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:
GITHUB_LOGIN: nsmbot
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

update-integration-k8s-kind:
needs:
- automerge
name: Update integration-k8s-kind
runs-on: ubuntu-latest
if: github.repository != 'networkservicemesh/cmd-template' && github.actor == 'nsmbot' && github.base_ref == 'master' && github.event_name == 'pull_request'
steps:
- name: Checkout ${{ github.repository }}
uses: actions/checkout@v2
with:
path: ${{ github.repository }}
repository: ${{ github.repository }}
token: ${{ secrets.NSM_BOT_GITHUB_TOKEN }}
- name: Create commit message
working-directory: ${{ github.repository }}
run: |
echo "Update application version to latest version from ${{ github.repository }}@master ${{ github.repository }}#${{ github.event.number }}" >> /tmp/commit-message
echo "" >> /tmp/commit-message
echo "${{ github.repository }} PR link: https://github.com/${{ github.repository }}/pull/${{ github.event.number }}" >> /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/integration-k8s-kind
uses: actions/checkout@v2
with:
path: networkservicemesh/integration-k8s-kind
repository: networkservicemesh/integration-k8s-kind
token: ${{ secrets.NSM_BOT_GITHUB_TOKEN }}
- uses: benjlevesque/short-sha@v1.1
id: short-sha
with:
length: 8
- name: Find and Replace version
uses: jacobtomlinson/gha-find-replace@master
with:
find: "${{ github.event.repository.name }}:.*\n"
replace: "${{ github.event.repository.name }}:${{ steps.short-sha.outputs.sha }}\n"
- name: Push update to the integration-k8s-kind
working-directory: networkservicemesh/integration-k8s-kind
run: |
echo Starting to update repositotry integration-k8s-kind
git add -- .
if ! [ -n "$(git diff --cached --exit-code)" ]; then
echo Repository already up to date
exit 0;
fi
diff=$(git diff --name-only)
branchName="${{ github.event.repository.name }}"
if [ $(grep "go.mod" <<< "${diff}") && $(grep "" -c <<< "${diff}") == 1 ]; then
sdkPattern="github.com\/networkservicemesh\/sdk "
sdkVersion=$(grep --regexp "${sdkPattern}" go.mod)
branchName="${sdkVersion:${#sdkPattern}}"
fi;
git config --global user.email "nsmbot@networkservicmesh.io"
git config --global user.name "NSMBot"
git commit -s -F /tmp/commit-message
git checkout -b update/"${branchName}"
while [ git push origin update/"${branchName}" ]; do
git fetch origin update/"${branchName}"
git rebase origin/update/"${branchName}"
done
72 changes: 72 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
name: "CodeQL"

on:
push:
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
schedule:
- cron: '0 5 * * 0'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
# Override automatic language detection by changing the below list
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
language: ['go']
# Learn more...
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection

steps:
- name: Checkout repository
uses: actions/checkout@v2
with:
# We must fetch at least the immediate parents so that if this is
# a pull request then we can checkout the head.
fetch-depth: 2

# If this run was triggered by a pull request event, then checkout
# the head of the pull request instead of the merge commit.
- run: git checkout HEAD^2
if: ${{ github.event_name == 'pull_request' }}

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

# - run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
Loading

0 comments on commit 5b58216

Please sign in to comment.