From a470b6edbaf58c016506ec60bfeaabd4a0a5883b Mon Sep 17 00:00:00 2001 From: Gjermund Garaba Date: Wed, 28 Aug 2024 13:26:50 +0200 Subject: [PATCH] add basic ci pipelines. closes #14 --- .github/workflows/e2e.yaml | 86 ++++++++++++++++++++++++++++ .github/workflows/lint.yml | 40 +++++++++++++ .github/workflows/test.yml | 30 ++++++++++ README.md | 7 ++- justfile | 20 ++++--- testing/Makefile | 16 +++--- testing/interchaintest/setup_test.go | 27 +++++---- 7 files changed, 197 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/e2e.yaml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml new file mode 100644 index 0000000..b1ccb7c --- /dev/null +++ b/.github/workflows/e2e.yaml @@ -0,0 +1,86 @@ +name: "E2E testing" +on: + workflow_dispatch: + push: + branches: + - main + pull_request: + +jobs: + docker-images: + name: "Build Docker images" + runs-on: ubuntu-latest + strategy: + matrix: + docker-images: + - { name: "ghcr.io/cosmos/interchain-attestation-simapp", path: "testing/simapp.Dockerfile" } + - { name: "ghcr.io/cosmos/interchain-attestation-rollupsimapp", path: "testing/rollupsimapp.Dockerfile" } + - { name: "ghcr.io/cosmos/interchain-attestation-sidecar", path: "testing/sidecar.Dockerfile" } + - { name: "ghcr.io/cosmos/interchain-attestation-mock-da", path: "testing/mock-da.Dockerfile" } + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 # Useful because the docker builds caches the go modules + with: + go-version: 1.23 + cache-dependency-path: | + core/go.sum + configmodule/go.sum + sidecar/go.sum + testing/interchaintest/go.sum + testing/simapp/go.sum + testing/rollupsimapp/go.sum + - uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Add SHORT_SHA env property with commit short sha + run: echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + + # TODO: Any nicer way to do this? :P + - name: Set Tags + run: | + echo "COMMIT_TAG=${{ matrix.docker-images.name }}:${{ SHORT_SHA }}" >> $GITHUB_ENV + if [ "${{ github.ref }}" = "refs/heads/main" ]; then + echo "LATEST_TAG=${{ matrix.docker-images.name }}:latest" >> $GITHUB_ENV + else + echo "LATEST_TAG=" >> $GITHUB_ENV + fi + + - name: Build + uses: docker/build-push-action@v6 + with: + push: true + context: . # Even though the docker images are in the testing directory, they need the root context + file: ${{ matrix.docker-images.path }} + tags: | + ${{ COMMIT_TAG }} + ${{ LATEST_TAG }} + + e2e: + name: "E2E test" + runs-on: ubuntu-latest + needs: + - docker-images + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: 1.23 + cache-dependency-path: | + core/go.sum + configmodule/go.sum + sidecar/go.sum + testing/interchaintest/go.sum + testing/simapp/go.sum + testing/rollupsimapp/go.sum + - name: Install just + uses: extractions/setup-just@v2 + + - name: Add SHORT_SHA env property with commit short sha + run: echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV + + - name: Run e2e tests + run: just test-e2e ${SHORT_SHA} \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..017c12c --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,40 @@ +name: "Linting" +on: + workflow_dispatch: + push: + branches: + - main + pull_request: + +jobs: + lint: + name: "Lint" + runs-on: ubuntu-latest + strategy: + matrix: + module: + - core + - configmodule + - sidecar + - testing/interchaintest + - testing/simapp + - testing/rollupsimapp + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version: 1.23 + cache-dependency-path: | #We need all of them cached because many modules are shared + core/go.sum + configmodule/go.sum + sidecar/go.sum + testing/interchaintest/go.sum + testing/simapp/go.sum + testing/rollupsimapp/go.sum + + - name: Lint ${{ matrix.module }} + uses: golangci/golangci-lint-action@v6.1.0 + with: + version: v1.60 + args: --timeout 5m + working-directory: ${{ matrix.module }} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..d3bd521 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,30 @@ +name: "Unit testing" +on: + workflow_dispatch: + push: + branches: + - main + pull_request: + +jobs: + lint: + name: "Unit test" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: 1.23 + cache-dependency-path: | + core/go.sum + configmodule/go.sum + sidecar/go.sum + testing/interchaintest/go.sum + testing/simapp/go.sum + testing/rollupsimapp/go.sum + - name: Install just + uses: extractions/setup-just@v2 + + - name: Run tests + run: just test-unit + diff --git a/README.md b/README.md index 4771978..4456461 100644 --- a/README.md +++ b/README.md @@ -67,8 +67,9 @@ Each module has a unit test suite that can be run with `make test`. You can also run all unit tests with for all modules with `just test-unit`. -In addition, there is an e2e test suite that can be run using `make interchaintest` (under `testing/`). -Before running the test, however, you need to build the docker images (which is required for every change you make to the code) with `make docker-images`. +In addition, there is an e2e test suite that can be run using `just test-e2e`. +The recipe takes an optional argument for which image-versions (docker tag) to use (e.g. `just test-e2e latest`). +If no argument is provided, it will default to `local` and also build the docker images locally with the local tag. ### Linting @@ -83,7 +84,7 @@ If you make changes to the proto files, you need to regenerate the go code with You can spin up a local testnet using `make serve` (under `testing/`. This spins up two chains, configures a sidecar process, and sets up an IBC connection with clients, connections and channels. To stop all the processes, run `make kill-all`. - + ## Background This project was originally built by Gjermund Garaba (https://github.com/gjermundgaraba/, https://twitter.com/gjermundgaraba) diff --git a/justfile b/justfile index 1d403f5..461a94c 100644 --- a/justfile +++ b/justfile @@ -1,12 +1,12 @@ lint: @echo "Running golangci-lint in all packages" - cd core && golangci-lint run -c ../.golangci.yml - cd configmodule && golangci-lint run -c ../.golangci.yml - cd sidecar && golangci-lint run -c ../.golangci.yml - cd testing/simapp && golangci-lint run -c ../../.golangci.yml - cd testing/rollupsimapp && golangci-lint run -c ../../.golangci.yml - cd testing/interchaintest && golangci-lint run -c ../../.golangci.yml + cd core && golangci-lint run + cd configmodule && golangci-lint run + cd sidecar && golangci-lint run + cd testing/simapp && golangci-lint run + cd testing/rollupsimapp && golangci-lint run + cd testing/interchaintest && golangci-lint run tidy: @echo "Running go mod tidy in all packages" @@ -28,5 +28,9 @@ test-unit: cd configmodule && make test cd sidecar && make test -test-e2e: - cd testing && make interchaintest \ No newline at end of file +test-e2e image-version="local": + if [[ "{{image-version}}" = "local" ]]; then just build-docker-images; fi + cd testing && DOCKER_IMAGE_VERSION={{image-version}} make interchaintest + +build-docker-images: + cd testing && make docker-images diff --git a/testing/Makefile b/testing/Makefile index 14be659..14eed86 100644 --- a/testing/Makefile +++ b/testing/Makefile @@ -27,20 +27,20 @@ generate-abi: docker-images: simapp-image rollupsimapp-image sidecar-image mock-da-image simapp-image: - @echo "Building simapp:local docker image" - docker build -t simapp:local -f simapp.Dockerfile ../ + @echo "Building ghcr.io/cosmos/interchain-attestation-simapp:local docker image" + docker build -t ghcr.io/cosmos/interchain-attestation-simapp:local -f simapp.Dockerfile ../ rollupsimapp-image: - @echo "Building rollupsimapp:local docker image" - docker build -t rollupsimapp:local -f rollupsimapp.Dockerfile ../ + @echo "Building ghcr.io/cosmos/interchain-attestation-rollupsimapp:local docker image" + docker build -t ghcr.io/cosmos/interchain-attestation-rollupsimapp:local -f rollupsimapp.Dockerfile ../ sidecar-image: - @echo "Building attestationsidecar:local docker image" - docker build -t attestationsidecar:local -f sidecar.Dockerfile ../ + @echo "Building ghcr.io/cosmos/interchain-attestation-sidecar:local docker image" + docker build -t ghcr.io/cosmos/interchain-attestation-sidecar:local -f sidecar.Dockerfile ../ mock-da-image: - @echo "Building mock-da:local docker image" - docker build -t mock-da:local -f mock-da.Dockerfile . + @echo "Building ghcr.io/cosmos/interchain-attestation-mock-da:local docker image" + docker build -t ghcr.io/cosmos/interchain-attestation-mock-da:local -f mock-da.Dockerfile . ############################################################################### ### Testing ### diff --git a/testing/interchaintest/setup_test.go b/testing/interchaintest/setup_test.go index 3739fe8..caf15ae 100644 --- a/testing/interchaintest/setup_test.go +++ b/testing/interchaintest/setup_test.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "fmt" + "os" "path" "strings" "testing" @@ -226,19 +227,25 @@ func (s *E2ETestSuite) TearDownSuite() { } func (s *E2ETestSuite) getChainFactory() *interchaintest.BuiltinChainFactory { + version := os.Getenv("DOCKER_IMAGE_VERSION") + if version == "" { + version = "local" + } + fmt.Println("Using docker image version:", version) + return interchaintest.NewBuiltinChainFactory(zaptest.NewLogger(s.T()), []*interchaintest.ChainSpec{ { Name: "simapp", ChainName: "simapp", - Version: "local", + Version: version, ChainConfig: ibc.ChainConfig{ Type: "cosmos", Name: "simapp", ChainID: simappChainID, Images: []ibc.DockerImage{ { - Repository: "simapp", - Version: "local", + Repository: "ghcr.io/cosmos/interchain-attestation-simapp", + Version: version, UidGid: "1025:1025", }, }, @@ -260,8 +267,8 @@ func (s *E2ETestSuite) getChainFactory() *interchaintest.BuiltinChainFactory { { ProcessName: "attestationsidecar", Image: ibc.DockerImage{ - Repository: "attestationsidecar", - Version: "local", + Repository: "ghcr.io/cosmos/interchain-attestation-sidecar", + Version: version, UidGid: "1025:1025", }, HomeDir: "", @@ -279,15 +286,15 @@ func (s *E2ETestSuite) getChainFactory() *interchaintest.BuiltinChainFactory { { Name: "rollupsimapp", ChainName: "rollupsimapp", - Version: "local", + Version: version, ChainConfig: ibc.ChainConfig{ Type: "cosmos", Name: "rollupsimapp", ChainID: rollupsimappChainID, Images: []ibc.DockerImage{ { - Repository: "rollupsimapp", - Version: "local", + Repository: "ghcr.io/cosmos/interchain-attestation-rollupsimapp", + Version: version, UidGid: "1025:1025", }, }, @@ -364,8 +371,8 @@ da_address = \"http://%s:%s\""`+" >> /var/cosmos-chain/rollupsimapp/config/confi { ProcessName: "mock-da", Image: ibc.DockerImage{ - Repository: "mock-da", - Version: "local", + Repository: "ghcr.io/cosmos/interchain-attestation-mock-da", + Version: version, UidGid: "1025:1025", }, HomeDir: "",