-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (137 loc) · 5.18 KB
/
listen-swagger-changes.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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