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 GitHub actions for e2e tests (E2E #2) #1646

Merged
merged 26 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
47be6be
feat(e2e): adding script to dynamically generate list of e2e tests
chatton Jul 4, 2022
ce80411
feat(e2e): adding github CI to run E2E tests
chatton Jul 4, 2022
bfbba03
feat(e2e) adding placeholder test for github action to execute
chatton Jul 4, 2022
4569fa5
wip: extracting correct tag for image
chatton Jul 4, 2022
272ad61
wip: extracting correct tag for image
chatton Jul 4, 2022
6afe90c
wip: corrected workflow syntax
chatton Jul 4, 2022
7497574
wip: corrected workflow syntax
chatton Jul 4, 2022
7091fbc
removed unreferenced job
chatton Jul 4, 2022
6ebcc6d
wip: adding makefile
chatton Jul 4, 2022
05d9a45
wip: displaying env vars in placeholder test
chatton Jul 4, 2022
308eb0f
wip: adding go script to determine simd tag
chatton Jul 4, 2022
9ebacd7
fix: corrected outputs name in test.yml
chatton Jul 4, 2022
c431850
fix: specifying correct output name
chatton Jul 4, 2022
3c4f62b
fix: updating go script to accept a single argument
chatton Jul 4, 2022
b5fff2a
chore: greatly simplifying determine_simd_tag.go
chatton Jul 4, 2022
abb0eca
chore: adding docstring to determine_simd_tag.go
chatton Jul 4, 2022
f36025b
chore: extract output variable
chatton Jul 4, 2022
9039137
chore: adding echo to display the tag in the workflow
chatton Jul 4, 2022
7083607
chore: removed simd tag variable
chatton Jul 5, 2022
e9ddf3f
Revert "chore: removed simd tag variable"
chatton Jul 5, 2022
e323780
Merge branch 'main' into cian/issue#1642-add-tool-to-dynamically-gene…
chatton Jul 5, 2022
5f6cf40
chore: adding additional tests and erroring on duplicate test functions
chatton Jul 5, 2022
6cdc8aa
Merge branch 'cian/issue#1642-add-tool-to-dynamically-generate-e2e-te…
chatton Jul 5, 2022
1bfc42f
Merge branch 'cian/issue#1642-add-tool-to-dynamically-generate-e2e-te…
chatton Jul 5, 2022
3ff43db
Merge branch 'main' into cian/issue#1643-add-e2e-github-actions-for-e…
chatton Jul 6, 2022
c18313b
remove github context action
chatton Jul 6, 2022
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
34 changes: 34 additions & 0 deletions .github/scripts/determine_simd_tag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"flag"
"fmt"
"os"
)

var prNum int
var ref string

func init() {
flag.IntVar(&prNum, "pr", 0, "the number of the pr")
flag.StringVar(&ref, "ref", "", "the github ref")
flag.Parse()
}

// in the context of a GithubAction workflow, the PR is the event number. So if the ref is not specified
// but the event number is, that means we are running for a PR. If the ref is specified, this means
// we have merged the PR, so we want to use the ref as a tag instead of the PR number.
func main() {
if prNum == 0 && ref == "" {
fmt.Printf("must specify one or bot of [pr, ref]")
os.Exit(1)
}
fmt.Printf(getSimdTag(prNum, ref))
}

func getSimdTag(prNum int, ref string) string {
if ref != "" {
return ref
}
return fmt.Sprintf("pr-%d", prNum)
}
97 changes: 89 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ on:
push:
branches:
- main

env:
REGISTRY: ghcr.io
IMAGE_NAME: ibc-go-simd-e2e

jobs:
cleanup-runs:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -51,13 +56,6 @@ jobs:
- name: Build
run: GOARCH=${{ matrix.go-arch }} LEDGER_ENABLED=false make build

docker-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Docker Build
run: docker build . --no-cache

