Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add gen-test command for chatops #379

Merged
merged 4 commits into from
May 19, 2020
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
6 changes: 6 additions & 0 deletions .github/chatops_permissions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,41 @@ roles:
- rebase
- approve
- add-contributors
- gen-test
- label
- format
author:
policies:
- rebase
- approve
- add-contributors
- gen-test
- label
- format
sig-lead:
policies:
- rebase
- approve
- gen-test
- label
- format
sig-sre:
policies:
- rebase
- add-contributors
- gen-test
- label
- format
sig-set:
policies:
- rebase
- gen-test
- label
- format
sig-core:
policies:
- rebase
- gen-test
- label
- format
contributor:
Expand Down
108 changes: 108 additions & 0 deletions .github/workflows/chatops.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ jobs:
git add CONTRIBUTORS README.md
git commit --signoff -m ":robot: Automatically add contributor"

git pull --rebase

git remote set-url origin "https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"

git push origin ${HEAD_BRANCH}
Expand All @@ -237,11 +239,117 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.DISPATCH_TOKEN }}
API_URL: ${{ github.event.issue.comments_url }}
gentest:
name: Add tests
needs:
- rebase
runs-on: ubuntu-latest
steps:
- name: check PR Comments
id: check_comments_gen_test
uses: machine-learning-apps/actions-chatops@master
with:
TRIGGER_PHRASE: "/gen-test"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: install yq
if: steps.check_comments_gen_test.outputs.BOOL_TRIGGERED == 'true'
run: |
sudo curl -Lo /usr/local/bin/yq https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64
sudo chmod a+x /usr/local/bin/yq
- name: check permissions
if: steps.check_comments_gen_test.outputs.BOOL_TRIGGERED == 'true'
id: check_permissions
run: |
curl -o chatops_permissions.yaml https://raw.githubusercontent.com/vdaas/vald/master/.github/chatops_permissions.yaml
roles=`yq r chatops_permissions.yaml "users.${USERNAME}.role.*"`
if [ "$roles" = "" ]; then
roles=`yq r chatops_permissions.yaml "default-roles.*"`
fi
for role in `echo $roles`
do
if yq r chatops_permissions.yaml "roles.${role}.policies.*" | grep "^${REQUIRED_POLICY}$" > /dev/null 2>&1 ; then
echo "[OK] add-contributor requested by ${USERNAME}"
echo "::set-output name=EXECUTABLE::true"
break
fi
done
env:
USERNAME: ${{ steps.check_comments_gen_test.outputs.COMMENTER_USERNAME }}
REQUIRED_POLICY: gen-test
- name: check executable
if: steps.check_comments_gen_test.outputs.BOOL_TRIGGERED == 'true' && steps.check_permissions.outputs.EXECUTABLE == 'true'
run: |
curl --include --verbose --fail \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
-H "Authorization: token ${GITHUB_TOKEN}" \
--request POST \
--data "{\"body\": \"**[GEN TEST]** Generating missing test files triggered by ${USERNAME}.\"}" \
$API_URL
env:
GITHUB_TOKEN: ${{ secrets.DISPATCH_TOKEN }}
USERNAME: ${{ steps.check_comments_gen_test.outputs.COMMENTER_USERNAME }}
PR_AUTHOR: ${{ github.event.issue.user.login }}
API_URL: ${{ github.event.issue.comments_url }}
- uses: actions/checkout@v1
if: steps.check_comments_gen_test.outputs.BOOL_TRIGGERED == 'true' && steps.check_permissions.outputs.EXECUTABLE == 'true'
with:
fetch-depth: 10
- name: Generate tests and push
if: steps.check_comments_gen_test.outputs.BOOL_TRIGGERED == 'true' && steps.check_permissions.outputs.EXECUTABLE == 'true'
run: |
curl -s ${PR_INFO_URL} > /tmp/pr_info.json
PR_RESP=`cat /tmp/pr_info.json`
HEAD_BRANCH=$(cat /tmp/pr_info.json | jq -r .head.ref)
if [[ -z "$HEAD_BRANCH" ]]; then
echo "Cannot get head branch information for PR #${PR_NUM}!"
echo "API response: $PR_RESP"
exit 1
fi
echo "Head branch for PR #${PR_NUM} is ${HEAD_BRANCH}"

