Skip to content

Commit

Permalink
[CI] Integrate E2E tests with GitHub CI (#152)
Browse files Browse the repository at this point in the history
* add more debug output

* Empty commit

* symlink to pocketd for now

* rename pocketd

* --wip-- [skip ci]

* removing pocketd completely

* also remove comment

* rename repo

* test the permissions

* test permissions

* set project_id: ${{ secrets.GKE_PROTOCOL_PROJECT }}

* maybe that will help

* test perms

* try that

* test job

* try ls

* add checkout

* separate the jobs

* ignite is needed for tests

* avoid collision on name

* backoffLimit 0

* wait for pod

* change envs

* add wait for sequencer before running a test

* fix jq

* fail fast

* move to a script

* try this

* image sha to image tag

* dont use make targets then

* troubleshoot

* pre-populate the variable

* add debug output

* install more stuff into the container

* try this

* cleanup

* devnet-test-e2e label everywhere

* add env

* Update .github/workflows-helpers/run-e2e-test.sh

Co-authored-by: Daniel Olshansky <[email protected]>

* Update .github/workflows/run-tests.yml

Co-authored-by: Daniel Olshansky <[email protected]>

* requested changes

---------

Co-authored-by: Daniel Olshansky <[email protected]>
  • Loading branch information
okdas and Olshansk authored Nov 15, 2023
1 parent c6d29c2 commit cd68749
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 28 deletions.
14 changes: 7 additions & 7 deletions .github/label-actions.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# When `devnet-e2e-test` is added, also assign `devnet` to the PR.
devnet-e2e-test:
# When `devnet-test-e2e` is added, also assign `devnet` to the PR.
devnet-test-e2e:
prs:
comment: The CI will now also run the e2e tests on devnet, which increases the time it takes to complete all CI checks.
label:
- devnet
- push-image

# When `devnet-e2e-test` is removed, also delete `devnet` from the PR.
-devnet-e2e-test:
# When `devnet-test-e2e` is removed, also delete `devnet` from the PR.
-devnet-test-e2e:
prs:
unlabel:
- devnet
Expand All @@ -18,11 +18,11 @@ devnet:
label:
- push-image

# When `devnet` is removed, also delete `devnet-e2e-test` from the PR.
# When `devnet` is removed, also delete `devnet-test-e2e` from the PR.
-devnet:
prs:
unlabel:
- devnet-e2e-test
- devnet-test-e2e

# Let the developer know that they need to push another commit after attaching the label to PR.
push-image:
Expand All @@ -34,4 +34,4 @@ push-image:
prs:
unlabel:
- devnet
- devnet-e2e-test
- devnet-test-e2e
45 changes: 45 additions & 0 deletions .github/workflows-helpers/run-e2e-test-job-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: batch/v1
kind: Job
metadata:
name: ${JOB_NAME}
namespace: ${NAMESPACE}
spec:
ttlSecondsAfterFinished: 120
template:
spec:
containers:
- name: e2e-tests
image: ghcr.io/pokt-network/poktrolld:${IMAGE_TAG}
command: ["/bin/sh"]
args: ["-c", "poktrolld q gateway list-gateway --node=$POCKET_NODE && poktrolld q application list-application --node=$POCKET_NODE && poktrolld q supplier list-supplier --node=$POCKET_NODE && go test -v ./e2e/tests/... -tags=e2e"]
env:
- name: AUTH_TOKEN
valueFrom:
secretKeyRef:
key: auth_token
name: celestia-secret
- name: POCKET_NODE
value: tcp://${NAMESPACE}-sequencer:36657
- name: E2E_DEBUG_OUTPUT
value: "false" # Flip to true to see the command and result of the execution
- name: POKTROLLD_HOME
value: /root/.pocket
- name: CELESTIA_HOSTNAME
value: celestia-rollkit
volumeMounts:
- mountPath: /root/.pocket/keyring-test/
name: keys-volume
- mountPath: /root/.pocket/config/
name: configs-volume
restartPolicy: Never
volumes:
- configMap:
defaultMode: 420
name: poktrolld-keys
name: keys-volume
- configMap:
defaultMode: 420
name: poktrolld-configs
name: configs-volume
serviceAccountName: default
backoffLimit: 0
55 changes: 55 additions & 0 deletions .github/workflows-helpers/run-e2e-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Check if the pod with the matching image SHA and purpose is ready
echo "Checking for ready sequencer pod with image SHA ${IMAGE_TAG}..."
while : ; do
# Get all pods with the matching purpose
PODS_JSON=$(kubectl get pods -n ${NAMESPACE} -l pokt.network/purpose=sequencer -o json)

# Check if any pods are running and have the correct image SHA
READY_POD=$(echo $PODS_JSON | jq -r ".items[] | select(.status.phase == \"Running\") | select(.spec.containers[].image | contains(\"${IMAGE_TAG}\")) | .metadata.name")

if [[ -n "${READY_POD}" ]]; then
echo "Ready pod found: ${READY_POD}"
break
else
echo "Sequencer with with an image ${IMAGE_TAG} is not ready yet. Will retry in 10 seconds..."
sleep 10
fi
done

# Create a job to run the e2e tests
envsubst < .github/workflows-helpers/run-e2e-test-job-template.yaml > job.yaml
kubectl apply -f job.yaml

# Wait for the pod to be created and be in a running state
echo "Waiting for the pod to be in the running state..."
while : ; do
POD_NAME=$(kubectl get pods -n ${NAMESPACE} --selector=job-name=${JOB_NAME} -o jsonpath='{.items[*].metadata.name}')
[[ -z "${POD_NAME}" ]] && echo "Waiting for pod to be scheduled..." && sleep 5 && continue
POD_STATUS=$(kubectl get pod ${POD_NAME} -n ${NAMESPACE} -o jsonpath='{.status.phase}')
[[ "${POD_STATUS}" == "Running" ]] && break
echo "Current pod status: ${POD_STATUS}"
sleep 5
done

echo "Pod is running. Monitoring logs and status..."
# Stream the pod logs in the background
kubectl logs -f ${POD_NAME} -n ${NAMESPACE} &

# Monitor pod status in a loop
while : ; do
CURRENT_STATUS=$(kubectl get pod ${POD_NAME} -n ${NAMESPACE} -o jsonpath="{.status.containerStatuses[0].state}")
if echo $CURRENT_STATUS | grep -q 'terminated'; then
EXIT_CODE=$(echo $CURRENT_STATUS | jq '.terminated.exitCode')
if [[ "$EXIT_CODE" != "0" ]]; then
echo "Container terminated with exit code ${EXIT_CODE}"
kubectl delete job ${JOB_NAME} -n ${NAMESPACE}
exit 1
fi
break
fi
sleep 5
done

# If the loop exits without failure, the job succeeded
echo "Job completed successfully"
kubectl delete job ${JOB_NAME} -n ${NAMESPACE}
59 changes: 41 additions & 18 deletions .github/workflows/go.yml → .github/workflows/main-build.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Ignite build & test
name: Main build

on:
push:
branches: ["main"]
pull_request:

concurrency:
group: ${{ github.head_ref || github.ref_name }}
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true

jobs:
build:
build-push-container:
runs-on: ubuntu-latest
steps:
- name: install ignite
Expand All @@ -29,26 +26,17 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
go-version: "1.20.10"

- name: Install CI dependencies
run: make install_ci_deps

- name: Generate protobufs
run: make proto_regen

- name: Generate mocks
run: make go_mockgen

- name: Run golangci-lint
run: make go_lint

- name: Build
run: ignite chain build -v --debug --skip-proto

- name: Test
run: make go_test

- name: Set up Docker Buildx
if: (github.ref == 'refs/heads/main') || (contains(github.event.pull_request.labels.*.name, 'push-image'))
uses: docker/setup-buildx-action@v3
Expand All @@ -61,7 +49,7 @@ jobs:
DOCKER_METADATA_PR_HEAD_SHA: "true"
with:
images: |
ghcr.io/pokt-network/pocketd
ghcr.io/pokt-network/poktrolld
tags: |
type=ref,event=branch
type=ref,event=pr
Expand All @@ -76,11 +64,13 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Copy binary to inside of the Docker context
- name: Copy binaries to inside of the Docker context
if: (github.ref == 'refs/heads/main') || (contains(github.event.pull_request.labels.*.name, 'push-image'))
run: |
mkdir -p ./bin # Make sure the bin directory exists
cp $(which ignite) ./bin # Copy ignite binary to the repo's bin directory
cp $(go env GOPATH)/bin/poktrolld ./bin # Copy the binary to the repo's bin directory
ls -la ./bin
- name: Build and push Docker image
if: (github.ref == 'refs/heads/main') || (contains(github.event.pull_request.labels.*.name, 'push-image'))
Expand All @@ -95,3 +85,36 @@ jobs:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .

run-e2e-tests:
needs: build-push-container
if: contains(github.event.pull_request.labels.*.name, 'devnet-test-e2e')
runs-on: ubuntu-latest
env:
GKE_CLUSTER: protocol-us-central1
GKE_ZONE: us-central1
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: |
.github
- id: 'auth'
name: 'Authenticate to Google Cloud'
uses: 'google-github-actions/auth@v1'
with:
credentials_json: '${{ secrets.GKE_PROTOCOL_US_CENTRAL }}'

- uses: google-github-actions/get-gke-credentials@v1
with:
cluster_name: ${{ env.GKE_CLUSTER }}
location: ${{ env.GKE_ZONE }}
project_id: ${{ secrets.GKE_PROTOCOL_PROJECT }}

- name: Run E2E test job
env:
IMAGE_TAG: sha-${{ github.event.pull_request.head.sha || github.sha }}
NAMESPACE: devnet-issue-${{ github.event.number }}
JOB_NAME: e2e-test-${{ github.event.pull_request.head.sha || github.sha }}
POCKET_NODE: tcp://devnet-issue-${{ github.event.number }}-sequencer:36657
run: bash .github/workflows-helpers/run-e2e-test.sh
4 changes: 4 additions & 0 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
pull_request:
branches: ["main"]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true

jobs:
# Makes sure that comments like TODO_IN_THIS_PR or TODO_IN_THIS_COMMIT block merging to main
# More info: https://github.com/pokt-network/action-fail-on-found
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Run tests

on:
push:
branches: ["main"]
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true

env:
GKE_CLUSTER: protocol-us-central1
GKE_ZONE: us-central1

jobs:
go-test:
runs-on: ubuntu-latest
steps:
- name: install ignite
# If this step fails due to ignite.com failing, see #116 for a temporary workaround
run: |
curl https://get.ignite.com/cli! | bash
ignite version
- uses: actions/checkout@v3
with:
fetch-depth: "0" # Per https://github.com/ignite/cli/issues/1674#issuecomment-1144619147

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.20.10"

- name: Install CI dependencies
run: make install_ci_deps

- name: Generate protobufs
run: make proto_regen

- name: Generate mocks
run: make go_mockgen

- name: Run golangci-lint
run: make go_lint

- name: Test
run: make go_test
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ localnet/*/config/*.json
!localnet/poktrolld/config/client.toml
!localnet/poktrolld/config/config.toml


# Macos
.DS_Store
**/.DS_Store
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ FROM golang:1.20 as base
RUN apt update && \
apt-get install -y \
ca-certificates \
curl jq make
curl jq make vim less

# enable faster module downloading.
ENV GOPROXY https://proxy.golang.org
Expand All @@ -15,7 +15,7 @@ COPY . /poktroll

WORKDIR /poktroll

RUN mv /poktroll/bin/poktrolld /usr/bin/poktrolld
RUN mv /poktroll/bin/ignite /usr/bin/ && mv /poktroll/bin/poktrolld /usr/bin/

EXPOSE 8545
EXPOSE 8546
Expand Down
6 changes: 6 additions & 0 deletions e2e/tests/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ var (
defaultRPCHost = "127.0.0.1"
// defaultHome is the default home directory for pocketd
defaultHome = os.Getenv("POKTROLLD_HOME")
// defaultDebugOutput provides verbose output on manipulations with binaries (cli command, stdout, stderr)
defaultDebugOutput = os.Getenv("E2E_DEBUG_OUTPUT")
)

func init() {
Expand Down Expand Up @@ -93,5 +95,9 @@ func (p *pocketdBin) runCmd(args ...string) (*commandResult, error) {
err = fmt.Errorf("error running command [%s]: %v, stderr: %s", commandStr, err, stderrBuf.String())
}

if defaultDebugOutput == "true" {
fmt.Printf("%#v\n", r)
}

return r, err
}

0 comments on commit cd68749

Please sign in to comment.