Skip to content

Commit

Permalink
Add GitHub actions for e2e tests (E2E #2) (#1646)
Browse files Browse the repository at this point in the history
  • Loading branch information
chatton authored Jul 8, 2022
1 parent 527a11a commit 6d1fa91
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 8 deletions.
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)
}

0 comments on commit 6d1fa91

Please sign in to comment.