From 2692d41d49d094c8d232f2af87fc575f1120842c Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Tue, 2 Jul 2024 10:44:13 -0700 Subject: [PATCH] ci: convert e2e to matrix --- .github/actions/e2e.yml | 113 ++++++++++++++++++++++++++++++++++++ .github/workflows/build.yml | 93 ----------------------------- .github/workflows/e2e.yml | 22 +++++++ 3 files changed, 135 insertions(+), 93 deletions(-) create mode 100644 .github/actions/e2e.yml create mode 100644 .github/workflows/e2e.yml diff --git a/.github/actions/e2e.yml b/.github/actions/e2e.yml new file mode 100644 index 0000000000..b0b81449c7 --- /dev/null +++ b/.github/actions/e2e.yml @@ -0,0 +1,113 @@ +name: Reusable E2E Testing Workflow +on: + workflow_call: + inputs: + runs_on: + description: 'The type of runner to run on (e.g., ubuntu-22.04)' + type: string + default: 'ubuntu-22.04' + make_target: + description: 'Makefile target to execute in the Start Test step' + required: true + type: string + timeout_minutes: + description: 'The maximum number of minutes the job can run' + type: number + default: 25 + run: + description: 'Whether to run the job or not' + required: true + type: boolean + +jobs: + e2e-test: + runs-on: ${{ inputs.runs_on }} + if: ${{ run }} + timeout-minutes: ${{ inputs.timeout_minutes }} + steps: + - uses: actions/checkout@v4 + + # configure docker to use the containerd snapshotter + # so that we can use the buildkit cache + - uses: depot/use-containerd-snapshotter-action@v1 + + - name: Login to Docker Hub registry + uses: docker/login-action@v2 + if: (github.event_name == 'push' && github.repository == 'zeta-chain/node') || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'zeta-chain/node') + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_READ_ONLY }} + + - name: Login to github docker registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Restore go cache + uses: actions/cache@v4 + id: restore-go-cache + with: + path: | + go-cache + key: cache-${{ hashFiles('go.sum') }} + lookup-only: ${{ github.event_name != 'push' }} + + - name: Inject go cache into docker + uses: reproducible-containers/buildkit-cache-dance@v3.1.2 + with: + cache-map: | + { + "go-cache": "/root/.cache/go-build" + } + skip-extraction: ${{ steps.restore-go-cache.outputs.cache-hit || github.event_name != 'push' }} + + # build zetanode with cache options + - name: Build zetanode for cache + uses: docker/build-push-action@v6 + env: + CACHE_FROM_CONFIG: "type=registry,ref=ghcr.io/${{ github.repository }}:buildcache" + CACHE_TO_CONFIG: "type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max" + with: + context: . + file: ./Dockerfile-localnet + push: false + tags: zetanode:latest + cache-from: ${{ env.CACHE_FROM_CONFIG }} + cache-to: ${{ github.event_name == 'push' && env.CACHE_TO_CONFIG || '' }} + target: latest-runtime + + - name: Start Test + run: make ${{ inputs.make_target }} + + # use docker logs -f rather than docker attach to make sure we get the initial logs + - name: Watch Test + run: | + container_id=$(docker ps --filter "ancestor=orchestrator:latest" --format "{{.ID}}") + docker logs -f "${container_id}" & + exit $(docker wait "${container_id}") + + - name: Full Log Dump On Failure + if: failure() + run: | + make stop-localnet + + - name: Notify Slack on Failure + if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/develop' + uses: 8398a7/action-slack@v3 + with: + status: ${{ job.status }} + fields: repo,message,commit,author,action,eventName,ref,workflow,job,took + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_CI_ALERTS }} + + - name: Stop Private Network + if: always() + run: | + make stop-localnet + + - name: Clean Up Workspace + if: always() + shell: bash + run: sudo rm -rf * \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0d316ebfb3..bc075e6447 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -100,96 +100,3 @@ jobs: if: always() shell: bash run: rm -rf * - - e2e-test: - runs-on: ubuntu-20.04 - timeout-minutes: 25 - steps: - - uses: actions/checkout@v4 - - # configure docker to use the containerd snapshotter - # so that we can use the buildkit cache - - uses: depot/use-containerd-snapshotter-action@v1 - - - name: Login to Docker Hub registry - uses: docker/login-action@v2 - if: (github.event_name == 'push' && github.repository == 'zeta-chain/node') || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == 'zeta-chain/node') - with: - username: ${{ secrets.DOCKER_HUB_USERNAME }} - password: ${{ secrets.DOCKER_HUB_READ_ONLY }} - - - name: Login to github docker registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Restore go cache - uses: actions/cache@v4 - id: restore-go-cache - with: - path: | - go-cache - key: cache-${{ hashFiles('go.sum') }} - lookup-only: ${{ github.event_name != 'push' }} - - - name: Inject go cache into docker - uses: reproducible-containers/buildkit-cache-dance@v3.1.2 - with: - cache-map: | - { - "go-cache": "/root/.cache/go-build" - } - skip-extraction: ${{ steps.restore-go-cache.outputs.cache-hit || github.event_name != 'push' }} - - # build zetanode with cache options - - name: Build zetanode for cache - uses: docker/build-push-action@v6 - env: - CACHE_FROM_CONFIG: "type=registry,ref=ghcr.io/${{ github.repository }}:buildcache" - CACHE_TO_CONFIG: "type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max" - with: - context: . - file: ./Dockerfile-localnet - push: false - tags: zetanode:latest - cache-from: ${{ env.CACHE_FROM_CONFIG }} - cache-to: ${{ github.event_name == 'push' && env.CACHE_TO_CONFIG || '' }} - target: latest-runtime - - - name: Start Test - run: make start-e2e-test - - # use docker logs -f rather than docker attach to make sure we get the initial logs - - name: Watch Test - run: | - container_id=$(docker ps --filter "ancestor=orchestrator:latest" --format "{{.ID}}") - docker logs -f "${container_id}" & - exit $(docker wait "${container_id}") - - - name: Full Log Dump On Failure - if: failure() - run: | - make stop-localnet - - - name: Notify Slack on Failure - if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/develop' - uses: 8398a7/action-slack@v3 - with: - status: ${{ job.status }} - fields: repo,message,commit,author,action,eventName,ref,workflow,job,took - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_CI_ALERTS }} - - - name: Stop Private Network - if: always() - run: | - make stop-localnet - - - name: Clean Up Workspace - if: always() - shell: bash - run: sudo rm -rf * - - diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml new file mode 100644 index 0000000000..16f7153630 --- /dev/null +++ b/.github/workflows/e2e.yml @@ -0,0 +1,22 @@ +name: e2e + +on: + push: + branches: + - develop + pull_request: + branches: + - "*" + +jobs: + e2e: + strategy: + matrix: + include: + - make_target: "start-e2e-test" + run: true + - make_target: "start-upgrade-test-light" + run: ${{ github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'MINIMAL_CI') }} + uses: ./.github/actions/e2e.yml + with: + make_target: ${{ matrix.make_target }} \ No newline at end of file