Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Integrate E2E tests with GitHub CI #152

Merged
merged 46 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
c458279
add more debug output
okdas Nov 7, 2023
c933eb2
Empty commit
okdas Nov 7, 2023
1f2d44d
symlink to pocketd for now
okdas Nov 7, 2023
341c7c5
rename pocketd
okdas Nov 7, 2023
0fff5bd
--wip-- [skip ci]
okdas Nov 7, 2023
8ff6e3d
removing pocketd completely
okdas Nov 7, 2023
0ebb318
also remove comment
okdas Nov 7, 2023
d356a84
Merge branch 'main' into issue/18-e2e-tests-automation
okdas Nov 9, 2023
9874e6a
rename repo
okdas Nov 9, 2023
0ab073b
test the permissions
okdas Nov 9, 2023
2937c5f
test permissions
okdas Nov 9, 2023
38fff23
set project_id: ${{ secrets.GKE_PROTOCOL_PROJECT }}
okdas Nov 9, 2023
0e2f159
maybe that will help
okdas Nov 9, 2023
2c2faa7
test perms
okdas Nov 9, 2023
216652b
try that
okdas Nov 9, 2023
e7a14c7
test job
okdas Nov 10, 2023
b3c8860
Merge branch 'main' into issue/18-e2e-tests-automation
okdas Nov 10, 2023
7f78a1c
try ls
okdas Nov 10, 2023
8b3eaf5
add checkout
okdas Nov 10, 2023
45844a2
separate the jobs
okdas Nov 10, 2023
af01e2a
ignite is needed for tests
okdas Nov 10, 2023
4f4b208
avoid collision on name
okdas Nov 10, 2023
74e7cb5
backoffLimit 0
okdas Nov 10, 2023
a9f7223
wait for pod
okdas Nov 10, 2023
e773092
change envs
okdas Nov 10, 2023
aa7ae7b
add wait for sequencer before running a test
okdas Nov 10, 2023
91057ae
fix jq
okdas Nov 10, 2023
f719c88
fail fast
okdas Nov 10, 2023
81eb71d
Merge branch 'main' into issue/18-e2e-tests-automation
okdas Nov 10, 2023
11100ba
move to a script
okdas Nov 10, 2023
cbc2f79
try this
okdas Nov 10, 2023
a7dd1f3
image sha to image tag
okdas Nov 10, 2023
349d822
dont use make targets then
okdas Nov 10, 2023
037b3a9
troubleshoot
okdas Nov 10, 2023
4424f56
pre-populate the variable
okdas Nov 10, 2023
191b0d4
add debug output
okdas Nov 10, 2023
57419d1
install more stuff into the container
okdas Nov 10, 2023
c29a74b
try this
okdas Nov 10, 2023
1885c4c
cleanup
okdas Nov 10, 2023
763f4ff
devnet-test-e2e label everywhere
okdas Nov 10, 2023
2e4355e
Merge branch 'main' into issue/18-e2e-tests-automation
okdas Nov 10, 2023
dc4ce63
add env
okdas Nov 10, 2023
726a96c
Update .github/workflows-helpers/run-e2e-test.sh
okdas Nov 15, 2023
f486920
Update .github/workflows/run-tests.yml
okdas Nov 15, 2023
65305ff
requested changes
okdas Nov 15, 2023
ad816cb
Merge branch 'main' into issue/18-e2e-tests-automation
okdas Nov 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

towelie-south-park

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker but just a question.

Is the plan to keep this bash script as is? I know you've used things like argoCD and other DAG like workflow builders, so was just surprised to have a simple bash script like it today.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Olshansk, if this will cause issues, we'll switch. Even with Argo Workflows with DAG, we are going to need some bash scripting. I'm not a fan of them, but we don't have the permissions/connectivity restraints we used to have on previous infrastructure so it seemed as an OK solution.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great comments throughout!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @openai

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
}
Loading