Skip to content

Commit

Permalink
Implemented download + upload of openapi.json (#62)
Browse files Browse the repository at this point in the history
* Implemented download + upload of openapi.json
  • Loading branch information
ckunki authored Jun 5, 2024
1 parent 1d64153 commit ed34701
Show file tree
Hide file tree
Showing 4 changed files with 3,414 additions and 16 deletions.
21 changes: 7 additions & 14 deletions .github/workflows/check-api-outdated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,6 @@ jobs:
- name: SCM Checkout
uses: actions/checkout@v4

- name: Display Branch and Download openapi.json
id: download
run: |
git branch
F="ci-$(date "+%y%m%d-%H%M").json"
curl -s https://cloud.exasol.com/openapi.json -o "$F"
echo json=$F >> "$GITHUB_OUTPUT"
- name: Upload openapi.json
uses: actions/upload-artifact@v4
with:
name: ${{ steps.download.outputs.json}}
path: ${{ steps.download.outputs.json}}

- name: Setup Python & Poetry Environment
uses: exasol/python-toolbox/.github/actions/[email protected]
with:
Expand All @@ -58,3 +44,10 @@ jobs:
notify_when: "failure,cancelled,warnings,skipped"
env:
SLACK_WEBHOOK_URL: ${{ secrets.INTEGRATION_TEAM_SLACK_NOTIFICATION_WEBHOOK }}

- name: Upload openapi.json
if: ${{ failure() }}
uses: actions/upload-artifact@v4
with:
name: openapi.json
path: openapi.json
2 changes: 2 additions & 0 deletions doc/changes/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

* #53: Separated long-running tests
* Updated GitHub workflow to upload `openapi.json` as artifact
* #61: Restricted upload of `openapi.json` to failures

## Features

* #55 Added publicly callable function finding the database id from its name.
* #60: Added download of `openapi.json` when generating python client

## Documentation

Expand Down
23 changes: 21 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import json
import os
import nox
import requests

from datetime import datetime, timezone
from pathlib import Path
from nox import Session
from noxconfig import PROJECT_CONFIG
Expand All @@ -13,6 +16,21 @@
nox.options.sessions = ["fix"]


def _download_openapi_json() -> Path:
url = f"{SAAS_HOST}/openapi.json"
response = requests.get(url)
response.raise_for_status()
content = response.json()
content["info"]["download"] = {
"source": url,
"timestamp": datetime.now(timezone.utc).isoformat(),
}
file = Path("openapi.json")
with open(file, "w") as f:
json.dump(content, f, indent=4)
return file


@nox.session(name="generate-api", python=False)
def generate_api(session: Session):
"""
Expand All @@ -26,10 +44,11 @@ def generate_api(session: Session):
#default-environment-variables.
"""
silent = "CI" not in os.environ
filename = _download_openapi_json()
session.run(
"openapi-python-client",
"update",
"--url", f"{SAAS_HOST}/openapi.json",
"--path", str(filename),
"--config", "openapi_config.yml",
silent=silent,
)
Expand All @@ -42,7 +61,7 @@ def check_api_outdated(session: Session):
Generate API and run git diff to verify if API is out-dated.
"""
generate_api(session)
session.run("git", "diff", "--exit-code")
session.run("git", "diff", "--exit-code", "exasol/saas/client/openapi")


@nox.session(name="get-project-short-tag", python=False)
Expand Down
Loading

0 comments on commit ed34701

Please sign in to comment.