Skip to content

Commit 89fdbac

Browse files
committed
- Add some ignore rules in Changesets configuration for adding only the new python SDK
- Modify GitHub Actions workflow for Python SDK publishing - Update Python SDK for adding changeset and setup.py to use dynamic version from package.json
1 parent 2c62f72 commit 89fdbac

File tree

7 files changed

+73
-30
lines changed

7 files changed

+73
-30
lines changed

.changeset/config.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@
77
"changelog": false,
88
"bumpVersionsWithWorkspaceProtocolOnly": true,
99
"privatePackages": {
10-
"version": false,
10+
"version": true,
1111
"tag": false
12-
}
12+
},
13+
"ignore": [
14+
"@human-protocol/*-client",
15+
"@human-protocol/*-server",
16+
"@human-protocol/*-frontend",
17+
"@human-protocol/*-oracle",
18+
"@human-protocol/subgraph",
19+
"gcv"
20+
]
1321
}
Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,60 @@
11
name: Python SDK publish
22

3+
permissions:
4+
contents: write
5+
36
on:
4-
release:
5-
types: [published]
6-
workflow_dispatch:
7-
inputs:
8-
release_version:
9-
description: 'Release version to use'
10-
required: true
7+
push:
8+
branches:
9+
- main
10+
paths:
11+
- "packages/sdk/python/human-protocol-sdk/**"
1112

1213
jobs:
1314
publish-python-sdk:
1415
name: Publish Python SDK
1516
runs-on: ubuntu-latest
1617
steps:
1718
- uses: actions/checkout@v5
19+
with:
20+
token: ${{ secrets.GH_GITBOOK_TOKEN }}
1821
- uses: actions/setup-node@v4
1922
with:
2023
node-version-file: .nvmrc
2124
cache: yarn
22-
- name: Install dependencies
25+
- name: Install JS dependencies
2326
run: yarn install
2427
- name: Build core package
2528
run: yarn workspace @human-protocol/core build
2629
- name: Set up Python
2730
uses: actions/setup-python@v6
2831
with:
2932
python-version: "3.x"
30-
- name: Install dependencies
33+
- name: Read package version
34+
id: read_version
35+
run: |
36+
VERSION=$(jq -r '.version' packages/sdk/python/human-protocol-sdk/package.json)
37+
echo "version=$VERSION" >> $GITHUB_OUTPUT
38+
- name: Install build deps
3139
working-directory: ./packages/sdk/python/human-protocol-sdk
3240
run: |
3341
python -m pip install --upgrade pip
3442
pip install setuptools==68.2.2 wheel twine
35-
- name: Set the release version
36-
uses: "DamianReeves/write-file-action@master"
37-
if: ${{ github.event_name != 'workflow_dispatch' }}
38-
with:
39-
path: ./packages/sdk/python/human-protocol-sdk/human_protocol_sdk/__init__.py
40-
write-mode: overwrite
41-
contents: |
42-
__version__ = "${{ github.event.release.tag_name }}"
43-
- name: Set the release version
44-
uses: "DamianReeves/write-file-action@master"
45-
if: ${{ github.event_name == 'workflow_dispatch' }}
46-
with:
47-
path: ./packages/sdk/python/human-protocol-sdk/human_protocol_sdk/__init__.py
48-
write-mode: overwrite
49-
contents: |
50-
__version__ = "${{ github.event.inputs.release_version }}"
5143
- name: Build and publish
5244
working-directory: ./packages/sdk/python/human-protocol-sdk
5345
env:
5446
TWINE_USERNAME: __token__
5547
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
48+
run: make publish-package
49+
- name: Create and push tag
50+
working-directory: ./packages/sdk/python/human-protocol-sdk
5651
run: |
57-
make publish-package
52+
VERSION="${{ steps.read_version.outputs.version }}"
53+
TAG="python/sdk@${VERSION}"
54+
echo "Version: $VERSION | Tag: $TAG"
55+
if git rev-parse -q --verify "refs/tags/${TAG}" >/dev/null; then
56+
echo "Tag ${TAG} already exists. Skipping tag creation."
57+
exit 0
58+
fi
59+
git tag -a "$TAG" -m "Python SDK $VERSION"
60+
git push origin "$TAG"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
recursive-include artifacts *.json
2+
include package.json
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1-
__version__ = "0.0.0"
1+
from pathlib import Path
2+
import json
3+
4+
_base_dir = Path(__file__).resolve().parent.parent
5+
_pkg_json_path = _base_dir / "package.json"
6+
try:
7+
with _pkg_json_path.open("r", encoding="utf-8") as f:
8+
_pkg = json.load(f)
9+
except FileNotFoundError as e:
10+
raise RuntimeError(f"package.json not found at {_pkg_json_path}") from e
11+
except Exception as e:
12+
raise RuntimeError("Failed to read package.json") from e
13+
14+
_v = _pkg.get("version")
15+
if not isinstance(_v, str) or not _v.strip():
16+
raise RuntimeError("Missing or empty 'version' in package.json")
17+
18+
__version__ = _v
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "@human-protocol/python-sdk",
3+
"version": "4.4.0",
4+
"private": true,
5+
"description": "Stub package to integrate the Python SDK with Changesets (dev-only).",
6+
"license": "MIT"
7+
}

packages/sdk/python/human-protocol-sdk/setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import setuptools
2+
from human_protocol_sdk import __version__ as _version
23

34
setuptools.setup(
45
name="human-protocol-sdk",
5-
version="4.1.3",
6+
version=_version,
67
author="HUMAN Protocol",
78
description="A python library to launch escrow contracts to the HUMAN network.",
89
url="https://github.com/humanprotocol/human-protocol/packages/sdk/python/human-protocol-sdk",

yarn.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4772,6 +4772,12 @@ __metadata:
47724772
languageName: unknown
47734773
linkType: soft
47744774

4775+
"@human-protocol/python-sdk@workspace:packages/sdk/python/human-protocol-sdk":
4776+
version: 0.0.0-use.local
4777+
resolution: "@human-protocol/python-sdk@workspace:packages/sdk/python/human-protocol-sdk"
4778+
languageName: unknown
4779+
linkType: soft
4780+
47754781
"@human-protocol/reputation-oracle@workspace:packages/apps/reputation-oracle/server":
47764782
version: 0.0.0-use.local
47774783
resolution: "@human-protocol/reputation-oracle@workspace:packages/apps/reputation-oracle/server"

0 commit comments

Comments
 (0)