From e7affdeab5db4a7dc2c15b1d7e8e9d7ac7195ccf Mon Sep 17 00:00:00 2001 From: Jeev B Date: Mon, 21 Aug 2023 08:04:10 -0700 Subject: [PATCH 1/5] Run tests in CI Signed-off-by: Jeev B --- .github/workflows/tests.yml | 2 + Makefile | 1 + .../flyte/end2end/functional-test-config.yaml | 17 +----- boilerplate/flyte/end2end/run-tests.py | 48 ++++++++-------- .../flyte/golang_test_targets/Makefile | 57 +++++++++++++++++++ .../flyte/golang_test_targets/Readme.rst | 31 ++++++++++ .../golang_test_targets/download_tooling.sh | 37 ++++++++++++ .../flyte/golang_test_targets/go-gen.sh | 22 +++++++ .../flyte/golang_test_targets/goimports | 8 +++ 9 files changed, 185 insertions(+), 38 deletions(-) mode change 100755 => 100644 boilerplate/flyte/end2end/run-tests.py create mode 100644 boilerplate/flyte/golang_test_targets/Makefile create mode 100644 boilerplate/flyte/golang_test_targets/Readme.rst create mode 100755 boilerplate/flyte/golang_test_targets/download_tooling.sh create mode 100755 boilerplate/flyte/golang_test_targets/go-gen.sh create mode 100755 boilerplate/flyte/golang_test_targets/goimports diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f1e185681d..d63baf6a5a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -16,6 +16,8 @@ jobs: go-version: "1.19" - name: Compile run: make compile + - name: Run tests + run: make test_unit docs: runs-on: ubuntu-latest diff --git a/Makefile b/Makefile index 6acccb1452..0474dd72ee 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ export REPOSITORY=flyte include boilerplate/flyte/end2end/Makefile +include boilerplate/flyte/golang_test_targets/Makefile define PIP_COMPILE pip-compile $(1) --upgrade --verbose --resolver=backtracking diff --git a/boilerplate/flyte/end2end/functional-test-config.yaml b/boilerplate/flyte/end2end/functional-test-config.yaml index c8fdb4c0cb..13fc445675 100644 --- a/boilerplate/flyte/end2end/functional-test-config.yaml +++ b/boilerplate/flyte/end2end/functional-test-config.yaml @@ -1,18 +1,5 @@ admin: + # For GRPC endpoints you might want to use dns:///flyte.myexample.com endpoint: dns:///localhost:30080 - insecure: true authType: Pkce -logger: - show-source: true - level: 0 -storage: - connection: - access-key: minio - auth-type: accesskey - disable-ssl: true - endpoint: http://localhost:30002 - region: us-east-1 - secret-key: miniostorage - type: minio - container: "my-s3-bucket" - enable-multicontainer: true + insecure: true diff --git a/boilerplate/flyte/end2end/run-tests.py b/boilerplate/flyte/end2end/run-tests.py old mode 100755 new mode 100644 index a03f715e79..6427681774 --- a/boilerplate/flyte/end2end/run-tests.py +++ b/boilerplate/flyte/end2end/run-tests.py @@ -21,7 +21,13 @@ # inputs. This is so we can progressively cover all priorities in the original flytesnacks manifest, # starting with "core". FLYTESNACKS_WORKFLOW_GROUPS: Mapping[str, List[Tuple[str, dict]]] = { + "lite": [ + ("basics.hello_world.my_wf", {}), + ("basics.lp.go_greet", {"day_of_week": "5", "number": 3, "am": True}), + ], "core": [ + ("basics.deck.wf", {}), + # The chain_workflows example in flytesnacks expects to be running in a sandbox. ("control_flow.chain_entities.chain_workflows_wf", {}), ("control_flow.dynamics.wf", {"s1": "Pear", "s2": "Earth"}), ("control_flow.map_task.my_map_workflow", {"a": [1, 2, 3, 4, 5]}), @@ -43,10 +49,7 @@ # ("basics.folders.download_and_rotate", {}), ("basics.hello_world.my_wf", {}), ("basics.lp.my_wf", {"val": 4}), - ( - "basics.lp.go_greet", - {"day_of_week": "5", "number": 3, "am": True}, - ), + ("basics.lp.go_greet", {"day_of_week": "5", "number": 3, "am": True}), ("basics.named_outputs.my_wf", {}), # # Getting a 403 for the wikipedia image # # ("basics.reference_task.wf", {}), @@ -55,36 +58,36 @@ # ("type_system.enums.enum_wf", {"c": "red"}), ("type_system.schema.df_wf", {"a": 42}), ("type_system.typed_schema.wf", {}), - # ("my.imperative.workflow.example", {"in1": "hello", "in2": "foo"}), + #("my.imperative.workflow.example", {"in1": "hello", "in2": "foo"}), ], "integrations-k8s-spark": [ - ("k8s_spark.pyspark_pi.my_spark", {"triggered_date": datetime.datetime.now()}), + ("k8s_spark_plugin.pyspark_pi.my_spark", {"triggered_date": datetime.datetime.now()}), ], "integrations-kfpytorch": [ - ("kfpytorch.pytorch_mnist.pytorch_training_wf", {}), + ("kfpytorch_plugin.pytorch_mnist.pytorch_training_wf", {}), ], "integrations-kftensorflow": [ - ("kftensorflow.tf_mnist.mnist_tensorflow_workflow", {}), + ("kftensorflow_plugin.tf_mnist.mnist_tensorflow_workflow", {}), ], # "integrations-pod": [ # ("pod.pod.pod_workflow", {}), # ], "integrations-pandera_examples": [ - ("pandera_examples.basic_schema_example.process_data", {}), + ("pandera_plugin.basic_schema_example.process_data", {}), # TODO: investigate type mismatch float -> numpy.float64 - # ("pandera_examples.validating_and_testing_ml_pipelines.pipeline", {"data_random_state": 42, "model_random_state": 99}), + # ("pandera_plugin.validating_and_testing_ml_pipelines.pipeline", {"data_random_state": 42, "model_random_state": 99}), ], "integrations-modin_examples": [ - ("modin_examples.knn_classifier.pipeline", {}), + ("modin_plugin.knn_classifier.pipeline", {}), ], "integrations-papermilltasks": [ - ("papermilltasks.simple.nb_to_python_wf", {"f": 3.1415926535}), + ("papermill_plugin.simple.nb_to_python_wf", {"f": 3.1415926535}), ], "integrations-greatexpectations": [ - ("greatexpectations.task_example.simple_wf", {}), - ("greatexpectations.task_example.file_wf", {}), - ("greatexpectations.task_example.schema_wf", {}), - ("greatexpectations.task_example.runtime_wf", {}), + ("greatexpectations_plugin.task_example.simple_wf", {}), + ("greatexpectations_plugin.task_example.file_wf", {}), + ("greatexpectations_plugin.task_example.schema_wf", {}), + ("greatexpectations_plugin.task_example.runtime_wf", {}), ], } @@ -190,16 +193,15 @@ def run( # For a given release tag and priority, this function filters the workflow groups from the flytesnacks # manifest file. For example, for the release tag "v0.2.224" and the priority "P0" it returns [ "core" ]. - manifest_url = ( - "https://raw.githubusercontent.com/flyteorg/flytesnacks/" - f"{flytesnacks_release_tag}/flyte_tests_manifest.json" - ) + manifest_url = "https://raw.githubusercontent.com/flyteorg/flytesnacks/" \ + f"{flytesnacks_release_tag}/flyte_tests_manifest.json" r = requests.get(manifest_url) parsed_manifest = r.json() + workflow_groups = [] + workflow_groups = ["lite"] if "lite" in priorities else [ + group["name"] for group in parsed_manifest if group["priority"] in priorities + ] - workflow_groups = [ - group["name"] for group in parsed_manifest if group["priority"] in priorities - ] results = [] valid_workgroups = [] for workflow_group in workflow_groups: diff --git a/boilerplate/flyte/golang_test_targets/Makefile b/boilerplate/flyte/golang_test_targets/Makefile new file mode 100644 index 0000000000..280e1e55e4 --- /dev/null +++ b/boilerplate/flyte/golang_test_targets/Makefile @@ -0,0 +1,57 @@ +# WARNING: THIS FILE IS MANAGED IN THE 'BOILERPLATE' REPO AND COPIED TO OTHER REPOSITORIES. +# ONLY EDIT THIS FILE FROM WITHIN THE 'FLYTEORG/BOILERPLATE' REPOSITORY: +# +# TO OPT OUT OF UPDATES, SEE https://github.com/flyteorg/boilerplate/blob/master/Readme.rst + + +.PHONY: download_tooling +download_tooling: #download dependencies (including test deps) for the package + @boilerplate/flyte/golang_test_targets/download_tooling.sh + +.PHONY: generate +generate: download_tooling #generate go code + @boilerplate/flyte/golang_test_targets/go-gen.sh + +.PHONY: lint +lint: download_tooling #lints the package for common code smells + GL_DEBUG=linters_output,env golangci-lint run --deadline=5m --exclude deprecated -v + +# If code is failing goimports linter, this will fix. +# skips 'vendor' +.PHONY: goimports +goimports: + @boilerplate/flyte/golang_test_targets/goimports + +.PHONY: mod_download +mod_download: #download dependencies (including test deps) for the package + go mod download + +.PHONY: install +install: download_tooling mod_download + +.PHONY: show +show: + go list -m all + +.PHONY: test_unit +test_unit: + go test -cover ./... -race + +.PHONY: test_benchmark +test_benchmark: + go test -bench . ./... + +.PHONY: test_unit_cover +test_unit_cover: + go test ./... -coverprofile /tmp/cover.out -covermode=count + go tool cover -func /tmp/cover.out + +.PHONY: test_unit_visual +test_unit_visual: + go test ./... -coverprofile /tmp/cover.out -covermode=count + go tool cover -html=/tmp/cover.out + +.PHONY: test_unit_codecov +test_unit_codecov: + go test ./... -race -coverprofile=coverage.txt -covermode=atomic + curl -s https://codecov.io/bash > codecov_bash.sh && bash codecov_bash.sh diff --git a/boilerplate/flyte/golang_test_targets/Readme.rst b/boilerplate/flyte/golang_test_targets/Readme.rst new file mode 100644 index 0000000000..f9d890fdd7 --- /dev/null +++ b/boilerplate/flyte/golang_test_targets/Readme.rst @@ -0,0 +1,31 @@ +Golang Test Targets +~~~~~~~~~~~~~~~~~~~ + +Provides an ``install`` make target that uses ``go mod`` to install golang dependencies. + +Provides a ``lint`` make target that uses golangci to lint your code. + +Provides a ``test_unit`` target for unit tests. + +Provides a ``test_unit_cover`` target for analysing coverage of unit tests, which will output the coverage of each function and total statement coverage. + +Provides a ``test_unit_visual`` target for visualizing coverage of unit tests through an interactive html code heat map. + +Provides a ``test_benchmark`` target for benchmark tests. + +**To Enable:** + +Add ``flyteorg/golang_test_targets`` to your ``boilerplate/update.cfg`` file. + +Make sure you're using ``go mod`` for dependency management. + +Provide a ``.golangci`` configuration (the lint target requires it). + +Add ``include boilerplate/flyte/golang_test_targets/Makefile`` in your main ``Makefile`` _after_ your REPOSITORY environment variable + +:: + + REPOSITORY= + include boilerplate/flyte/golang_test_targets/Makefile + +(this ensures the extra make targets get included in your main Makefile) diff --git a/boilerplate/flyte/golang_test_targets/download_tooling.sh b/boilerplate/flyte/golang_test_targets/download_tooling.sh new file mode 100755 index 0000000000..003220ea70 --- /dev/null +++ b/boilerplate/flyte/golang_test_targets/download_tooling.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Everything in this file needs to be installed outside of current module +# The reason we cannot turn off module entirely and install is that we need the replace statement in go.mod +# because we are installing a mockery fork. Turning it off would result installing the original not the fork. +# We also want to version all the other tools. We also want to be able to run go mod tidy without removing the version +# pins. To facilitate this, we're maintaining two sets of go.mod/sum files - the second one only for tooling. This is +# the same approach that go 1.14 will take as well. +# See: +# https://github.com/flyteorg/flyte/issues/129 +# https://github.com/golang/go/issues/30515 for some background context +# https://github.com/go-modules-by-example/index/blob/5ec250b4b78114a55001bd7c9cb88f6e07270ea5/010_tools/README.md + +set -e + +# List of tools to go get +# In the format of ":" or ":" if no cli +tools=( + "github.com/EngHabu/mockery/cmd/mockery" + "github.com/flyteorg/flytestdlib/cli/pflags@latest" + "github.com/golangci/golangci-lint/cmd/golangci-lint@latest" + "github.com/alvaroloes/enumer" + "github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc" +) + +tmp_dir=$(mktemp -d -t gotooling-XXX) +echo "Using temp directory ${tmp_dir}" +cp -R boilerplate/flyte/golang_support_tools/* $tmp_dir +pushd "$tmp_dir" + +for tool in "${tools[@]}" +do + echo "Installing ${tool}" + GO111MODULE=on go install $tool +done + +popd diff --git a/boilerplate/flyte/golang_test_targets/go-gen.sh b/boilerplate/flyte/golang_test_targets/go-gen.sh new file mode 100755 index 0000000000..54bd6af61b --- /dev/null +++ b/boilerplate/flyte/golang_test_targets/go-gen.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +set -ex + +echo "Running go generate" +go generate ./... + +# This section is used by GitHub workflow to ensure that the generation step was run +if [ -n "$DELTA_CHECK" ]; then + DIRTY=$(git status --porcelain) + if [ -n "$DIRTY" ]; then + echo "FAILED: Go code updated without commiting generated code." + echo "Ensure make generate has run and all changes are committed." + DIFF=$(git diff) + echo "diff detected: $DIFF" + DIFF=$(git diff --name-only) + echo "files different: $DIFF" + exit 1 + else + echo "SUCCESS: Generated code is up to date." + fi +fi diff --git a/boilerplate/flyte/golang_test_targets/goimports b/boilerplate/flyte/golang_test_targets/goimports new file mode 100755 index 0000000000..af1829036c --- /dev/null +++ b/boilerplate/flyte/golang_test_targets/goimports @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +# WARNING: THIS FILE IS MANAGED IN THE 'BOILERPLATE' REPO AND COPIED TO OTHER REPOSITORIES. +# ONLY EDIT THIS FILE FROM WITHIN THE 'FLYTEORG/BOILERPLATE' REPOSITORY: +# +# TO OPT OUT OF UPDATES, SEE https://github.com/flyteorg/boilerplate/blob/master/Readme.rst + +goimports -w $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./pkg/client/*" -not -path "./boilerplate/*") From a74984e7bcffa6c17dfbb2fa02f58fbf0e17b6cc Mon Sep 17 00:00:00 2001 From: Jeev B Date: Mon, 21 Aug 2023 09:16:17 -0700 Subject: [PATCH 2/5] Register basics.basics.deck Signed-off-by: Jeev B --- .github/workflows/single-binary.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/single-binary.yml b/.github/workflows/single-binary.yml index 9194ccabbf..0f248b8499 100644 --- a/.github/workflows/single-binary.yml +++ b/.github/workflows/single-binary.yml @@ -189,7 +189,9 @@ jobs: # ref: ${{ env.FLYTESNACKS_VERSION }} - name: Register specific tests run: | - for f in basics/basics/basic_workflow.py \ + for f in \ + basics/basics/basic_workflow.py \ + basics/basics/deck.py \ basics/basics/hello_world.py \ basics/basics/lp.py \ basics/basics/named_outputs.py \ From 9db8e8fe977714744b91f566a32db3e2b9921128 Mon Sep 17 00:00:00 2001 From: Jeev B Date: Mon, 21 Aug 2023 15:15:40 -0700 Subject: [PATCH 3/5] fix missing deps Signed-off-by: Jeev B --- .github/workflows/single-binary.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/single-binary.yml b/.github/workflows/single-binary.yml index 0f248b8499..8465c17b51 100644 --- a/.github/workflows/single-binary.yml +++ b/.github/workflows/single-binary.yml @@ -160,7 +160,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: '3.10' + python-version: '3.11' - uses: unionai/flytectl-setup-action@v0.0.1 - name: Setup sandbox run: | @@ -178,7 +178,7 @@ jobs: - name: Install Python dependencies run: | python -m pip install --upgrade pip - pip install flytekit + pip install flytekit flytekitplugins-deck-standard pip freeze - name: Checkout flytesnacks uses: actions/checkout@v3 From 6a3ed39d4bb5879eba19405492d164c3bb209fce Mon Sep 17 00:00:00 2001 From: Jeev B Date: Mon, 21 Aug 2023 15:58:28 -0700 Subject: [PATCH 4/5] Add missing boilerplate module Signed-off-by: Jeev B --- boilerplate/update.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/boilerplate/update.cfg b/boilerplate/update.cfg index 89075915af..5ba796f048 100644 --- a/boilerplate/update.cfg +++ b/boilerplate/update.cfg @@ -1,2 +1,3 @@ flyte/end2end flyte/code_of_conduct +flyte/golang_test_targets From b097cc438de31f3e911f22fbe0160f7f216389b9 Mon Sep 17 00:00:00 2001 From: Jeev B Date: Mon, 21 Aug 2023 18:36:01 -0700 Subject: [PATCH 5/5] update boilerplate Signed-off-by: Jeev B --- boilerplate/flyte/golang_test_targets/download_tooling.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boilerplate/flyte/golang_test_targets/download_tooling.sh b/boilerplate/flyte/golang_test_targets/download_tooling.sh index 003220ea70..c7e5577ef3 100755 --- a/boilerplate/flyte/golang_test_targets/download_tooling.sh +++ b/boilerplate/flyte/golang_test_targets/download_tooling.sh @@ -18,7 +18,7 @@ set -e tools=( "github.com/EngHabu/mockery/cmd/mockery" "github.com/flyteorg/flytestdlib/cli/pflags@latest" - "github.com/golangci/golangci-lint/cmd/golangci-lint@latest" + "github.com/golangci/golangci-lint/cmd/golangci-lint" "github.com/alvaroloes/enumer" "github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc" )