Publish and Release #30
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 and Release | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'fastapi_agents/**' | |
- 'pyproject.toml' | |
- 'uv.lock' | |
- 'docs/**' | |
- 'README.md' | |
workflow_dispatch: | |
jobs: | |
version_bump_and_publish: | |
if: ${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && (contains(join(github.event.head_commit.modified, ' '), 'fastapi_agents/') || contains(join(github.event.head_commit.modified, ' '), 'pyproject.toml'))) }} | |
permissions: | |
contents: write | |
runs-on: ubuntu-latest | |
environment: | |
name: pypi | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 1 | |
- name: Set up Python version from file | |
uses: actions/setup-python@v4 | |
with: | |
python-version-file: .python-version | |
- name: Install uv | |
run: | | |
python3 -m pip install --upgrade pip | |
python3 -m pip install uv | |
- name: Install dev dependencies | |
run: | | |
uv sync --dev | |
- name: Run tests with pytest | |
run: | | |
uv run pytest | |
- name: Bump version and tag | |
run: | | |
uv run bump-version | |
NEW_VERSION=$(uv run get-version) | |
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
git add pyproject.toml uv.lock | |
git commit -m "Bump version to $NEW_VERSION" | |
git tag v$NEW_VERSION | |
- name: Push changes and tags | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git | |
git push origin main --tags | |
- name: Build and publish | |
env: | |
UV_PUBLISH_TOKEN: ${{ secrets.UV_PUBLISH_TOKEN }} | |
run: | | |
uv build | |
uv publish | |
- name: Get previous version tag | |
id: get_previous_version_tag | |
run: | | |
PREVIOUS_TAG=$(git describe --tags $(git rev-list --tags --skip=1 --max-count=1)) | |
echo "PREVIOUS_TAG=$PREVIOUS_TAG" >> $GITHUB_ENV | |
- name: Generate release notes | |
id: generate_release_notes | |
run: | | |
echo "Changes in this release:" > release_notes.md | |
git log $(git describe --tags --abbrev=0 $(git describe --tags --abbrev=0)^)..HEAD --pretty=format:"- %s ([%h](https://github.com/${{ github.repository }}/commit/%H))" >> release_notes.md | |
echo "" >> release_notes.md | |
echo "" >> release_notes.md | |
echo "[View details on PyPI](https://pypi.org/project/fastapi-agents/${{ env.NEW_VERSION }}/)" >> release_notes.md | |
echo "" >> release_notes.md | |
echo "To upgrade via pip:" >> release_notes.md | |
echo "\`\`\`" >> release_notes.md | |
echo "pip install --upgrade fastapi-agents" >> release_notes.md | |
echo "\`\`\`" >> release_notes.md | |
echo "" >> release_notes.md | |
- name: Output release notes for debugging | |
run: cat release_notes.md | |
- name: Create release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ env.NEW_VERSION }} | |
release_name: Release v${{ env.NEW_VERSION }} | |
body_path: release_notes.md | |
- name: Prevent publish trigger | |
run: echo "Skipped publish" > skip_publish.txt | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
generate_and_publish_docs: | |
if: ${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && (contains(join(github.event.head_commit.modified, ' '), 'README.md') || contains(join(github.event.head_commit.modified, ' '), 'docs/'))) || github.job == 'version_bump_and_publish' }} | |
permissions: | |
contents: write | |
pages: write | |
id-token: write | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 1 | |
- name: Set up Python version from file | |
uses: actions/setup-python@v4 | |
with: | |
python-version-file: .python-version | |
- name: Install uv | |
run: | | |
python3 -m pip install --upgrade pip | |
python3 -m pip install uv | |
- name: Install dev dependencies | |
run: | | |
uv sync --dev | |
- name: Build docs | |
run: | | |
uv run mkdocs build | |
- name: Deploy to GitHub Pages | |
run: | | |
uv run mkdocs gh-deploy --force |