split-test-files:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -108,7 +106,7 @@ jobs:
if: env.GIT_DIFF
- name: test & coverage report creation
run: |
cat pkgs.txt.part.${{ matrix.part }} | xargs go test -race -mod=readonly -timeout 30m -coverprofile=${{ matrix.part }}profile.out -covermode=atomic -tags='ledger test_ledger_mock'
cat pkgs.txt.part.${{ matrix.part }} | xargs go test $(go list ./... | grep -v e2e) -race -mod=readonly -timeout 30m -coverprofile=${{ matrix.part }}profile.out -covermode=atomic -tags='ledger test_ledger_mock'
if: env.GIT_DIFF
- uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -161,3 +159,86 @@ jobs:
with:
file: ./coverage.txt
if: env.GIT_DIFF


docker-build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@49ed152c8eca782a232dede0303416e8f356c37b
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@69f6fc9d46f2f8bf0d5491e4aabe0bb8c6a4678a
with:
images: ${{ env.REGISTRY }}/cosmos/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@e551b19e49efd4e98792db7592c17c09b89db8d8
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}


# dynamically build a matrix of test/test suite pairs to run
build-test-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.18
- id: set-matrix
run: echo "::set-output name=matrix::$(go run .github/scripts/build_test_matrix.go)"


# the tag of the image will differ if this is a PR or the branch is being merged into main.
# we store the tag as an environment variable and use it in the E2E tests to determine the tag.
determine-image-tag:
runs-on: ubuntu-latest
outputs:
simd-tag: ${{ steps.get-tag.outputs.simd-tag }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.18
- id: get-tag
run: |
tag=$(go run .github/scripts/determine_simd_tag.go -ref "${{ github.event.push.ref }}" -pr "${{ github.event.pull_request.number }}" )
echo "Using tag $tag"
echo "::set-output name=simd-tag::$tag"


e2e:
runs-on: ubuntu-latest
needs:
- build-test-matrix
- determine-image-tag
- docker-build
env:
SIMD_TAG: ${{ needs.determine-image-tag.outputs.simd-tag }}
SIMD_IMAGE: ghcr.io/cosmos/ibc-go-simd-e2e
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.build-test-matrix.outputs.matrix) }}
steps:
- uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@49ed152c8eca782a232dede0303416e8f356c37b
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Run e2e Test
run: |
make e2e-test suite=${{ matrix.suite }} test=${{ matrix.test }}
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ MOCKS_DIR = $(CURDIR)/tests/mocks
HTTPS_GIT := https://github.com/cosmos/ibc-go.git
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.0.0-rc8
TEST_CONTAINERS=$(shell docker ps --filter "label=ibc-test" -a -q)

export GO111MODULE = on

Expand Down Expand Up @@ -324,6 +325,15 @@ benchmark:
@go test -mod=readonly -bench=. $(PACKAGES_NOSIMULATION)
.PHONY: benchmark

cleanup-ibc-test-containers:
for id in $(TEST_CONTAINERS) ; do \
$(DOCKER) stop $$id ; \
$(DOCKER) rm $$id ; \
done

e2e-test: cleanup-ibc-test-containers
@go test -v ./e2e --run $(suite) -testify.m ^$(test)$$

###############################################################################
### Linting ###
###############################################################################
Expand Down
29 changes: 29 additions & 0 deletions e2e/fee_middleware_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package e2e

import (
"os"
"testing"

"github.com/stretchr/testify/suite"
)

func TestFeeMiddlewareTestSuite(t *testing.T) {
suite.Run(t, new(FeeMiddlewareTestSuite))
}

type FeeMiddlewareTestSuite struct {
suite.Suite
}

func (s *FeeMiddlewareTestSuite) TestPlaceholder() {
tag, ok := os.LookupEnv("SIMD_TAG")
s.Require().True(ok)
s.T().Logf("SIMD_TAG=%s", tag)

image, ok := os.LookupEnv("SIMD_IMAGE")
s.Require().True(ok)
s.T().Logf("SIMD_IMAGE=%s", image)

s.T().Logf("Placeholder test")
s.Require().True(true)
}