|
| 1 | +# Required secrets for real publishing: |
| 2 | +# - NPM_TOKEN |
| 3 | +# - PYPI_API_TOKEN |
| 4 | +# - CARGO_REGISTRY_TOKEN |
| 5 | +name: Publish SDKs |
| 6 | + |
| 7 | +on: |
| 8 | + push: |
| 9 | + tags: |
| 10 | + - "v*" |
| 11 | + workflow_dispatch: |
| 12 | + inputs: |
| 13 | + dry_run: |
| 14 | + description: "Build and validate publish commands without uploading packages" |
| 15 | + required: true |
| 16 | + type: boolean |
| 17 | + default: true |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: read |
| 21 | + id-token: write |
| 22 | + |
| 23 | +concurrency: |
| 24 | + group: publish-sdks-${{ github.ref }} |
| 25 | + cancel-in-progress: false |
| 26 | + |
| 27 | +jobs: |
| 28 | + verify: |
| 29 | + name: Verify SDKs |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v4 |
| 33 | + |
| 34 | + - uses: actions/setup-node@v4 |
| 35 | + with: |
| 36 | + node-version: 22 |
| 37 | + cache: npm |
| 38 | + |
| 39 | + - uses: actions/setup-python@v5 |
| 40 | + with: |
| 41 | + python-version: "3.12" |
| 42 | + |
| 43 | + - name: Install TypeScript dependencies |
| 44 | + run: npm ci |
| 45 | + |
| 46 | + - name: Check SDK versions |
| 47 | + run: | |
| 48 | + python3 - <<'PY' |
| 49 | + import json |
| 50 | + import os |
| 51 | + import pathlib |
| 52 | + import sys |
| 53 | + import tomllib |
| 54 | +
|
| 55 | + root = pathlib.Path.cwd() |
| 56 | + npm_version = json.loads((root / "packages/agent-protocols/package.json").read_text())["version"] |
| 57 | + py_version = tomllib.loads((root / "python/agent-protocols/pyproject.toml").read_text())["project"]["version"] |
| 58 | + cargo_version = tomllib.loads((root / "crates/agent-protocols/Cargo.toml").read_text())["package"]["version"] |
| 59 | +
|
| 60 | + versions = { |
| 61 | + "npm": npm_version, |
| 62 | + "python": py_version, |
| 63 | + "cargo": cargo_version, |
| 64 | + } |
| 65 | + if len(set(versions.values())) != 1: |
| 66 | + print(f"SDK versions must match before publishing: {versions}", file=sys.stderr) |
| 67 | + sys.exit(1) |
| 68 | +
|
| 69 | + ref_type = os.environ.get("GITHUB_REF_TYPE") |
| 70 | + ref_name = os.environ.get("GITHUB_REF_NAME") |
| 71 | + expected_tag = f"v{npm_version}" |
| 72 | + if ref_type == "tag" and ref_name != expected_tag: |
| 73 | + print(f"Tag {ref_name} does not match SDK version {expected_tag}", file=sys.stderr) |
| 74 | + sys.exit(1) |
| 75 | +
|
| 76 | + print(f"SDK version: {npm_version}") |
| 77 | + PY |
| 78 | +
|
| 79 | + - name: Run TypeScript checks |
| 80 | + run: | |
| 81 | + npm test |
| 82 | + npm run build |
| 83 | +
|
| 84 | + - name: Run Python tests |
| 85 | + run: | |
| 86 | + python3 -m pip install --upgrade pip |
| 87 | + python3 -m pip install -e ./python/agent-protocols |
| 88 | + python3 -m unittest discover -s python/agent-protocols/tests |
| 89 | +
|
| 90 | + - name: Run Rust tests |
| 91 | + run: | |
| 92 | + rustup update --no-self-update stable |
| 93 | + cargo test --all-features |
| 94 | +
|
| 95 | + publish-npm: |
| 96 | + name: Publish TypeScript SDK to npm |
| 97 | + runs-on: ubuntu-latest |
| 98 | + needs: verify |
| 99 | + steps: |
| 100 | + - uses: actions/checkout@v4 |
| 101 | + |
| 102 | + - uses: actions/setup-node@v4 |
| 103 | + with: |
| 104 | + node-version: 22 |
| 105 | + cache: npm |
| 106 | + registry-url: "https://registry.npmjs.org" |
| 107 | + |
| 108 | + - name: Build package |
| 109 | + run: | |
| 110 | + npm ci |
| 111 | + npm run build --workspace agent-protocols |
| 112 | +
|
| 113 | + - name: Dry-run npm publish |
| 114 | + if: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run }} |
| 115 | + working-directory: packages/agent-protocols |
| 116 | + run: npm publish --dry-run --access public |
| 117 | + |
| 118 | + - name: Publish to npm |
| 119 | + if: ${{ github.event_name == 'push' || inputs.dry_run == false }} |
| 120 | + working-directory: packages/agent-protocols |
| 121 | + env: |
| 122 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 123 | + run: npm publish --access public --provenance |
| 124 | + |
| 125 | + publish-pypi: |
| 126 | + name: Publish Python SDK to PyPI |
| 127 | + runs-on: ubuntu-latest |
| 128 | + needs: verify |
| 129 | + steps: |
| 130 | + - uses: actions/checkout@v4 |
| 131 | + |
| 132 | + - uses: actions/setup-python@v5 |
| 133 | + with: |
| 134 | + python-version: "3.12" |
| 135 | + |
| 136 | + - name: Build package |
| 137 | + run: | |
| 138 | + python3 -m pip install --upgrade pip |
| 139 | + python3 -m pip install build twine |
| 140 | + python3 -m build python/agent-protocols |
| 141 | + python3 -m twine check python/agent-protocols/dist/* |
| 142 | +
|
| 143 | + - name: Dry-run PyPI publish |
| 144 | + if: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run }} |
| 145 | + run: python3 -m twine check python/agent-protocols/dist/* |
| 146 | + |
| 147 | + - name: Publish to PyPI |
| 148 | + if: ${{ github.event_name == 'push' || inputs.dry_run == false }} |
| 149 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 150 | + with: |
| 151 | + packages-dir: python/agent-protocols/dist |
| 152 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 153 | + |
| 154 | + publish-cargo: |
| 155 | + name: Publish Rust SDK to crates.io |
| 156 | + runs-on: ubuntu-latest |
| 157 | + needs: verify |
| 158 | + steps: |
| 159 | + - uses: actions/checkout@v4 |
| 160 | + |
| 161 | + - name: Prepare Rust toolchain |
| 162 | + run: rustup update --no-self-update stable |
| 163 | + |
| 164 | + - name: Dry-run cargo publish |
| 165 | + if: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run }} |
| 166 | + run: cargo publish -p agent-protocols --dry-run |
| 167 | + |
| 168 | + - name: Publish to crates.io |
| 169 | + if: ${{ github.event_name == 'push' || inputs.dry_run == false }} |
| 170 | + env: |
| 171 | + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} |
| 172 | + run: cargo publish -p agent-protocols --token "$CARGO_REGISTRY_TOKEN" |
0 commit comments