|
| 1 | +--- |
| 2 | +name: update-protobuf |
| 3 | +description: >- |
| 4 | + Update the protobuf generated Python files from the latest |
| 5 | + microsoft/durabletask-protobuf definitions. Use when the proto definitions |
| 6 | + need to be refreshed or regenerated. |
| 7 | +--- |
| 8 | + |
| 9 | +# Update Protobuf Definitions |
| 10 | + |
| 11 | +This skill regenerates the Python protobuf files in `durabletask/internal/` |
| 12 | +from the latest proto source at |
| 13 | +<https://github.com/microsoft/durabletask-protobuf>. |
| 14 | + |
| 15 | +## Prerequisites |
| 16 | + |
| 17 | +- Python 3.11 must be available on the system. Verify with `py -3.11 --version` |
| 18 | + (Windows) or `python3.11 --version` (Linux/macOS). If it is not installed, |
| 19 | + stop and ask the user to install it — do **not** use a different version. |
| 20 | +- On Linux/macOS, [`jq`](https://jqlang.github.io/jq/) must be installed. |
| 21 | +- Internet access is required to download the proto file and query the GitHub |
| 22 | + API. |
| 23 | + |
| 24 | +## Steps |
| 25 | + |
| 26 | +### 1. Set up the `.proto_venv` environment (skip if it already exists) |
| 27 | + |
| 28 | +Check whether `.proto_venv/` already exists at the repo root and whether |
| 29 | +`grpcio-tools==1.65.4` is installed in it: |
| 30 | + |
| 31 | +```bash |
| 32 | +# Windows |
| 33 | +.proto_venv\Scripts\pip.exe list 2>$null | Select-String grpcio-tools |
| 34 | + |
| 35 | +# Bash |
| 36 | +.proto_venv/bin/pip list 2>/dev/null | grep grpcio-tools |
| 37 | +``` |
| 38 | + |
| 39 | +If the venv **does not exist** or `grpcio-tools` is missing, create/recreate it: |
| 40 | + |
| 41 | +```bash |
| 42 | +# Windows |
| 43 | +py -3.11 -m venv .proto_venv |
| 44 | +.proto_venv\Scripts\python.exe -m pip install grpcio-tools==1.65.4 |
| 45 | + |
| 46 | +# Bash |
| 47 | +python3.11 -m venv .proto_venv |
| 48 | +.proto_venv/bin/python -m pip install grpcio-tools==1.65.4 |
| 49 | +``` |
| 50 | + |
| 51 | +> [!NOTE] |
| 52 | +> Do **not** delete `.proto_venv` after use. It is reused across runs to avoid |
| 53 | +> reinstalling `grpcio-tools` each time. The directory is already in |
| 54 | +> `.gitignore`. |
| 55 | +
|
| 56 | +### 2. Download the latest proto file |
| 57 | + |
| 58 | +Download from the `main` branch of `microsoft/durabletask-protobuf`: |
| 59 | + |
| 60 | +```bash |
| 61 | +# Windows (PowerShell) |
| 62 | +Invoke-WebRequest ` |
| 63 | + -Uri "https://raw.githubusercontent.com/microsoft/durabletask-protobuf/refs/heads/main/protos/orchestrator_service.proto" ` |
| 64 | + -OutFile "durabletask/internal/orchestrator_service.proto" |
| 65 | + |
| 66 | +# Bash |
| 67 | +curl -o durabletask/internal/orchestrator_service.proto \ |
| 68 | + https://raw.githubusercontent.com/microsoft/durabletask-protobuf/refs/heads/main/protos/orchestrator_service.proto |
| 69 | +``` |
| 70 | + |
| 71 | +### 3. Regenerate the Python files |
| 72 | + |
| 73 | +Run `grpc_tools.protoc` from the **repo root**: |
| 74 | + |
| 75 | +```bash |
| 76 | +# Windows |
| 77 | +.proto_venv\Scripts\python.exe -m grpc_tools.protoc --proto_path=. --python_out=. --pyi_out=. --grpc_python_out=. ./durabletask/internal/orchestrator_service.proto |
| 78 | + |
| 79 | +# Bash |
| 80 | +.proto_venv/bin/python -m grpc_tools.protoc --proto_path=. --python_out=. --pyi_out=. --grpc_python_out=. ./durabletask/internal/orchestrator_service.proto |
| 81 | +``` |
| 82 | + |
| 83 | +This produces three files in `durabletask/internal/`: |
| 84 | + |
| 85 | +- `orchestrator_service_pb2.py` |
| 86 | +- `orchestrator_service_pb2_grpc.py` |
| 87 | +- `orchestrator_service_pb2.pyi` |
| 88 | + |
| 89 | +### 4. Update `PROTO_SOURCE_COMMIT_HASH` |
| 90 | + |
| 91 | +Query the GitHub API for the latest commit that touched the proto file and |
| 92 | +**overwrite** `durabletask/internal/PROTO_SOURCE_COMMIT_HASH` with that single |
| 93 | +hash: |
| 94 | + |
| 95 | +```bash |
| 96 | +# Windows (PowerShell) |
| 97 | +$response = Invoke-RestMethod ` |
| 98 | + -Uri "https://api.github.com/repos/microsoft/durabletask-protobuf/commits?path=protos/orchestrator_service.proto&sha=main&per_page=1" |
| 99 | +$response[0].sha | Out-File -FilePath "durabletask/internal/PROTO_SOURCE_COMMIT_HASH" -NoNewline -Encoding ascii |
| 100 | +
|
| 101 | +# Bash |
| 102 | +curl -s -H "Accept: application/vnd.github.v3+json" \ |
| 103 | + "https://api.github.com/repos/microsoft/durabletask-protobuf/commits?path=protos/orchestrator_service.proto&sha=main&per_page=1" \ |
| 104 | + | jq -jr '.[0].sha' > durabletask/internal/PROTO_SOURCE_COMMIT_HASH |
| 105 | +``` |
| 106 | + |
| 107 | +The file should contain exactly one commit hash with no trailing newline. |
| 108 | + |
| 109 | +### 5. Clean up the downloaded proto file |
| 110 | + |
| 111 | +Delete the `.proto` source file — only the generated Python files are kept in |
| 112 | +the repo: |
| 113 | + |
| 114 | +```bash |
| 115 | +# Windows |
| 116 | +Remove-Item durabletask/internal/orchestrator_service.proto |
| 117 | +
|
| 118 | +# Bash |
| 119 | +rm durabletask/internal/orchestrator_service.proto |
| 120 | +``` |
| 121 | + |
| 122 | +### 6. Verify |
| 123 | + |
| 124 | +Confirm the generated modules import successfully using the project's main |
| 125 | +venv: |
| 126 | +
|
| 127 | +```bash |
| 128 | +python -c "from durabletask.internal import orchestrator_service_pb2; print('pb2 OK'); from durabletask.internal import orchestrator_service_pb2_grpc; print('pb2_grpc OK')" |
| 129 | +``` |
| 130 | +
|
| 131 | +## Generated files |
| 132 | +
|
| 133 | +| File | Description | |
| 134 | +|---|---| |
| 135 | +| `durabletask/internal/orchestrator_service_pb2.py` | Message classes | |
| 136 | +| `durabletask/internal/orchestrator_service_pb2_grpc.py` | gRPC stubs | |
| 137 | +| `durabletask/internal/orchestrator_service_pb2.pyi` | Type stubs | |
| 138 | +| `durabletask/internal/PROTO_SOURCE_COMMIT_HASH` | Source commit hash | |
0 commit comments