From 7df93997ad66d210de06e98eacb2ba9599b32158 Mon Sep 17 00:00:00 2001 From: Diogo Santos Date: Wed, 2 Apr 2025 10:56:05 +0100 Subject: [PATCH 1/4] Parallel tests --- .github/workflows/compose-tests.yml | 41 +++++++++++++ .github/workflows/integration-tests.yml | 26 +++++++++ .github/workflows/test.yml | 78 ------------------------- .github/workflows/unit-tests.yml | 65 +++++++++++++++++++++ core/fetcher/graffiti_internal_test.go | 2 +- 5 files changed, 133 insertions(+), 79 deletions(-) create mode 100644 .github/workflows/compose-tests.yml create mode 100644 .github/workflows/integration-tests.yml delete mode 100644 .github/workflows/test.yml create mode 100644 .github/workflows/unit-tests.yml diff --git a/.github/workflows/compose-tests.yml b/.github/workflows/compose-tests.yml new file mode 100644 index 0000000000..84ca08f8f1 --- /dev/null +++ b/.github/workflows/compose-tests.yml @@ -0,0 +1,41 @@ +name: Compose Tests +on: + pull_request: + push: + branches: + - main* + +concurrency: + group: compose-tests-${{ github.ref }} + cancel-in-progress: true + +jobs: + compose_tests: + runs-on: charon-ci + steps: + - uses: actions/checkout@v4 + - name: Set up QEMU + id: qemu + uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 + with: + driver-opts: "image=moby/buildkit:v0.10.5" + - uses: ./.github/actions/setup-go + - uses: actions/cache@v4 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - run: | + echo "CHARON_REPO=$(pwd)" >> $GITHUB_ENV + echo "DOCKER_BUILDKIT=1" >> $GITHUB_ENV + - run: go test -race github.com/obolnetwork/charon/testutil/compose/smoke -v -integration -sudo-perms -timeout=20m -log-dir=. + - uses: actions/upload-artifact@v4 + if: always() + with: + name: smoke-test-logs + path: testutil/compose/smoke/*.log + retention-days: 3 diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml new file mode 100644 index 0000000000..c25a0882a7 --- /dev/null +++ b/.github/workflows/integration-tests.yml @@ -0,0 +1,26 @@ +name: Integration Tests +on: + pull_request: + push: + branches: + - main* + +concurrency: + group: integration-tests-${{ github.ref }} + cancel-in-progress: true + +jobs: + integration_tests: + runs-on: charon-ci + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup-go + - uses: actions/cache@v4 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - run: go test -v -timeout=10m -race github.com/obolnetwork/charon/testutil/integration -integration diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index e8b272f09d..0000000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,78 +0,0 @@ -name: go tests -on: - pull_request: - push: - branches: - - main* -jobs: - unit_tests: - runs-on: charon-ci - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup-go - - uses: actions/cache@v4 - with: - path: | - ~/go/pkg/mod - ~/.cache/go-build - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - run: go test -coverprofile=coverage.out -covermode=atomic -timeout=5m -race ./... - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v5.4.0 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: coverage.out - - integration_tests: - runs-on: charon-ci - if: ${{ always() }} # makes this step always execute, even if unit_tests fails - needs: - - unit_tests - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup-go - - uses: actions/cache@v4 - with: - path: | - ~/go/pkg/mod - ~/.cache/go-build - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - run: go test -v -timeout=10m -race github.com/obolnetwork/charon/testutil/integration -integration - - compose_tests: - runs-on: charon-ci - if: ${{ always() }} # makes this step always execute, even if unit_tests or integration_tests fails - needs: - - unit_tests - - integration_tests - steps: - - uses: actions/checkout@v4 - - name: Set up QEMU - id: qemu - uses: docker/setup-qemu-action@v3 - - uses: docker/setup-buildx-action@v3 # For compose to build images - with: - driver-opts: "image=moby/buildkit:v0.10.5" # avoid unknown/unknown arch in ghcr - - uses: ./.github/actions/setup-go - - uses: actions/cache@v4 - with: - path: | - ~/go/pkg/mod - ~/.cache/go-build - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - run: | - echo "CHARON_REPO=$(pwd)" >> $GITHUB_ENV - echo "DOCKER_BUILDKIT=1" >> $GITHUB_ENV - - run: go test -race github.com/obolnetwork/charon/testutil/compose/smoke -v -integration -sudo-perms -timeout=20m -log-dir=. - - uses: actions/upload-artifact@v4 - if: always() - with: - name: smoke-test-logs - path: testutil/compose/smoke/*.log - retention-days: 3 diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 0000000000..f43b53865c --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -0,0 +1,65 @@ +name: Unit Tests +on: + pull_request: + push: + branches: + - main* + +concurrency: + group: unit-tests-${{ github.ref }} + cancel-in-progress: true + +jobs: + unit_tests: + runs-on: charon-ci + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup-go + - uses: actions/cache@v4 + with: + path: | + ~/go/pkg/mod + ~/.cache/go-build + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - run: go test -coverprofile=coverage.out -covermode=atomic -timeout=5m -race ./... + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v5.4.0 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: coverage.out + + - name: Cancel other workflows if this one fails + if: failure() + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + // Get all workflow runs + const runs = await github.rest.actions.listWorkflowRunsForRepo({ + owner: context.repo.owner, + repo: context.repo.repo, + status: 'in_progress', + branch: context.payload.pull_request?.head.ref, + }); + + for (const run of runs.data.workflow_runs) { + if (run.id === context.runId) { + continue; + } + if (run.name !== 'Integration Tests' && run.name !== 'Compose Tests') { + continue; + } + console.log(`Attempting to cancel workflow run ${run.id} (${run.name})`); + try { + const result = await github.rest.actions.cancelWorkflowRun({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: run.id + }); + console.log(`Cancellation API response status: ${result.status}`); + } catch (error) { + console.error(`Error cancelling workflow ${run.id}:`, error.message); + } + } diff --git a/core/fetcher/graffiti_internal_test.go b/core/fetcher/graffiti_internal_test.go index 71ea80fd54..fb914c2375 100644 --- a/core/fetcher/graffiti_internal_test.go +++ b/core/fetcher/graffiti_internal_test.go @@ -43,7 +43,7 @@ func TestFetchBeaconNodeToken(t *testing.T) { eth2Cl := mocks.NewClient(t) eth2Cl.On("NodeVersion", mock.Anything, mock.Anything).Return(ð2api.Response[string]{Data: "Lighthouse/v0.1.5 (Linux x86_64)"}, nil).Once() token := fetchBeaconNodeToken(eth2Cl) - require.Equal(t, "LH", token) + require.Equal(t, "LHH", token) }) } From 15752dcf940c170e54671e43bfc9f9908f69a393 Mon Sep 17 00:00:00 2001 From: Diogo Santos Date: Thu, 3 Apr 2025 10:04:52 +0100 Subject: [PATCH 2/4] fix test used for debugging CI --- core/fetcher/graffiti_internal_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/fetcher/graffiti_internal_test.go b/core/fetcher/graffiti_internal_test.go index fb914c2375..71ea80fd54 100644 --- a/core/fetcher/graffiti_internal_test.go +++ b/core/fetcher/graffiti_internal_test.go @@ -43,7 +43,7 @@ func TestFetchBeaconNodeToken(t *testing.T) { eth2Cl := mocks.NewClient(t) eth2Cl.On("NodeVersion", mock.Anything, mock.Anything).Return(ð2api.Response[string]{Data: "Lighthouse/v0.1.5 (Linux x86_64)"}, nil).Once() token := fetchBeaconNodeToken(eth2Cl) - require.Equal(t, "LHH", token) + require.Equal(t, "LH", token) }) } From 91c2d870559f147276e6fe73c3685e4c981e03bf Mon Sep 17 00:00:00 2001 From: Diogo Santos Date: Thu, 3 Apr 2025 10:10:45 +0100 Subject: [PATCH 3/4] add cancelation script to integration test workflow --- .github/workflows/integration-tests.yml | 34 +++++++++++++++++++++++++ .github/workflows/unit-tests.yml | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index c25a0882a7..9928f2115b 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -24,3 +24,37 @@ jobs: restore-keys: | ${{ runner.os }}-go- - run: go test -v -timeout=10m -race github.com/obolnetwork/charon/testutil/integration -integration + + - name: Cancel compose workflow if this workflow fails + if: failure() + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + // Get all workflow runs + const runs = await github.rest.actions.listWorkflowRunsForRepo({ + owner: context.repo.owner, + repo: context.repo.repo, + status: 'in_progress', + branch: context.payload.pull_request?.head.ref, + }); + + for (const run of runs.data.workflow_runs) { + if (run.id === context.runId) { + continue; + } + if (run.name !== 'Compose Tests') { + continue; + } + console.log(`Attempting to cancel workflow run ${run.id} (${run.name})`); + try { + const result = await github.rest.actions.cancelWorkflowRun({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: run.id + }); + console.log(`Cancellation API response status: ${result.status}`); + } catch (error) { + console.error(`Error cancelling workflow ${run.id}:`, error.message); + } + } diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index f43b53865c..e68390800b 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -30,7 +30,7 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.out - - name: Cancel other workflows if this one fails + - name: Cancel integration/compose workflows if this workflow fails if: failure() uses: actions/github-script@v6 with: From 54be67c1ebc7e310430ada9d0b72bf9304c5d58e Mon Sep 17 00:00:00 2001 From: Diogo Santos Date: Thu, 3 Apr 2025 12:07:56 +0100 Subject: [PATCH 4/4] remove cancelation scripts --- .github/workflows/integration-tests.yml | 34 ------------------------- .github/workflows/unit-tests.yml | 34 ------------------------- 2 files changed, 68 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 9928f2115b..c25a0882a7 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -24,37 +24,3 @@ jobs: restore-keys: | ${{ runner.os }}-go- - run: go test -v -timeout=10m -race github.com/obolnetwork/charon/testutil/integration -integration - - - name: Cancel compose workflow if this workflow fails - if: failure() - uses: actions/github-script@v6 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - // Get all workflow runs - const runs = await github.rest.actions.listWorkflowRunsForRepo({ - owner: context.repo.owner, - repo: context.repo.repo, - status: 'in_progress', - branch: context.payload.pull_request?.head.ref, - }); - - for (const run of runs.data.workflow_runs) { - if (run.id === context.runId) { - continue; - } - if (run.name !== 'Compose Tests') { - continue; - } - console.log(`Attempting to cancel workflow run ${run.id} (${run.name})`); - try { - const result = await github.rest.actions.cancelWorkflowRun({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: run.id - }); - console.log(`Cancellation API response status: ${result.status}`); - } catch (error) { - console.error(`Error cancelling workflow ${run.id}:`, error.message); - } - } diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index e68390800b..2771d109eb 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -29,37 +29,3 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} files: coverage.out - - - name: Cancel integration/compose workflows if this workflow fails - if: failure() - uses: actions/github-script@v6 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - // Get all workflow runs - const runs = await github.rest.actions.listWorkflowRunsForRepo({ - owner: context.repo.owner, - repo: context.repo.repo, - status: 'in_progress', - branch: context.payload.pull_request?.head.ref, - }); - - for (const run of runs.data.workflow_runs) { - if (run.id === context.runId) { - continue; - } - if (run.name !== 'Integration Tests' && run.name !== 'Compose Tests') { - continue; - } - console.log(`Attempting to cancel workflow run ${run.id} (${run.name})`); - try { - const result = await github.rest.actions.cancelWorkflowRun({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: run.id - }); - console.log(`Cancellation API response status: ${result.status}`); - } catch (error) { - console.error(`Error cancelling workflow ${run.id}:`, error.message); - } - }