diff --git a/.github/scripts/determine_simd_tag.go b/.github/scripts/determine_simd_tag.go new file mode 100644 index 00000000000..3fb4ce6986f --- /dev/null +++ b/.github/scripts/determine_simd_tag.go @@ -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) +} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ff8ed4d65d9..8482853965a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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: @@ -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: @@ -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 }} diff --git a/Makefile b/Makefile index 9beb4ab61bc..df259c5a477 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 ### ############################################################################### diff --git a/e2e/fee_middleware_test.go b/e2e/fee_middleware_test.go new file mode 100644 index 00000000000..33327ecfb15 --- /dev/null +++ b/e2e/fee_middleware_test.go @@ -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) +}