Publish to PyPi #23
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish to PyPi | |
on: | |
push: | |
branches: | |
- master | |
paths: | |
- '**.py' | |
workflow_dispatch: ~ | |
permissions: | |
contents: write | |
jobs: | |
tests: | |
name: "Run tests" | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.9' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install ruff pytest | |
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
- name: Test with pytest | |
run: | | |
pytest --ignore=tests/example.py --doctest-modules --junitxml=junit/test-results.xml | |
version: | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.changelog.outputs.version }} | |
tag: ${{ steps.changelog.outputs.tag }} | |
changelog: ${{ steps.changelog.outputs.changelog }} | |
clean_changelog: ${{ steps.changelog.outputs.clean_changelog }} | |
skipped: ${{ steps.changelog.outputs.skipped }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Conventional Changelog Action | |
id: changelog | |
uses: TriPSs/conventional-changelog-action@v5 | |
with: | |
release-count: '1' | |
skip-version-file: 'true' | |
skip-commit: 'true' | |
skip-git-pull: 'true' | |
git-push: 'false' | |
fallback-version: '0.3.2' | |
release: | |
name: "Release and publish the version" | |
needs: [ tests, version ] | |
runs-on: ubuntu-latest | |
environment: | |
name: pypi | |
url: https://pypi.org/p/openai-streaming | |
permissions: | |
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing | |
contents: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.8' | |
- name: Set version | |
env: | |
BUILD_VERSION: "${{ needs.version.outputs.version }}" | |
run: sed -i "s/version = \"0.0.0-dev\"/version = \"${BUILD_VERSION}\"/g" pyproject.toml | |
- name: Update reference docs | |
run: pipx run pydoc-markdown | |
- name: Build SDist | |
run: pipx run build --sdist --wheel | |
- name: "Publish to PyPi" | |
uses: pypa/[email protected] | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Update changelog | |
shell: bash | |
run: | | |
git config user.name github-actions | |
git config user.email [email protected] | |
touch CHANGELOG.md | |
echo -e "${{ needs.version.outputs.changelog }}\n\n$(cat CHANGELOG.md)" > CHANGELOG.md | |
git add CHANGELOG.md | |
git add docs/reference.md | |
git commit -m "chore(release): ${{ needs.version.outputs.version }}" CHANGELOG.md | |
git push | |
- name: Tag | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
github.rest.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: 'refs/tags/${{ needs.version.outputs.tag }}', | |
sha: context.sha | |
}) | |
- name: Release on GitHub | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: ${{ needs.version.outputs.tag }} | |
files: dist/* | |
body: | | |
Released to https://pypi.org/project/openai-streaming/${{ needs.version.outputs.version }}/ | |
--- | |
${{ needs.version.outputs.clean_changelog }} | |
prerelease: ${{ inputs.prerelease }} | |
name: Version ${{ needs.version.outputs.version }} | |
generate_release_notes: false |