git checkout ${HEAD_BRANCH}

make gotests/install
make -j 4 gotests/gen

git config --global user.name "vdaas-ci"
git config --global user.email "ci@vdaas.org"

git add cmd hack internal pkg
git commit --signoff -m ":robot: Add automatically generated tests"

git pull --rebase

git remote set-url origin "https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"

git push origin ${HEAD_BRANCH}
env:
GITHUB_USER: ${{ secrets.DISPATCH_USER }}
GITHUB_TOKEN: ${{ secrets.DISPATCH_TOKEN }}
PR_INFO_URL: ${{ github.event.issue.pull_request.url }}
PR_AUTHOR: ${{ github.event.issue.user.login }}
PR_NUM: ${{ github.event.issue.number }}
- name: failure comment
if: failure()
run: |
curl --include --verbose --fail \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
-H "Authorization: token ${GITHUB_TOKEN}" \
--request POST \
--data "{\"body\": \"**[GEN TEST]** Failed to generate tests.\"}" \
$API_URL
env:
GITHUB_TOKEN: ${{ secrets.DISPATCH_TOKEN }}
API_URL: ${{ github.event.issue.comments_url }}
format:
name: Add license and run goimports
needs:
- rebase
- add-contributors
- gentest
runs-on: ubuntu-latest
steps:
- name: check PR Comments
Expand Down
77 changes: 53 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
REPO ?= vdaas
NAME = vald
GOPKG = github.com/$(REPO)/$(NAME)
TAG = $(shell date -u +%Y%m%d-%H%M%S)
TAG = $(eval TAG := $(shell date -u +%Y%m%d-%H%M%S))$(TAG)
BASE_IMAGE = $(NAME)-base
AGENT_IMAGE = $(NAME)-agent-ngt
GATEWAY_IMAGE = $(NAME)-gateway
Expand All @@ -31,16 +31,16 @@ MANAGER_INDEX_IMAGE = $(NAME)-manager-index
CI_CONTAINER_IMAGE = $(NAME)-ci-container
HELM_OPERATOR_IMAGE = $(NAME)-helm-operator

NGT_VERSION := $(shell cat versions/NGT_VERSION)
NGT_VERSION := $(eval NGT_VERSION := $(shell cat versions/NGT_VERSION))$(NGT_VERSION)
NGT_REPO = github.com/yahoojapan/NGT

GO_VERSION := $(shell cat versions/GO_VERSION)
GOPATH := $(shell go env GOPATH)
GOCACHE := $(shell go env GOCACHE)
GO_VERSION := $(eval GO_VERSION := $(shell cat versions/GO_VERSION))$(GO_VERSION)
GOPATH := $(eval GOPATH := $(shell go env GOPATH))$(GOPATH)
GOCACHE := $(eval GOCACHE := $(shell go env GOCACHE))$(GOCACHE)

TENSORFLOW_C_VERSION := $(shell cat versions/TENSORFLOW_C_VERSION)
TENSORFLOW_C_VERSION := $(eval TENSORFLOW_C_VERSION := $(shell cat versions/TENSORFLOW_C_VERSION))$(TENSORFLOW_C_VERSION)

OPERATOR_SDK_VERSION := $(shell cat versions/OPERATOR_SDK_VERSION)
OPERATOR_SDK_VERSION := $(eval OPERATOR_SDK_VERSION := $(shell cat versions/OPERATOR_SDK_VERSION))$(OPERATOR_SDK_VERSION)

DOCKFMT_VERSION ?= v0.3.3
KIND_VERSION ?= v0.7.0
Expand All @@ -55,12 +55,12 @@ SWAP_TAG ?= latest

