Skip to content

Check for new Swagger release 🕵️‍♂️ #125

Check for new Swagger release 🕵️‍♂️

Check for new Swagger release 🕵️‍♂️ #125

name: "Check for new Swagger release 🕵️‍♂️"
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
check:
name: "Check for new Swagger release 🕵️‍♂️"
runs-on: ubuntu-latest
outputs:
version: ${{ steps.output.outputs.version }}
updated: ${{ steps.output.outputs.updated }}
steps:
- name: "Check out repository 🚚"
uses: actions/checkout@v4
- name: "Print some debug info 🐞"
run: |
echo "Current directory: $(pwd)"
echo "Files in the current directory: $(ls)"
- name: "Set up Python 🐍"
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: "Install python libraries 📚"
run: python -m pip install requests
- name: "Check for new Swagger release 🕵️‍♂️"
id: check
run: python check_swagger.py
# It will set SWAGGER_UI_UPDATED and SWAGGER_UI_VERSION env variables
# If there is a new release, then needed files will be updated
- name: "Make the output available to other jobs 📤"
id: output
run: |
echo "updated=$SWAGGER_UI_UPDATED" >> "$GITHUB_OUTPUT"
echo "version=$SWAGGER_UI_VERSION" >> "$GITHUB_OUTPUT"
- name: "Make a commit if needed 📝"
env:
updated: ${{ steps.output.outputs.updated }}
version: ${{ steps.output.outputs.version }}
run: |
echo "Updated: $updated"
echo "Version: $version"
if [ "$updated" == true ]; then
echo "New Swagger UI version: $version"
git config --global user.email "[email protected]"
git config --global user.name "Automated Swagger UI update"
git add 'fastapi_swagger/resources'
git add 'latest_release.txt'
git commit -m "chore: update Swagger UI to $version"
git push
else
echo "No new Swagger UI release"
fi
build:
name: "Build and release 🚀"
runs-on: ubuntu-latest
needs: check
if: ${{ needs.check.outputs.updated == 'true' }}
steps:
- name: "Check out repository 🚚"
uses: actions/checkout@v4
- name: "Pull the latest changes 🔄"
run: git pull
- name: "Set up Python 🐍"
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: "Install Poetry 📦 (cache-hit)"
id: cached-poetry
uses: actions/cache@v4
with:
path: ~/.local # the path depends on the OS
key: poetry-1.8.3 # increment to reset cache
- name: "Install Poetry 📦"
if: steps.cached-poetry.outputs.cache-hit != 'true'
uses: snok/install-poetry@v1
with:
version: '1.8.3'
virtualenvs-create: true
virtualenvs-in-project: true
- name: "Install Poetry dependencies 📦 (cache-hit)"
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: .venv
key: venv-test-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: "Install Poetry dependencies 📦"
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --with dev
- name: "Test the project 🧪"
run: poetry run pytest
- name: "Bump version 📈"
id: bump
run: |
package_version=$(poetry version patch --short)
echo "package_version=$package_version" >> "$GITHUB_OUTPUT"
- name: "Build the project 🏗"
run: poetry build
- name: "Commit the changes with tag 🏷"
env:
package_version: ${{ steps.bump.outputs.package_version }}
run: |
git config --global user.email "[email protected]"
git config --global user.name "Automated Swagger UI update"
git add pyproject.toml
git commit -m "chore: bump version to $package_version"
git tag -a "v$package_version" -m "Release $package_version"
git push --follow-tags
- name: "Upload artifacts 📦"
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: "Make a release 🚀"
uses: softprops/action-gh-release@v2
with:
files: dist/*
tag_name: "v${{ steps.bump.outputs.package_version }}"
body: "Package version: v${{ steps.bump.outputs.package_version }} 🚀\nSwagger UI version: ${{ needs.check.outputs.version }}"
pypi-publish:
name: "Upload release to PyPI 📦"
needs: build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/fastapi-swagger
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
# retrieve your distributions here
- name: "Get distribution artifacts ⬇️"
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: "Publish package distributions to PyPI ⬆️"
uses: pypa/gh-action-pypi-publish@release/v1