Skip to content

Commit 76aa864

Browse files
ci: run all the integration tests on PR or push
1 parent 68cfec9 commit 76aa864

File tree

5 files changed

+154
-93
lines changed

5 files changed

+154
-93
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Integration Tests
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
branch:
7+
description: 'Branch to checkout and test'
8+
required: false
9+
type: string
10+
default: ''
11+
is_nightly:
12+
description: 'Whether this is a nightly run'
13+
required: false
14+
type: boolean
15+
default: false
16+
changes_only:
17+
description: 'Only build tests affected by changes'
18+
required: false
19+
type: boolean
20+
default: false
21+
commit_id:
22+
description: 'Base commit ID for change comparison'
23+
required: false
24+
type: string
25+
default: ''
26+
27+
jobs:
28+
build-integration-tests:
29+
runs-on: namespace-profile-large-ubuntu-24-04-amd64
30+
outputs:
31+
test_binaries: ${{ steps.build.outputs.test_binaries }}
32+
steps:
33+
- uses: actions/checkout@v4
34+
with:
35+
# Fetch the entire history.
36+
fetch-depth: 0
37+
ref: ${{ inputs.branch }}
38+
39+
- uses: ./.github/actions/bootstrap
40+
with:
41+
github_token: ${{ secrets.GITHUB_TOKEN }}
42+
43+
# Setup pypy for running Python scripts (scripts/run_tests.py).
44+
- uses: actions/setup-python@v5
45+
id: setup-pypy
46+
with:
47+
python-version: "pypy3.9"
48+
cache: "pip"
49+
- run: ln -s '${{ steps.setup-pypy.outputs.python-path }}' /usr/local/bin/pypy3.9
50+
- env:
51+
LD_LIBRARY_PATH: ${{ env.Python3_ROOT_DIR }}/bin
52+
run: echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV
53+
- run: pip install -r scripts/requirements.txt
54+
55+
- name: "Build integration tests"
56+
id: build
57+
run: |
58+
NIGHTLY_FLAG=""
59+
if [[ "${{ inputs.is_nightly }}" == "true" ]]; then
60+
NIGHTLY_FLAG="--is_nightly"
61+
fi
62+
CHANGES_FLAGS=""
63+
if [[ "${{ inputs.changes_only }}" == "true" ]]; then
64+
CHANGES_FLAGS="--changes_only --include_dependencies"
65+
if [[ -n "${{ inputs.commit_id }}" ]]; then
66+
CHANGES_FLAGS="$CHANGES_FLAGS --commit_id ${{ inputs.commit_id }}"
67+
fi
68+
fi
69+
scripts/run_tests.py --command build_integration $NIGHTLY_FLAG $CHANGES_FLAGS
70+
71+
- name: "Upload integration test binaries"
72+
if: steps.build.outputs.test_binaries
73+
uses: namespace-actions/upload-artifact@v1
74+
with:
75+
name: integration-test-binaries-${{ replace(inputs.branch || github.ref_name, '/', '-') }}
76+
path: ./target/debug
77+
compression-level: 0
78+
79+
run-integration-tests:
80+
needs: build-integration-tests
81+
if: needs.build-integration-tests.outputs.test_binaries
82+
runs-on: namespace-profile-large-ubuntu-24-04-amd64
83+
strategy:
84+
fail-fast: false
85+
matrix:
86+
test_binary: ${{ fromJson(needs.build-integration-tests.outputs.test_binaries) }}
87+
steps:
88+
- uses: actions/checkout@v4
89+
with:
90+
fetch-depth: 1
91+
ref: ${{ inputs.branch }}
92+
93+
- uses: ./.github/actions/bootstrap
94+
with:
95+
github_token: ${{ secrets.GITHUB_TOKEN }}
96+
97+
- name: "Download integration test binaries"
98+
uses: namespace-actions/download-artifact@v1
99+
with:
100+
name: integration-test-binaries-${{ replace(inputs.branch || github.ref_name, '/', '-') }}
101+
path: ./target/debug
102+
103+
- name: "Restore executable permissions"
104+
run: |
105+
chmod +x ./target/debug/apollo_node
106+
chmod +x ./target/debug/${{ matrix.test_binary }}
107+
108+
- name: "Run ${{ matrix.test_binary }}"
109+
run: ./target/debug/${{ matrix.test_binary }}
110+
env:
111+
SEED: 0
112+

