Check for new Swagger release 🕵️♂️ #447
This file contains hidden or 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: "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: "Install uv 📦" | |
uses: astral-sh/setup-uv@v6 | |
- name: "Install uv dependencies 📦" | |
run: uv sync | |
- name: "Test the project 🧪" | |
run: uv run pytest | |
- name: "Bump version 📈" | |
id: bump | |
run: | | |
package_version=$(uv version --bump patch --short) | |
echo "package_version=$package_version" >> "$GITHUB_OUTPUT" | |
- name: "Build the project 🏗" | |
run: uv 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 |