diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8c96843..82e7a68 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 @@ -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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7485c76..fab2034 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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" \ No newline at end of file diff --git a/tests/test_yepcode_run.py b/tests/test_yepcode_run.py index a8bd9ba..f1de554 100644 --- a/tests/test_yepcode_run.py +++ b/tests/test_yepcode_run.py @@ -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() @@ -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() @@ -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() @@ -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), @@ -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}, ) @@ -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}, ) @@ -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,