Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ on:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
tests:
uses: ./.github/workflows/tests.yml
secrets: inherit

deploy:
needs: tests
runs-on: ubuntu-latest
container:
image: python:3.12-slim
Expand All @@ -25,6 +31,7 @@ jobs:
run: "poetry build"
- name: Publish
run: "poetry config pypi-token.pypi ${{ secrets.PUBLIC_YEPCODE_PYPI_API_TOKEN }} && poetry publish"

create_release:
needs: deploy
name: Create Release
Expand Down
31 changes: 25 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,41 @@ name: Tests
on:
workflow_call:
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
container:
image: python:3.12-slim
env:
YEPCODE_API_TOKEN: ${{ secrets.TEST_YEPCODE_API_TOKEN }}
strategy:
fail-fast: false
matrix:
python-version: ["3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y curl gcc g++

- name: Configure poetry
run: |-
apt update && apt install -y curl gcc g++ && curl -sSL https://install.python-poetry.org | python3 -
run: |
curl -sSL https://install.python-poetry.org | python3 -
export PATH="${PATH}:${HOME}/.local/bin"
echo "${HOME}/.local/bin" >> $GITHUB_PATH
poetry install
env:
YEPCODE_API_TOKEN: ${{ secrets.TEST_YEPCODE_API_TOKEN }}

- name: Run pytest
run: "poetry run pytest"
env:
YEPCODE_API_TOKEN: ${{ secrets.TEST_YEPCODE_API_TOKEN }}

- name: Build
run: "poetry build"
60 changes: 38 additions & 22 deletions tests/test_yepcode_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ def random_hex():
return secrets.token_hex(2)


def random_js_comment():
"""Generate a random JavaScript comment to avoid parallel execution conflicts"""
return f"// random comment to avoid parallel executions conflict {random_hex()}"


def random_py_comment():
"""Generate a random Python comment to avoid parallel execution conflicts"""
return f"# random comment to avoid parallel executions conflict {random_hex()}"


@pytest.fixture(scope="session")
def yep_code_env():
env = YepCodeEnv()
Expand Down Expand Up @@ -46,15 +56,16 @@ def test_manage_env_vars(yep_code_env):

def test_run_javascript_code(yep_code_run):
execution = yep_code_run.run(
"""async function main() {
const message = `Hello, ${process.env.WORLD_ENV_VAR}!`
f"""async function main() {{
{random_js_comment()}
const message = `Hello, ${{process.env.WORLD_ENV_VAR}}!`
console.log(message)
return { message }
}
return {{ message }}
}}

module.exports = {
module.exports = {{
main,
};""",
}};""",
{"removeOnDone": True},
)
execution.wait_for_done()
Expand All @@ -64,12 +75,13 @@ def test_run_javascript_code(yep_code_run):

def test_run_python_code(yep_code_run):
execution = yep_code_run.run(
"""import os
f"""import os

def main():
message = f"Hello, {os.getenv('WORLD_ENV_VAR')}!"
{random_py_comment()}
message = f"Hello, {{os.getenv('WORLD_ENV_VAR')}}!"
print(message)
return {"message": message}""",
return {{"message": message}}""",
{"removeOnDone": True},
)
execution.wait_for_done()
Expand All @@ -80,13 +92,14 @@ def main():
def test_trigger_on_log(yep_code_run):
logs = []
execution = yep_code_run.run(
"""async function main() {
f"""async function main() {{
{random_js_comment()}
console.log("Log message 1")
console.log("Log message 2")
return { success: true }
}
return {{ success: true }}
}}

module.exports = { main };""",
module.exports = {{ main }};""",
{
"removeOnDone": True,
"onLog": lambda log_entry: logs.append(log_entry.message),
Expand All @@ -106,11 +119,12 @@ def on_finish(return_value):
finish_value = return_value

execution = yep_code_run.run(
"""async function main() {
return { data: "test data" }
}
f"""async function main() {{
{random_js_comment()}
return {{ data: "test data" }}
}}

module.exports = { main };""",
module.exports = {{ main }};""",
{"removeOnDone": True, "onFinish": on_finish},
)

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

execution = yep_code_run.run(
"""async function main() {
f"""async function main() {{
{random_js_comment()}
throw new Error("Test error");
}
}}

module.exports = { main };""",
module.exports = {{ main }};""",
{"removeOnDone": True, "onError": on_error},
)

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

execution = yep_code_run.run(
"""def main():
f"""def main():
{random_py_comment()}
print("Log message 1")
print("Log message 2")
return {"data": "python test"}""",
return {{"data": "python test"}}""",
{
"language": "python",
"removeOnDone": True,
Expand Down