Repository navigation
137 lines (121 loc) · 3.83 KB
/
Copy pathpython-sdk-release.yml
File metadata and controls
137 lines (121 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: Python SDK Release
on:
release:
types: [published]
workflow_dispatch:
inputs:
target:
description: "Publish target"
required: true
type: choice
default: "testpypi"
options:
- testpypi
- pypi
- both
permissions:
contents: read
id-token: write
jobs:
build-sdk:
name: Build openviking-sdk
if: github.event_name == 'workflow_dispatch' || startsWith(github.event.release.tag_name, 'python-sdk@')
runs-on: ubuntu-24.04
outputs:
sdk_version: ${{ steps.version.outputs.sdk_version }}
publish_target: ${{ steps.target.outputs.publish_target }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Fetch all tags
run: git fetch --force --tags
- name: Set publish target
id: target
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "publish_target=${{ inputs.target }}" >> "$GITHUB_OUTPUT"
else
echo "publish_target=pypi" >> "$GITHUB_OUTPUT"
fi
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Install build dependencies
working-directory: sdk/python
run: uv pip install --system build setuptools setuptools-scm wheel
- name: Resolve SDK version
id: version
working-directory: sdk/python
run: |
SDK_VERSION=$(python -m setuptools_scm)
echo "sdk_version=$SDK_VERSION" >> "$GITHUB_OUTPUT"
echo "Resolved SDK version: $SDK_VERSION"
- name: Validate tag matches SDK version
if: github.event_name == 'release'
env:
TAG_NAME: ${{ github.event.release.tag_name }}
SDK_VERSION: ${{ steps.version.outputs.sdk_version }}
run: |
EXPECTED_TAG="python-sdk@${SDK_VERSION}"
if [ "$TAG_NAME" != "$EXPECTED_TAG" ]; then
echo "Tag $TAG_NAME does not match resolved SDK version $SDK_VERSION"
exit 1
fi
- name: Build SDK distributions
working-directory: sdk/python
run: python -m build
- name: Upload SDK distributions
uses: actions/upload-artifact@v7
with:
name: python-sdk-distributions
path: sdk/python/dist/*
publish-testpypi:
name: Publish SDK to TestPyPI
needs: [build-sdk]
if: needs.build-sdk.outputs.publish_target == 'testpypi' || needs.build-sdk.outputs.publish_target == 'both'
runs-on: ubuntu-24.04
environment:
name: testpypi
url: https://test.pypi.org/p/openviking-sdk
permissions:
id-token: write
steps:
- name: Download SDK distributions
uses: actions/download-artifact@v8
with:
name: python-sdk-distributions
path: dist/
- name: Publish SDK to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
verbose: true
publish-pypi:
name: Publish SDK to PyPI
needs: [build-sdk]
if: needs.build-sdk.outputs.publish_target == 'pypi' || needs.build-sdk.outputs.publish_target == 'both'
runs-on: ubuntu-24.04
environment:
name: pypi
url: https://pypi.org/p/openviking-sdk
permissions:
id-token: write
steps:
- name: Download SDK distributions
uses: actions/download-artifact@v8
with:
name: python-sdk-distributions
path: dist/
- name: Publish SDK to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
verbose: true