Skip to content

Commit

Permalink
add basic ci pipelines. closes #14
Browse files Browse the repository at this point in the history
  • Loading branch information
gjermundgaraba committed Aug 28, 2024
1 parent c9d09c9 commit a470b6e
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 29 deletions.
86 changes: 86 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -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}
40 changes: 40 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
version: v1.60
args: --timeout 5m
working-directory: ${{ matrix.module }}
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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

7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
20 changes: 12 additions & 8 deletions justfile
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -28,5 +28,9 @@ test-unit:
cd configmodule && make test
cd sidecar && make test

test-e2e:
cd testing && make interchaintest
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
16 changes: 8 additions & 8 deletions testing/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###
Expand Down
27 changes: 17 additions & 10 deletions testing/interchaintest/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"os"
"path"
"strings"
"testing"
Expand Down Expand Up @@ -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",
},
},
Expand All @@ -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: "",
Expand All @@ -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",
},
},
Expand Down Expand Up @@ -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: "",
Expand Down

0 comments on commit a470b6e

Please sign in to comment.