Skip to content

Commit dceea2d

Browse files
committed
ci: setup automatic releases (#693)
1 parent e0aafc6 commit dceea2d

9 files changed

+220
-1
lines changed

.github/workflows/create-releases.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Create releases
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
release:
9+
name: release
10+
if: github.ref == 'refs/heads/main' && github.repository == 'openai/openai-python'
11+
runs-on: ubuntu-latest
12+
environment: publish
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- uses: stainless-api/trigger-release-please@v1
18+
id: release
19+
with:
20+
repo: ${{ github.event.repository.full_name }}
21+
stainless-api-key: ${{ secrets.STAINLESS_API_KEY }}
22+
23+
- name: Install Rye
24+
if: ${{ steps.release.outputs.releases_created }}
25+
run: |
26+
curl -sSf https://rye-up.com/get | bash
27+
echo "$HOME/.rye/shims" >> $GITHUB_PATH
28+
env:
29+
RYE_VERSION: 0.15.2
30+
RYE_INSTALL_OPTION: "--yes"
31+
32+
- name: Publish to PyPI
33+
if: ${{ steps.release.outputs.releases_created }}
34+
run: |
35+
bash ./bin/publish-pypi
36+
env:
37+
PYPI_TOKEN: ${{ secrets.OPENAI_PYPI_TOKEN || secrets.PYPI_TOKEN }}

.github/workflows/publish-pypi.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# workflow for re-running publishing to PyPI in case it fails for some reason
2+
# you can run this workflow by navigating to https://www.github.com/openai/openai-python/actions/workflows/publish-pypi.yml
3+
name: Publish PyPI
4+
on:
5+
workflow_dispatch:
6+
7+
jobs:
8+
publish:
9+
name: publish
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v3
14+
15+
- name: Install Rye
16+
run: |
17+
curl -sSf https://rye-up.com/get | bash
18+
echo "$HOME/.rye/shims" >> $GITHUB_PATH
19+
env:
20+
RYE_VERSION: 0.15.2
21+
RYE_INSTALL_OPTION: "--yes"
22+
23+
- name: Publish to PyPI
24+
run: |
25+
bash ./bin/publish-pypi
26+
env:
27+
PYPI_TOKEN: ${{ secrets.OPENAI_PYPI_TOKEN || secrets.PYPI_TOKEN }}

.github/workflows/release-doctor.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Release Doctor
2+
on:
3+
push:
4+
branches:
5+
- main
6+
workflow_dispatch:
7+
8+
jobs:
9+
release_doctor:
10+
name: release doctor
11+
runs-on: ubuntu-latest
12+
environment: publish
13+
if: github.repository == 'openai/openai-python' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please') || github.head_ref == 'next')
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- name: Check release environment
19+
run: |
20+
bash ./bin/check-release-environment
21+
env:
22+
STAINLESS_API_KEY: ${{ secrets.STAINLESS_API_KEY }}
23+
PYPI_TOKEN: ${{ secrets.OPENAI_PYPI_TOKEN || secrets.PYPI_TOKEN }}

.release-please-manifest.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
".": "1.1.1"
3+
}

bin/check-release-environment

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
errors=()
4+
5+
if [ -z "${STAINLESS_API_KEY}" ]; then
6+
errors+=("The STAINLESS_API_KEY secret has not been set. Please contact Stainless for an API key & set it in your organization secrets on GitHub.")
7+
fi
8+
9+
if [ -z "${PYPI_TOKEN}" ]; then
10+
errors+=("The OPENAI_PYPI_TOKEN secret has not been set. Please set it in either this repository's secrets or your organization secrets.")
11+
fi
12+
13+
len=${#errors[@]}
14+
15+
if [[ len -gt 0 ]]; then
16+
echo -e "Found the following errors in the release environment:\n"
17+
18+
for error in "${errors[@]}"; do
19+
echo -e "- $error\n"
20+
done
21+
22+
exit 1
23+
fi
24+
25+
echo "The environment is ready to push releases!"

bin/publish-pypi

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -eux
4+
mkdir -p dist
5+
rye build --clean
6+
rye publish --yes --token=$PYPI_TOKEN

examples/audio.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python
2+
3+
from pathlib import Path
4+
5+
from openai import OpenAI
6+
7+
# gets OPENAI_API_KEY from your environment variables
8+
openai = OpenAI()
9+
10+
speech_file_path = Path(__file__).parent / "speech.mp3"
11+
12+
13+
def main() -> None:
14+
# Create text-to-speech audio file
15+
response = openai.audio.speech.create(
16+
model="tts-1", voice="alloy", input="the quick brown fox jumped over the lazy dogs"
17+
)
18+
19+
response.stream_to_file(speech_file_path)
20+
21+
# Create transcription from audio file
22+
transcription = openai.audio.transcriptions.create(model="whisper-1", file=speech_file_path)
23+
print(transcription.text)
24+
25+
# Create translation from audio file
26+
translation = openai.audio.translations.create(
27+
model="whisper-1",
28+
file=speech_file_path,
29+
)
30+
print(translation.text)
31+
32+
33+
if __name__ == "__main__":
34+
main()

release-please-config.json

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"packages": {
3+
".": {}
4+
},
5+
"$schema": "https://raw.githubusercontent.com/stainless-api/release-please/main/schemas/config.json",
6+
"include-v-in-tag": true,
7+
"include-component-in-tag": false,
8+
"bump-minor-pre-major": true,
9+
"bump-patch-for-minor-pre-major": false,
10+
"pull-request-header": "Automated Release PR",
11+
"pull-request-title-pattern": "release: ${version}",
12+
"changelog-sections": [
13+
{
14+
"type": "feat",
15+
"section": "Features"
16+
},
17+
{
18+
"type": "fix",
19+
"section": "Bug Fixes"
20+
},
21+
{
22+
"type": "perf",
23+
"section": "Performance Improvements"
24+
},
25+
{
26+
"type": "revert",
27+
"section": "Reverts"
28+
},
29+
{
30+
"type": "chore",
31+
"section": "Chores"
32+
},
33+
{
34+
"type": "docs",
35+
"section": "Documentation"
36+
},
37+
{
38+
"type": "style",
39+
"section": "Styles"
40+
},
41+
{
42+
"type": "refactor",
43+
"section": "Refactors"
44+
},
45+
{
46+
"type": "test",
47+
"section": "Tests",
48+
"hidden": true
49+
},
50+
{
51+
"type": "build",
52+
"section": "Build System"
53+
},
54+
{
55+
"type": "ci",
56+
"section": "Continuous Integration",
57+
"hidden": true
58+
}
59+
],
60+
"release-type": "python",
61+
"extra-files": [
62+
"src/openai/_version.py"
63+
]
64+
}

src/openai/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# File generated from our OpenAPI spec by Stainless.
22

33
__title__ = "openai"
4-
__version__ = "1.1.1"
4+
__version__ = "1.1.1" # x-release-please-version

0 commit comments

Comments
 (0)