Skip to content

Commit 81d652d

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

File tree

5 files changed

+158
-93
lines changed

5 files changed

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

.github/workflows/main.yml

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -144,32 +144,11 @@ 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+
branch: ${{ github.head_ref }}
152+
changes_only: true
153+
commit_id: ${{ github.event.pull_request.base.sha }}
154+
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)