.github/workflows/main.yml

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -144,32 +144,10 @@ jobs:
144144
env:
145145
SEED: 0
146146

147-
run-integration-tests:
148-
runs-on: namespace-profile-large-ubuntu-24-04-amd64
149-
steps:
150-
- uses: actions/checkout@v4
151-
with:
152-
# Fetch the entire history.
153-
fetch-depth: 0
154-
- uses: ./.github/actions/bootstrap
155-
with:
156-
github_token: ${{ secrets.GITHUB_TOKEN }}
157-
158-
# Setup pypy and link to the location expected by .cargo/config.toml.
159-
- uses: actions/setup-python@v5
160-
id: setup-pypy
161-
with:
162-
python-version: "pypy3.9"
163-
cache: "pip"
164-
- run: ln -s '${{ steps.setup-pypy.outputs.python-path }}' /usr/local/bin/pypy3.9
165-
- env:
166-
LD_LIBRARY_PATH: ${{ env.Python3_ROOT_DIR }}/bin
167-
run: echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV
168-
- run: pip install -r scripts/requirements.txt
169-
170-
- name: "Run integration tests pull request"
171-
if: github.event_name == 'pull_request'
172-
run: |
173-
scripts/run_tests.py --command integration --changes_only --include_dependencies --commit_id ${{ github.event.pull_request.base.sha }}
174-
env:
175-
SEED: 0
147+
integration-tests-pr:
148+
if: github.event_name == 'pull_request'
149+
uses: ./.github/workflows/integration-tests.yml
150+
with:
151+
changes_only: true
152+
commit_id: ${{ github.event.pull_request.base.sha }}
153+
secrets: inherit

.github/workflows/main_nightly.yml

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -89,33 +89,13 @@ jobs:
8989
- name: "Run feature combo on all crates."
9090
run: scripts/run_feature_combos_test.py
9191

92-
run-integration-tests:
93-
runs-on: namespace-profile-large-ubuntu-24-04-amd64
92+
integration-tests:
9493
needs: define_branches
9594
strategy:
9695
matrix:
9796
branch: ${{ fromJson(needs.define_branches.outputs.branches) }}
98-
steps:
99-
- uses: actions/checkout@v4
100-
with:
101-
ref: ${{ matrix.branch }}
102-
103-
- uses: ./.github/actions/bootstrap
104-
with:
105-
github_token: ${{ secrets.GITHUB_TOKEN }}
106-
107-
# Setup pypy and link to the location expected by .cargo/config.toml.
108-
- uses: actions/setup-python@v5
109-
id: setup-pypy
110-
with:
111-
python-version: "pypy3.9"
112-
- run: ln -s '${{ steps.setup-pypy.outputs.python-path }}' /usr/local/bin/pypy3.9
113-
- env:
114-
LD_LIBRARY_PATH: ${{ env.Python3_ROOT_DIR }}/bin
115-
run: echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV
116-
- run: pip install -r scripts/requirements.txt
117-
- name: "Run integration tests pull request"
118-
run: |
119-
scripts/run_tests.py --command integration --is_nightly
120-
env:
121-
SEED: 0
97+
uses: ./.github/workflows/integration-tests.yml
98+
with:
99+
branch: ${{ matrix.branch }}
100+
is_nightly: true
101+
secrets: inherit

crates/apollo_integration_tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Trigger CI integration tests
12
[package]
23
name = "apollo_integration_tests"
34
version.workspace = true

scripts/run_tests.py

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/env python3
22

33
import argparse
4+
import os
45
import subprocess
56
from enum import Enum
67
from typing import List, Optional, Set
@@ -18,24 +19,32 @@
1819

1920
# List of sequencer node integration test binary names. Stored as a list to maintain order.
2021
SEQUENCER_INTEGRATION_TEST_NAMES: List[str] = [
21-
"integration_test_restart_flow",
22-
]
23-
NIGHTLY_ONLY_SEQUENCER_INTEGRATION_TEST_NAMES: List[str] = [
2422
"integration_test_positive_flow",
2523
"integration_test_restart_flow",
2624
"integration_test_restart_service_multiple_nodes_flow",
2725
"integration_test_restart_service_single_node_flow",
2826
"integration_test_revert_flow",
29-
"integration_test_central_and_p2p_sync_flow",
27+
# TODO(shahak): revive this test
28+
# "integration_test_central_and_p2p_sync_flow",
3029
]
3130

