|
1 | 1 | name: Python SDK publish |
2 | 2 |
|
| 3 | +permissions: |
| 4 | + contents: write |
| 5 | + |
3 | 6 | 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/**" |
11 | 12 |
|
12 | 13 | jobs: |
13 | 14 | publish-python-sdk: |
14 | 15 | name: Publish Python SDK |
15 | 16 | runs-on: ubuntu-latest |
16 | 17 | steps: |
17 | 18 | - uses: actions/checkout@v5 |
| 19 | + with: |
| 20 | + token: ${{ secrets.GH_GITBOOK_TOKEN }} |
18 | 21 | - uses: actions/setup-node@v4 |
19 | 22 | with: |
20 | 23 | node-version-file: .nvmrc |
21 | 24 | cache: yarn |
22 | | - - name: Install dependencies |
| 25 | + - name: Install JS dependencies |
23 | 26 | run: yarn install |
24 | 27 | - name: Build core package |
25 | 28 | run: yarn workspace @human-protocol/core build |
26 | 29 | - name: Set up Python |
27 | 30 | uses: actions/setup-python@v6 |
28 | 31 | with: |
29 | 32 | 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 |
31 | 39 | working-directory: ./packages/sdk/python/human-protocol-sdk |
32 | 40 | run: | |
33 | 41 | python -m pip install --upgrade pip |
34 | 42 | 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 }}" |
51 | 43 | - name: Build and publish |
52 | 44 | working-directory: ./packages/sdk/python/human-protocol-sdk |
53 | 45 | env: |
54 | 46 | TWINE_USERNAME: __token__ |
55 | 47 | 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 |
56 | 51 | 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" |
0 commit comments