Skip to content

Add server script and update documentation for API constraints #13

Add server script and update documentation for API constraints

Add server script and update documentation for API constraints #13

# This workflow will upload a Python Package using Twine when code is pushed to main
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Upload Python Package
on:
push:
branches: [ "master" ]
release:
types: [published]
permissions:
contents: write
id-token: write
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[test,dev]
- name: Run tests
run: |
pytest tests/ -v
deploy:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine tomli-w tomli
- name: Create version update script
run: |
cat > update_version.py << 'EOF'
import sys
import os
try:
import tomllib
except ImportError:
import tomli as tomllib
import tomli_w
def get_current_version():
with open('pyproject.toml', 'rb') as f:
data = tomllib.load(f)
return data['project']['version']
def increment_version(version):
parts = version.split('.')
parts[-1] = str(int(parts[-1]) + 1)
return '.'.join(parts)
def update_version(new_version):
with open('pyproject.toml', 'rb') as f:
data = tomllib.load(f)
data['project']['version'] = new_version
with open('pyproject.toml', 'wb') as f:
tomli_w.dump(data, f)
if __name__ == "__main__":
current = get_current_version()
new = increment_version(current)
update_version(new)
print(f"Updated version from {current} to {new}")
# Write to GitHub output
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f"new_version={new}\n")
EOF
- name: Update version
id: update_version
run: python update_version.py
- name: Build package
run: python -m build
- name: Check package
run: twine check dist/*
- name: Publish package to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
twine upload dist/*
- name: Commit version update
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add pyproject.toml
git commit -m "Bump version to ${{ steps.update_version.outputs.new_version }}" || exit 0
git push
- name: Create Git Tag
run: |
git tag v${{ steps.update_version.outputs.new_version }}
git push origin v${{ steps.update_version.outputs.new_version }}
- name: Generate Release Notes
id: release_notes
run: |
# Get commits since last tag
LAST_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
# First release - get all commits
COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges HEAD~10..HEAD)
else
# Get commits since last tag
COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges $LAST_TAG..HEAD~1)
fi
# Create release notes file
cat > release_notes.md << EOF
## 🚀 Release v${{ steps.update_version.outputs.new_version }}
### What's Changed
$COMMITS
### 📦 Installation
\`\`\`bash
pip install lightapi==${{ steps.update_version.outputs.new_version }}
\`\`\`
### 📖 Documentation
- [Getting Started](https://iklobato.github.io/lightapi/getting-started/installation/)
- [API Reference](https://iklobato.github.io/lightapi/api-reference/core/)
- [Examples](https://iklobato.github.io/lightapi/examples/basic-rest/)
**Full Changelog**: https://github.com/iklobato/lightapi/compare/${LAST_TAG}...v${{ steps.update_version.outputs.new_version }}
EOF
echo "Generated release notes for v${{ steps.update_version.outputs.new_version }}"
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.update_version.outputs.new_version }}
name: "LightAPI v${{ steps.update_version.outputs.new_version }}"
body_path: release_notes.md
draft: false
prerelease: false
files: |
dist/lightapi-${{ steps.update_version.outputs.new_version }}-py3-none-any.whl
dist/lightapi-${{ steps.update_version.outputs.new_version }}.tar.gz
token: ${{ secrets.GITHUB_TOKEN }}