-
Notifications
You must be signed in to change notification settings - Fork 0
106 lines (104 loc) · 4.06 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
name: "Check for new Swagger release 🕵️♂️"
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
check:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.check.outputs.version }}
updated: ${{ steps.check.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 &&
echo "updated=$SWAGGER_UI_UPDATED" >> "$GITHUB_OUTPUT" &&
echo "version=$SWAGGER_UI_VERSION" >> "$GITHUB_OUTPUT"
# 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 a commit if needed 📝"
env:
updated: ${{ steps.check.outputs.updated }}
version: ${{ steps.check.outputs.version }}
run: |
if [ "$updated" = "true" ]; then
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
fi
build:
runs-on: ubuntu-latest
needs: check
if: ${{ needs.check.outputs.updated == 'true' }}
steps:
- name: "Check out repository 🚚"
uses: actions/checkout@v4
- 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: "Make a release 🚀"
uses: softprops/action-gh-release@v2
with:
files: dist/*
tag_name: "v${{ steps.bump.outputs.package_version }}"
name: "Release ${{ steps.bump.outputs.package_version }}"
body: "Release ${{ steps.bump.outputs.package_version }} 🚀\nSwagger UI version: ${{ needs.check.outputs.version }}"