Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .ci/generate_rsm_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Script to generate the RMS models from the OpenAPI spec."""

import argparse
import os
import subprocess
import tempfile

import requests

parser = argparse.ArgumentParser()
parser.add_argument("-U", "--url", default="https://localhost:8443/hps")

args = parser.parse_args()

hps_url = args.url

file_name = "rms_openapi.json"
api_spec_url = f"{hps_url}/rms/openapi.json"

r = requests.get(api_spec_url, verify=False)

with tempfile.TemporaryDirectory() as tmpdirname:
file_name = os.path.join(tmpdirname, file_name)
with open(file_name, "w") as f:
f.write(r.text)

cmd = (
f"datamodel-codegen --input {file_name} --input-file-type openapi "
"--output src/ansys/hps/client/rms/models.py "
"--output-model-type pydantic_v2.BaseModel "
"--base-class ansys.hps.client.common.DictModel "
"--custom-file-header-path rms_models.header"
)
print(f"* Generate models with the following command:\n {cmd}")
subprocess.run(cmd, check=True, shell=True)

cmd = "pre-commit run --files src/ansys/hps/client/rms/models.py"
print(f"* Running pre-commit on models with the following command:\n {cmd}")
subprocess.run(cmd, check=False, shell=True)
54 changes: 54 additions & 0 deletions .github/workflows/update_rsm_models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Update RSM Models
on:
workflow_dispatch:
schedule:
- cron: "0 5 * * *"

env:
MAIN_PYTHON_VERSION: '3.12'

jobs:

update-models:
name: Update models
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.MAIN_PYTHON_VERSION }}

- name: Start HPS services
id: hps-services
uses: ansys/pyhps/.github/actions/hps_services@main
with:
token: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}
ghcr-username: ${{ secrets.PYANSYS_CI_BOT_USERNAME }}
ghcr-token: ${{ secrets.PYANSYS_CI_BOT_PACKAGE_TOKEN }}
version: 'latest-dev'
feature: 'main'

- name: Install dependencies
run: |
python -m pip install -e .[build]
pip install pre-commit

- name: Run script
run: |
python .ci/generate_rsm_models.py

- name: "Create PR if changes detected"
if: startsWith(github.ref, 'refs/heads/main')
uses: peter-evans/create-pull-request@v7
with:
title: "[Auto] Update RMS models"
body: An update of auto-generated RMS models has been triggered either manually or by a scheduled workflow.
base: main
branch: maint/rms-model-update
delete-branch: true
token: ${{ secrets.PYANSYS_CI_BOT_TOKEN }}
add-paths: |
src/ansys/hps/client/rms/models.py

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,5 @@ mapdl_motorbike_frame.zip
examples/mapdl_motorbike_frame/task_input_file*
build_info.*
doc/source/api/ansys
doc/source/api/_autosummary
doc/source/api/_autosummary
docker-compose-artifact
Loading