3231

32+
def build_cmds(with_cairo_native: bool) -> List[List[str]]:
33+
feature_flag = ["--features", "cairo_native"] if with_cairo_native else []
34+
# Commands to build the node and all the test binaries.
35+
build_cmds = [
36+
["cargo", "build", "--bin", binary_name] + feature_flag
37+
for binary_name in [SEQUENCER_BINARY_NAME] + SEQUENCER_INTEGRATION_TEST_NAMES
38+
]
39+
return build_cmds
40+
41+
3342
# Enum of base commands.
3443
class BaseCommand(Enum):
3544
TEST = "test"
3645
CLIPPY = "clippy"
3746
DOC = "doc"
38-
INTEGRATION = "integration"
47+
BUILD_INTEGRATION = "build_integration"
3948

4049
def cmds(self, crates: Set[str], is_nightly: bool) -> List[List[str]]:
4150
package_args = []
@@ -50,46 +59,27 @@ def cmds(self, crates: Set[str], is_nightly: bool) -> List[List[str]]:
5059
elif self == BaseCommand.DOC:
5160
doc_args = package_args if len(package_args) > 0 else ["--workspace"]
5261
return [["cargo", "doc", "--document-private-items", "--no-deps"] + doc_args]
53-
elif self == BaseCommand.INTEGRATION:
62+
elif self == BaseCommand.BUILD_INTEGRATION:
5463
# Do nothing if integration tests should not be triggered; on nightly, run the tests.
5564
if INTEGRATION_TEST_CRATE_TRIGGERS.isdisjoint(crates) and not is_nightly:
5665
print(f"Skipping sequencer integration tests.")
5766
return []
5867

59-
integration_test_names_to_run = (
60-
NIGHTLY_ONLY_SEQUENCER_INTEGRATION_TEST_NAMES
61-
if is_nightly
62-
else SEQUENCER_INTEGRATION_TEST_NAMES
68+
with_cairo_native = (not CAIRO_NATIVE_CRATE_TRIGGERS.isdisjoint(crates)) or is_nightly
69+
70+
print(
71+
f"Composing sequencer integration test commands, with_cairo_native={with_cairo_native}."
6372
)
6473

65-
print(f"Composing sequencer integration test commands.")
66-
67-
def build_cmds(with_feature: bool) -> List[List[str]]:
68-
feature_flag = (
69-
["--features", "cairo_native"] if (with_feature and is_nightly) else []
70-
)
71-
# Commands to build the node and all the test binaries.
72-
build_cmds = [
73-
["cargo", "build", "--bin", binary_name] + feature_flag
74-
for binary_name in [SEQUENCER_BINARY_NAME] + integration_test_names_to_run
75-
]
76-
return build_cmds
77-
78-
# Commands to run the test binaries.
79-
run_cmds = [
80-
[f"./target/debug/{test_binary_name}"]
81-
for test_binary_name in integration_test_names_to_run
82-
]
83-
84-
cmds_no_feat = build_cmds(with_feature=False) + run_cmds
85-
86-
# Only run cairo_native feature if the blockifier crate is modified, and in nightly.
87-
if CAIRO_NATIVE_CRATE_TRIGGERS.isdisjoint(crates) and not is_nightly:
88-
return cmds_no_feat
89-
90-
print("Composing sequencer integration test commands with cairo_native feature.")
91-
cmds_with_feat = build_cmds(with_feature=True) + run_cmds
92-
return cmds_no_feat + cmds_with_feat
74+
cmds = build_cmds(with_cairo_native=with_cairo_native)
75+
76+
assert "GITHUB_OUTPUT" in os.environ:
77+
test_list = str(SEQUENCER_INTEGRATION_TEST_NAMES)
78+
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
79+
f.write(f"test_binaries={test_list}\n")
80+
print(f"Wrote test list to GITHUB_OUTPUT: {test_list}")
81+
82+
return cmds
9383

9484
raise NotImplementedError(f"Command {self} not implemented.")
9585

0 commit comments

Comments
 (0)