Skip to content

Commit 9d55584

Browse files
committed
Add strategy matrix to test GitHub Action
1 parent c8d1a07 commit 9d55584

File tree

2 files changed

+63
-28
lines changed

2 files changed

+63
-28
lines changed

.github/workflows/tests.yml

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,41 @@ name: Tests
22
on:
33
workflow_call:
44
workflow_dispatch:
5+
56
jobs:
67
test:
78
runs-on: ubuntu-latest
8-
container:
9-
image: python:3.12-slim
10-
env:
11-
YEPCODE_API_TOKEN: ${{ secrets.TEST_YEPCODE_API_TOKEN }}
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
python-version: ["3.11", "3.12", "3.13"]
13+
1214
steps:
1315
- uses: actions/checkout@v4
16+
17+
- name: Set up Python ${{ matrix.python-version }}
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
22+
- name: Install system dependencies
23+
run: |
24+
sudo apt-get update
25+
sudo apt-get install -y curl gcc g++
26+
1427
- name: Configure poetry
15-
run: |-
16-
apt update && apt install -y curl gcc g++ && curl -sSL https://install.python-poetry.org | python3 -
28+
run: |
29+
curl -sSL https://install.python-poetry.org | python3 -
1730
export PATH="${PATH}:${HOME}/.local/bin"
1831
echo "${HOME}/.local/bin" >> $GITHUB_PATH
1932
poetry install
33+
env:
34+
YEPCODE_API_TOKEN: ${{ secrets.TEST_YEPCODE_API_TOKEN }}
35+
2036
- name: Run pytest
2137
run: "poetry run pytest"
38+
env:
39+
YEPCODE_API_TOKEN: ${{ secrets.TEST_YEPCODE_API_TOKEN }}
40+
2241
- name: Build
2342
run: "poetry build"

tests/test_yepcode_run.py

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ def random_hex():
77
return secrets.token_hex(2)
88

99

10+
def random_js_comment():
11+
"""Generate a random JavaScript comment to avoid parallel execution conflicts"""
12+
return f"// random comment to avoid parallel executions conflict {random_hex()}"
13+
14+
15+
def random_py_comment():
16+
"""Generate a random Python comment to avoid parallel execution conflicts"""
17+
return f"# random comment to avoid parallel executions conflict {random_hex()}"
18+
19+
1020
@pytest.fixture(scope="session")
1121
def yep_code_env():
1222
env = YepCodeEnv()
@@ -46,15 +56,16 @@ def test_manage_env_vars(yep_code_env):
4656

4757
def test_run_javascript_code(yep_code_run):
4858
execution = yep_code_run.run(
49-
"""async function main() {
50-
const message = `Hello, ${process.env.WORLD_ENV_VAR}!`
59+
f"""async function main() {{
60+
{random_js_comment()}
61+
const message = `Hello, ${{process.env.WORLD_ENV_VAR}}!`
5162
console.log(message)
52-
return { message }
53-
}
63+
return {{ message }}
64+
}}
5465
55-
module.exports = {
66+
module.exports = {{
5667
main,
57-
};""",
68+
}};""",
5869
{"removeOnDone": True},
5970
)
6071
execution.wait_for_done()
@@ -64,12 +75,13 @@ def test_run_javascript_code(yep_code_run):
6475

6576
def test_run_python_code(yep_code_run):
6677
execution = yep_code_run.run(
67-
"""import os
78+
f"""import os
6879
6980
def main():
70-
message = f"Hello, {os.getenv('WORLD_ENV_VAR')}!"
81+
{random_py_comment()}
82+
message = f"Hello, {{os.getenv('WORLD_ENV_VAR')}}!"
7183
print(message)
72-
return {"message": message}""",
84+
return {{"message": message}}""",
7385
{"removeOnDone": True},
7486
)
7587
execution.wait_for_done()
@@ -80,13 +92,14 @@ def main():
8092
def test_trigger_on_log(yep_code_run):
8193
logs = []
8294
execution = yep_code_run.run(
83-
"""async function main() {
95+
f"""async function main() {{
96+
{random_js_comment()}
8497
console.log("Log message 1")
8598
console.log("Log message 2")
86-
return { success: true }
87-
}
99+
return {{ success: true }}
100+
}}
88101
89-
module.exports = { main };""",
102+
module.exports = {{ main }};""",
90103
{
91104
"removeOnDone": True,
92105
"onLog": lambda log_entry: logs.append(log_entry.message),
@@ -106,11 +119,12 @@ def on_finish(return_value):
106119
finish_value = return_value
107120

108121
execution = yep_code_run.run(
109-
"""async function main() {
110-
return { data: "test data" }
111-
}
122+
f"""async function main() {{
123+
{random_js_comment()}
124+
return {{ data: "test data" }}
125+
}}
112126
113-
module.exports = { main };""",
127+
module.exports = {{ main }};""",
114128
{"removeOnDone": True, "onFinish": on_finish},
115129
)
116130

@@ -126,11 +140,12 @@ def on_error(error):
126140
error_message = error["message"]
127141

128142
execution = yep_code_run.run(
129-
"""async function main() {
143+
f"""async function main() {{
144+
{random_js_comment()}
130145
throw new Error("Test error");
131-
}
146+
}}
132147
133-
module.exports = { main };""",
148+
module.exports = {{ main }};""",
134149
{"removeOnDone": True, "onError": on_error},
135150
)
136151

@@ -147,10 +162,11 @@ def on_finish(return_value):
147162
finish_value = return_value
148163

149164
execution = yep_code_run.run(
150-
"""def main():
165+
f"""def main():
166+
{random_py_comment()}
151167
print("Log message 1")
152168
print("Log message 2")
153-
return {"data": "python test"}""",
169+
return {{"data": "python test"}}""",
154170
{
155171
"language": "python",
156172
"removeOnDone": True,

0 commit comments

Comments
 (0)