BINDIR ?= /usr/local/bin

UNAME := $(shell uname)
UNAME := $(eval UNAME := $(shell uname))$(UNAME)

MAKELISTS := Makefile $(shell find Makefile.d -type f -regex ".*\.mk")

ROOTDIR = $(shell git rev-parse --show-toplevel)
PROTODIRS := $(shell find apis/proto -type d | sed -e "s%apis/proto/%%g" | grep -v "apis/proto")
ROOTDIR = $(eval ROOTDIR := $(shell git rev-parse --show-toplevel))$(ROOTDIR)
PROTODIRS := $(eval PROTODIRS := $(shell find apis/proto -type d | sed -e "s%apis/proto/%%g" | grep -v "apis/proto"))$(PROTODIRS)
PBGODIRS = $(PROTODIRS:%=apis/grpc/%)
SWAGGERDIRS = $(PROTODIRS:%=apis/swagger/%)
GRAPHQLDIRS = $(PROTODIRS:%=apis/graphql/%)
Expand All @@ -72,14 +72,14 @@ BENCH_DATASET_HDF5_DIR_NAME = dataset
BENCH_DATASET_MD5_DIR = $(BENCH_DATASET_BASE_DIR)/$(BENCH_DATASET_MD5_DIR_NAME)
BENCH_DATASET_HDF5_DIR = $(BENCH_DATASET_BASE_DIR)/$(BENCH_DATASET_HDF5_DIR_NAME)

PROTOS := $(shell find apis/proto -type f -regex ".*\.proto")
PROTOS := $(eval PROTOS := $(shell find apis/proto -type f -regex ".*\.proto"))$(PROTOS)
PBGOS = $(PROTOS:apis/proto/%.proto=apis/grpc/%.pb.go)
SWAGGERS = $(PROTOS:apis/proto/%.proto=apis/swagger/%.swagger.json)
GRAPHQLS = $(PROTOS:apis/proto/%.proto=apis/graphql/%.pb.graphqls)
GQLCODES = $(GRAPHQLS:apis/graphql/%.pb.graphqls=apis/graphql/%.generated.go)
PBDOCS = $(PROTOS:apis/proto/%.proto=apis/docs/%.md)

BENCH_DATASET_MD5S := $(shell find $(BENCH_DATASET_MD5_DIR) -type f -regex ".*\.md5")
BENCH_DATASET_MD5S := $(eval BENCH_DATASET_MD5S := $(shell find $(BENCH_DATASET_MD5_DIR) -type f -regex ".*\.md5"))$(BENCH_DATASET_MD5S)
BENCH_DATASETS = $(BENCH_DATASET_MD5S:$(BENCH_DATASET_MD5_DIR)/%.md5=$(BENCH_DATASET_HDF5_DIR)/%.hdf5)

DATASET_ARGS ?= identity-128
Expand All @@ -99,6 +99,46 @@ PROTO_PATHS = \
$(GOPATH)/src/github.com/danielvladco/go-proto-gql \
$(GOPATH)/src/github.com/envoyproxy/protoc-gen-validate

GO_SOURCES = $(eval GO_SOURCES := $(shell find \
./cmd \
./hack \
./internal \
./pkg \
-not -path './cmd/cli/*' \
-not -path './internal/core/ngt/*' \
-not -path './hack/benchmark/internal/client/ngtd/*' \
-not -path './hack/benchmark/internal/starter/agent/*' \
-not -path './hack/benchmark/internal/starter/external/*' \
-not -path './hack/benchmark/internal/starter/gateway/*' \
-not -path './hack/license/*' \
-not -path './hack/swagger/*' \
-not -path './hack/tools/*' \
-type f \
-name '*.go' \
-not -regex '.*options?\.go' \
-not -name '*_test.go' \
-not -name 'doc.go'))$(GO_SOURCES)
GO_OPTION_SOURCES = $(eval GO_OPTION_SOURCES := $(shell find \
./cmd \
./hack \
./internal \
./pkg \
-not -path './cmd/cli/*' \
-not -path './internal/core/ngt/*' \
-not -path './hack/benchmark/internal/client/ngtd/*' \
-not -path './hack/benchmark/internal/starter/agent/*' \
-not -path './hack/benchmark/internal/starter/external/*' \
-not -path './hack/benchmark/internal/starter/gateway/*' \
-not -path './hack/license/*' \
-not -path './hack/swagger/*' \
-not -path './hack/tools/*' \
-type f \
-regex '.*options?\.go' \
-not -name '*_test.go' \
-not -name 'doc.go'))$(GO_OPTION_SOURCES)
GO_TEST_SOURCES = $(GO_SOURCES:%.go=%_test.go)
GO_OPTION_TEST_SOURCES = $(GO_OPTION_SOURCES:%.go=%_test.go)

