Skip to content

Commit 02d790c

Browse files
authored
Merge pull request #13 from spring-media/luabrudna/feature/check_openapiversions
Luabrudna/feature/check openapiversions
2 parents c349a6a + e3997bc commit 02d790c

6 files changed

+70
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Run Python Script
2+
3+
on:
4+
# Run the workflow every day at midnight (00:00) UTC.
5+
workflow_dispatch: # Allows manual triggering
6+
schedule:
7+
- cron: '0 0 * * *'
8+
9+
jobs:
10+
run-python-script:
11+
runs-on: ubuntu-latest # Use Ubuntu as the runner environment
12+
13+
steps:
14+
# Step 1: Checkout the repository
15+
- name: Checkout code
16+
uses: actions/checkout@v2
17+
18+
# Step 2: Set up Python environment
19+
- name: Set up Python
20+
uses: actions/setup-python@v2
21+
with:
22+
python-version: '3.12' # Specify the Python version (e.g., '3.x')
23+
24+
# Step 3: Install dependencies (optional, if your script has requirements)
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install -r scripts/requirements.txt
29+
# Step 4: Run your Python script
30+
- name: Run Python script
31+
run: python ./scripts/check_openapi_version.py
32+

scripts/check_openapi_version.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# check https://api.plenigo.com/ website, parse the html and check the version of the openapi spec
2+
# the version looks something like this as text: plenigo API v3 (API.241015-MAJOR)
3+
# and this as html:<h1 class="sc-fujyAs sc-dFRpbK bpZWeL fdKBSs">plenigo API v3<!-- --> <span>(<!-- -->API.241015-MAJOR<!-- -->)</span></h1>
4+
# the file containing the openapi spec can be found in the html: <p>Download OpenAPI specification<!-- -->:<a download="openapi.json" target="_blank" class="sc-bsatvv gidAUi" href="blob:https://api.plenigo.com/34a50f04-3802-4d2d-8bb9-7b1e12f1246e">Download</a></p>
5+
6+
import requests
7+
from bs4 import BeautifulSoup
8+
import json
9+
import os
10+
import sys
11+
12+
url = 'https://api.plenigo.com/'
13+
response = requests.get(url)
14+
soup = BeautifulSoup(response.text, 'html.parser')
15+
version = soup.find('h1').text
16+
# get words inside the parenthesis
17+
version = version.split('(')[1].split(')')[0]
18+
19+
# list the files in the openapi_specs folder
20+
# open the fist folder and check the version
21+
# if the version is different, print a message
22+
latest_folder_path = "./openapi_specs/latest"
23+
files = os.listdir(latest_folder_path)
24+
file_path = os.path.join(latest_folder_path, files[0])
25+
with open(file_path, 'r') as file:
26+
openapi_spec = json.load(file)
27+
current_prod_version = openapi_spec['info']['version']
28+
if version != current_prod_version:
29+
print(f"Version mismatch: Current version is {current_prod_version} while the website version is {version}")
30+
sys.exit(1)
31+
else:
32+
print("We are currently using the latest version")
33+
sys.exit(0)
34+
35+
36+

scripts/requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
beautifulsoup4
2+
requests

0 commit comments

Comments
 (0)