|
| 1 | +name: Build installable SDK package |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + native_provenance: |
| 7 | + type: string |
| 8 | + required: true |
| 9 | + runner: |
| 10 | + type: string |
| 11 | + required: true |
| 12 | + artifact_id: |
| 13 | + type: string |
| 14 | + required: true |
| 15 | + artifact_digest: |
| 16 | + type: string |
| 17 | + required: true |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: read |
| 21 | + actions: read |
| 22 | + |
| 23 | +jobs: |
| 24 | + build: |
| 25 | + name: Native package (${{ inputs.runner }}) |
| 26 | + runs-on: >- |
| 27 | + ${{ fromJSON( |
| 28 | + github.repository == 'openai/openai-agents-python' && inputs.runner == 'ubuntu-24.04' && '{"group":"codex-runners","labels":"codex-linux-x64"}' || |
| 29 | + github.repository == 'openai/openai-agents-python' && inputs.runner == 'windows-latest' && '{"group":"codex-runners","labels":"codex-windows-x64"}' || |
| 30 | + toJSON(inputs.runner) |
| 31 | + ) }} |
| 32 | + timeout-minutes: 100 |
| 33 | + defaults: |
| 34 | + run: |
| 35 | + shell: bash |
| 36 | + steps: |
| 37 | + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 |
| 38 | + with: |
| 39 | + persist-credentials: false |
| 40 | + - name: Configure Linux dependency registries |
| 41 | + if: runner.os == 'Linux' |
| 42 | + run: | |
| 43 | + { |
| 44 | + for variable in NPM_CONFIG_REGISTRY npm_config_registry PNPM_CONFIG_REGISTRY pnpm_config_registry COREPACK_NPM_REGISTRY YARN_NPM_REGISTRY_SERVER BUN_CONFIG_REGISTRY; do |
| 45 | + printf '%s=%s\n' "$variable" 'https://openai.firewall.socket.dev/npm/' |
| 46 | + done |
| 47 | + for variable in UV_DEFAULT_INDEX UV_INDEX_URL PIP_INDEX_URL; do |
| 48 | + printf '%s=%s\n' "$variable" 'https://openai.firewall.socket.dev/pypi/simple/' |
| 49 | + done |
| 50 | + } >> "$GITHUB_ENV" |
| 51 | + - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 |
| 52 | + with: |
| 53 | + python-version: "3.12" |
| 54 | + - uses: astral-sh/setup-uv@1c37ad07a6a961277cf70c0d37d6f313000f5884 |
| 55 | + with: |
| 56 | + enable-cache: false |
| 57 | + - name: Begin SDK qualification |
| 58 | + env: |
| 59 | + GH_TOKEN: ${{ github.token }} |
| 60 | + NATIVE_ARTIFACTS: ${{ format('{{"{0}-{1}":{{"id":{2},"digest":"sha256:{3}","provenance":{4}}}}}', runner.os, runner.arch, inputs.artifact_id, inputs.artifact_digest, inputs.native_provenance) }} |
| 61 | + NATIVE_SOURCE_RUN: ${{ github.run_id }} |
| 62 | + SNAPSHOT_DIRECTORY: ${{ runner.temp }}/agents-native-qualified |
| 63 | + run: python .github/scripts/download-native-snapshot.py |
| 64 | + - name: Prepare the source distribution |
| 65 | + # Use one stable source path for Cargo, the wheel and the test executor. |
| 66 | + run: | |
| 67 | + uv build --sdist |
| 68 | + python - <<'PYTHON' |
| 69 | + import os |
| 70 | + import tarfile |
| 71 | + from pathlib import Path |
| 72 | + source = Path(os.environ["RUNNER_TEMP"]) / "agents-native-source" |
| 73 | + source.mkdir() |
| 74 | + archive_path, = Path("dist").glob("openai_agents-*.tar.gz") |
| 75 | + with tarfile.open(archive_path) as archive: |
| 76 | + archive.extractall(source, filter="data") |
| 77 | + extracted, = source.iterdir() |
| 78 | + project = source / "project" |
| 79 | + extracted.rename(project) |
| 80 | + with open(os.environ["GITHUB_ENV"], "a", encoding="utf-8") as output: |
| 81 | + output.write(f"OPENAI_AGENTS_BUILD_SOURCE={project.resolve()}\n") |
| 82 | + PYTHON |
| 83 | + - name: Select the verified native overlay |
| 84 | + run: | |
| 85 | + python - <<'PYTHON' |
| 86 | + import os |
| 87 | + import shutil |
| 88 | + from pathlib import Path |
| 89 | + source = Path(os.environ["RUNNER_TEMP"]) / "agents-native-qualified" |
| 90 | + wheel, = source.glob("openai_agents-*.whl") |
| 91 | + name = "exec-server-fixture" + (".exe" if os.name == "nt" else "") |
| 92 | + Path("dist").mkdir(exist_ok=True) |
| 93 | + shutil.copy2(source / name, Path("dist") / name) |
| 94 | + with open(os.environ["GITHUB_ENV"], "a", encoding="utf-8") as output: |
| 95 | + output.write(f"OPENAI_AGENTS_NATIVE_WHEEL={wheel.resolve()}\n") |
| 96 | + output.write(f"OPENAI_AGENTS_NATIVE_RECEIPT_DIR={Path('dist').resolve()}\n") |
| 97 | + PYTHON |
| 98 | + - name: Repack the current Python SDK with the verified native snapshot |
| 99 | + run: uv build --wheel "$OPENAI_AGENTS_BUILD_SOURCE" --out-dir "$GITHUB_WORKSPACE/dist" |
| 100 | + - name: Install Linux sandbox runtime for fresh-wheel checks |
| 101 | + if: runner.os == 'Linux' |
| 102 | + run: | |
| 103 | + sudo apt-get update |
| 104 | + sudo apt-get install --yes bubblewrap dnsmasq-base |
| 105 | + - name: Test fresh installations without a checkout on the import path |
| 106 | + if: runner.os == 'Linux' |
| 107 | + run: | |
| 108 | + cp packages/codex/scripts/verify_installed.py "$RUNNER_TEMP/verify_installed.py" |
| 109 | + uv export --frozen --no-default-groups --no-emit-workspace --no-hashes \ |
| 110 | + --format requirements.txt --output-file "$RUNNER_TEMP/sdk-install-constraints.txt" |
| 111 | + for version in 3.10 3.11 3.12; do |
| 112 | + uv venv --seed --python "$version" "$RUNNER_TEMP/sdk-$version" |
| 113 | + "$RUNNER_TEMP/sdk-$version/bin/python" -m pip install \ |
| 114 | + --constraint "$RUNNER_TEMP/sdk-install-constraints.txt" dist/*.whl |
| 115 | + helper="$("$RUNNER_TEMP/sdk-$version/bin/python" -I - <<'PYTHON' |
| 116 | + import os |
| 117 | + import sysconfig |
| 118 | + from pathlib import Path |
| 119 | + import agents |
| 120 | + helper = (Path(agents.__file__).resolve().parent / "bin" / "codex-linux-sandbox").resolve() |
| 121 | + libraries = {Path(sysconfig.get_path(kind)).resolve() for kind in ("purelib", "platlib")} |
| 122 | + assert any(helper.is_relative_to(base) for base in libraries), "helper is outside the fresh environment" |
| 123 | + assert helper.is_file() and os.access(helper, os.X_OK), "installed Linux helper is not executable" |
| 124 | + runtime = helper.with_name("codex-sdk-runtime") |
| 125 | + assert runtime.is_file() and os.access(runtime, os.X_OK), "installed runtime is not executable" |
| 126 | + print(helper) |
| 127 | + PYTHON |
| 128 | + )" |
| 129 | + userns_restriction=unavailable |
| 130 | + profile_loaded=false |
| 131 | + if [[ -e /proc/sys/kernel/apparmor_restrict_unprivileged_userns ]]; then |
| 132 | + case "$(cat /proc/sys/kernel/apparmor_restrict_unprivileged_userns)" in |
| 133 | + 0) userns_restriction=0 ;; |
| 134 | + 1) userns_restriction=1 ;; |
| 135 | + *) userns_restriction=other ;; |
| 136 | + esac |
| 137 | + profile="agents-sdk-installed-linux-${version//./}" |
| 138 | + sudo tee "/etc/apparmor.d/$profile" > /dev/null <<EOF |
| 139 | + abi <abi/4.0>, |
| 140 | + include <tunables/global> |
| 141 | + profile $profile "$helper" flags=(unconfined) { |
| 142 | + userns, |
| 143 | + } |
| 144 | + profile $profile-runtime "${helper%/*}/codex-sdk-runtime" flags=(unconfined) { |
| 145 | + userns, |
| 146 | + } |
| 147 | + EOF |
| 148 | + sudo apparmor_parser -r "/etc/apparmor.d/$profile" |
| 149 | + profile_loaded=true |
| 150 | + fi |
| 151 | + printf 'Installed Linux sandbox host setup: userns_restriction=%s helper_profile_loaded=%s\n' "$userns_restriction" "$profile_loaded" |
| 152 | + ( |
| 153 | + cd "$RUNNER_TEMP" |
| 154 | + env -u OPENAI_API_KEY -u OPENAI_AGENTS_TEST_IN_CODEX_SANDBOX \ |
| 155 | + "$RUNNER_TEMP/sdk-$version/bin/python" -I verify_installed.py \ |
| 156 | + --output "$RUNNER_TEMP/installed-$version.json" |
| 157 | + ) |
| 158 | + done |
| 159 | + cp "$RUNNER_TEMP"/installed-*.json dist/ |
| 160 | + - name: Qualify canonical storage with the installed POSIX wheel |
| 161 | + if: runner.os == 'Linux' || runner.os == 'macOS' |
| 162 | + run: | |
| 163 | + stage=$(mktemp -d "$RUNNER_TEMP/canonical-storage.XXXXXX") |
| 164 | + mkdir -p "$stage/examples/canonical_storage" |
| 165 | + cp -R tests "$stage/tests" |
| 166 | + cp examples/canonical_storage/main.py "$stage/examples/canonical_storage" |
| 167 | + uv venv --seed --python 3.10 "$stage/venv" |
| 168 | + uv export --frozen --group dev --no-emit-workspace --no-hashes \ |
| 169 | + --format requirements.txt --output-file "$stage/constraints.txt" > /dev/null |
| 170 | + python="$stage/venv/bin/python" |
| 171 | + "$python" -m pip install --constraint "$stage/constraints.txt" dist/*.whl aiohttp pytest pytest-asyncio |
| 172 | + cd "$stage" |
| 173 | + "$python" -I -B - <<'PYTHON' |
| 174 | + import sys |
| 175 | + from pathlib import Path |
| 176 | + import agents |
| 177 | + import agents._native |
| 178 | +
|
| 179 | + prefix = Path(sys.prefix).resolve() |
| 180 | + assert Path(agents.__file__).resolve().is_relative_to(prefix) |
| 181 | + assert Path(agents._native.__file__).resolve().is_relative_to(prefix) |
| 182 | + print("Installed native revision:", agents._native.CODEX_REVISION) |
| 183 | + PYTHON |
| 184 | + chmod +x "$GITHUB_WORKSPACE/dist/exec-server-fixture" |
| 185 | + CODEX_EXEC_SERVER_TEST_BINARY="$GITHUB_WORKSPACE/dist/exec-server-fixture" \ |
| 186 | + "$python" -I -B -m pytest -q -o "pythonpath=$stage" -o asyncio_mode=auto \ |
| 187 | + tests/test_canonical_storage.py tests/test_canonical_storage_example.py \ |
| 188 | + tests/test_custom_storage_durability.py \ |
| 189 | + tests/test_native_local_descendant_receipts.py::test_local_descendant_admission_checks_receipts_without_resuming_work \ |
| 190 | + tests/test_native_local_descendant_receipts.py::test_local_reopen_refuses_cold_active_child_without_tool_receipt |
| 191 | + - name: Qualify offline Unix sockets with the installed Linux wheel |
| 192 | + if: runner.os == 'Linux' |
| 193 | + run: | |
| 194 | + stage=$(mktemp -d "$RUNNER_TEMP/offline-ipc.XXXXXX") |
| 195 | + mkdir -p "$stage/tests/qualification" "$stage/home" |
| 196 | + cp tests/{__init__,_asyncio,native_executor_fixtures,native_fixtures}.py "$stage/tests" |
| 197 | + cp tests/qualification/{offline_ipc.py,unix_socket_command.py,unix_peer_approval.py,offline_executor.sh} "$stage/tests/qualification" |
| 198 | + python="$RUNNER_TEMP/sdk-3.12/bin/python" |
| 199 | + uv export --frozen --only-group dev --no-emit-workspace --no-hashes \ |
| 200 | + --format requirements.txt --output-file "$stage/test-constraints.txt" |
| 201 | + "$python" -m pip install --constraint "$stage/test-constraints.txt" aiohttp pytest pytest-asyncio |
| 202 | + ( |
| 203 | + cd "$stage" |
| 204 | + env -i HOME="$stage/home" PATH=/usr/bin:/bin timeout 90 \ |
| 205 | + "$python" -I -B -m pytest -q -o "pythonpath=$stage" tests/qualification/unix_peer_approval.py |
| 206 | + ) |
| 207 | + chmod +x "$GITHUB_WORKSPACE/dist/exec-server-fixture" |
| 208 | + sudo unshare --mount --net --propagation private -- /bin/bash tests/qualification/run_offline_ipc.sh \ |
| 209 | + "$(readlink /proc/self/ns/net)" "$(readlink /proc/self/ns/mnt)" "$(id -u)" "$(id -g)" \ |
| 210 | + "$stage" "$python" "$GITHUB_WORKSPACE/dist/exec-server-fixture" |
| 211 | + - name: Test native macOS Unix socket policy with the installed wheel |
| 212 | + if: runner.os == 'macOS' |
| 213 | + run: | |
| 214 | + stage=$(mktemp -d "$RUNNER_TEMP/macos-ipc.XXXXXX") |
| 215 | + mkdir -p "$stage/tests/qualification" "$stage/home" |
| 216 | + cp tests/{__init__,_asyncio,native_executor_fixtures,native_fixtures}.py "$stage/tests" |
| 217 | + cp tests/qualification/{macos_ipc,offline_ipc,unix_socket_command}.py "$stage/tests/qualification" |
| 218 | + uv venv --seed --python "$(command -v python)" "$stage/venv" |
| 219 | + uv export --frozen --group dev --no-emit-workspace --no-hashes \ |
| 220 | + --format requirements.txt --output-file "$stage/constraints.txt" > /dev/null |
| 221 | + python="$stage/venv/bin/python" |
| 222 | + "$python" -m pip install --constraint "$stage/constraints.txt" dist/*.whl aiohttp pytest pytest-asyncio |
| 223 | + fixture="$GITHUB_WORKSPACE/dist/exec-server-fixture" |
| 224 | + chmod +x "$fixture" |
| 225 | + cd "$stage" |
| 226 | + env -i PATH=/usr/bin:/bin HOME="$stage/home" SHELL=/bin/sh \ |
| 227 | + "$python" -I -B -u -c 'import os,runpy,sys; sys.path.insert(0,os.getcwd()); runpy.run_module("tests.qualification.macos_ipc",run_name="__main__")' "$fixture" |
| 228 | + - name: Test Windows named pipes and Unix peer approval with the installed wheel |
| 229 | + if: runner.os == 'Windows' |
| 230 | + run: | |
| 231 | + stage=$(mktemp -d "$(cygpath -u "$RUNNER_TEMP")/windows-ipc.XXXXXX") |
| 232 | + mkdir -p "$stage/tests/qualification" |
| 233 | + cp tests/{__init__,_asyncio,native_executor_fixtures,native_fixtures}.py "$stage/tests" |
| 234 | + cp tests/qualification/{windows_ipc,offline_ipc,unix_peer_approval}.py "$stage/tests/qualification" |
| 235 | + uv venv --seed --python 3.12 "$stage/venv" |
| 236 | + uv export --frozen --group dev --no-emit-workspace --no-hashes \ |
| 237 | + --format requirements.txt --output-file "$stage/constraints.txt" > /dev/null |
| 238 | + "$stage/venv/Scripts/python.exe" -m pip install --constraint "$stage/constraints.txt" \ |
| 239 | + dist/*-win_amd64.whl aiohttp pytest pytest-asyncio |
| 240 | + python -I - "$stage" <<'PYTHON' |
| 241 | + import os |
| 242 | + import subprocess |
| 243 | + import sys |
| 244 | + from pathlib import Path |
| 245 | +
|
| 246 | + stage = Path(sys.argv[1]).resolve(strict=True) |
| 247 | + fixture = Path("dist/exec-server-fixture.exe").resolve(strict=True) |
| 248 | + keep = set(""" |
| 249 | + ALLUSERSPROFILE APPDATA COMMONPROGRAMFILES COMMONPROGRAMFILES(X86) COMMONPROGRAMW6432 |
| 250 | + COMPUTERNAME COMSPEC HOMEDRIVE HOMEPATH LOCALAPPDATA NUMBER_OF_PROCESSORS OS PATH PATHEXT |
| 251 | + PROCESSOR_ARCHITECTURE PROGRAMDATA PROGRAMFILES PROGRAMFILES(X86) PROGRAMW6432 PUBLIC |
| 252 | + SYSTEMDRIVE SYSTEMROOT TEMP TMP USERDOMAIN USERNAME USERPROFILE WINDIR |
| 253 | + """.split()) |
| 254 | + env = {key: value for key, value in os.environ.items() if key.upper() in keep} |
| 255 | + subprocess.run( |
| 256 | + [stage / "venv/Scripts/python.exe", "-I", "-B", "-c", |
| 257 | + "import os, sys, pytest; sys.path.insert(0, os.getcwd()); " |
| 258 | + "sys.exit(pytest.main(['-q', 'tests/qualification/unix_peer_approval.py']))"], |
| 259 | + cwd=stage, env=env, check=True, timeout=90, |
| 260 | + ) |
| 261 | + subprocess.run( |
| 262 | + [stage / "venv/Scripts/python.exe", "-I", "-B", "-u", "-c", |
| 263 | + "import os, runpy, sys; sys.path.insert(0, os.getcwd()); " |
| 264 | + "runpy.run_module('tests.qualification.windows_ipc', run_name='__main__')", fixture], |
| 265 | + cwd=stage, env=env, check=True, |
| 266 | + ) |
| 267 | + PYTHON |
| 268 | + - name: Share the package and test executor |
| 269 | + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 |
| 270 | + with: |
| 271 | + name: native-${{ runner.os }}-${{ runner.arch }} |
| 272 | + path: dist/ |
| 273 | + if-no-files-found: error |
| 274 | + retention-days: 14 |
0 commit comments