COMMA := ,
SHELL = bash

Expand Down Expand Up @@ -268,18 +308,6 @@ tensorflow/install: /usr/local/lib/libtensorflow.so
rm -f libtensorflow-cpu-linux-x86_64-$(TENSORFLOW_C_VERSION).tar.gz
ldconfig

.PHONY: gentest
## gentest
gentest:
$(call gen-test)


.PHONY: fixtest
## fixtest
fixtest:
$(call fix-test)


.PHONY: test
## run tests
test:
Expand Down Expand Up @@ -318,3 +346,4 @@ include Makefile.d/k8s.mk
include Makefile.d/kind.mk
include Makefile.d/client.mk
include Makefile.d/ml.mk
include Makefile.d/test.mk
36 changes: 0 additions & 36 deletions Makefile.d/functions.mk
Original file line number Diff line number Diff line change
Expand Up @@ -90,39 +90,3 @@ define telepresence
## https://github.com/telepresenceio/telepresence/commit/bb7473fbf19ed4f61796a5e32747e23de6ab03da
## --deployment-type "$(SWAP_DEPLOYMENT_TYPE)"
endef

define gen-test
find . -type d | \
grep "./cmd\|./hack\|./internal\|./pkg" | \
grep -v "./cmd/cli\| \
./internal/core/ngt\| \
./hack/benchmark/internal/client/ngtd\| \
./hack/benchmark/internal/starter/agent\| \
./hack/benchmark/internal/starter/external\| \
./hack/benchmark/internal/starter/gateway\| \
./hack/license\| \
./hack/swagger\| \
./hack/tools"| \
while read dir; do \
files=`find $${dir} -type f -maxdepth 1 -name "*.go" -not -name '*_test.go' -not -name 'doc.go'`; \
for file in $${files}; do \
path='./assets/test/templates/common'; \
if [[ $${file} =~ .*options?\.go ]] ; then \
path='./assets/test/templates/option'; \
fi; \
echo start generate test code: $${file}; \
gotests -w -template_dir $${path} -all $${file}; \
done; \
done
rm $(ROOTDIR)/internal/core/ngt/*test.go
endef

define fix-test
find $(ROOTDIR)/internal/k8s/* -name '*_test.go' | xargs sed -i -E "s%k8s.io/apimachinery/pkg/api/errors%github.com/vdaas/vald/internal/errors%g"
find $(ROOTDIR)/* -name '*_test.go' | xargs sed -i -E "s%cockroachdb/errors%vdaas/vald/internal/errors%g"
find $(ROOTDIR)/* -name '*_test.go' | xargs sed -i -E "s%pkg/errors%vdaas/vald/internal/errors%g"
find $(ROOTDIR)/* -name '*_test.go' | xargs sed -i -E "s%go-errors/errors%vdaas/vald/internal/errors%g"
find $(ROOTDIR)/internal/errors -name '*_test.go' | xargs sed -i -E "s%\"github.com/vdaas/vald/internal/errors\"%%g"
find $(ROOTDIR)/internal/errors -name '*_test.go' | xargs sed -i -E "s/errors\.//g"
go mod tidy
endef
Loading