OpenAPI flows #13
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Flows OpenAPI Specs | |
on: | |
pull_request: | |
paths: | |
- 'flows/**' | |
repository_dispatch: | |
types: [flows_openapi_update] | |
permissions: | |
contents: read | |
issues: write | |
pull-requests: write | |
actions: read | |
jobs: | |
flow-openapi: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
persist-credentials: false | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
- name: Checkout Visionatrix | |
uses: actions/checkout@v4 | |
with: | |
path: src_visionatrix | |
repository: Visionatrix/Visionatrix | |
- name: Install PostgreSQL | |
run: | | |
sudo DEBIAN_FRONTEND=noninteractive apt-get update | |
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y postgresql postgresql-contrib | |
sudo pg_ctlcluster 14 main start | |
sudo -u postgres psql -c "CREATE USER vix_user WITH PASSWORD 'vix_password';" | |
sudo -u postgres psql -c "CREATE DATABASE vix_db OWNER vix_user;" | |
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE vix_db TO vix_user;" | |
- name: Set DATABASE_URI environment variable | |
run: echo "DATABASE_URI=postgresql+psycopg://vix_user:vix_password@localhost:5432/vix_db" >> $GITHUB_ENV | |
- name: Install Visionatrix | |
run: | | |
python3 -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu | |
python3 -m pip install "src_visionatrix/.[pgsql]" | |
python3 -m visionatrix install | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Install redoc-cli | |
run: npm install -g redoc-cli | |
- name: Install, check, and generate OpenAPI specs and HTML docs for flows | |
run: | | |
mkdir -p flows_openapi | |
mkdir -p flows_docs | |
for file in flows/*; do | |
echo "Processing $file" | |
VIX_MODE=SERVER VIX_SERVER_FULL_MODELS=0 python3 -m visionatrix install-flow --file="$file" | |
flow_name=$(basename "$file") | |
openapi_file="flows_openapi/$flow_name" | |
VIX_MODE=SERVER VIX_SERVER_FULL_MODELS=0 python3 -m visionatrix openapi --only-flows --installed --file="$openapi_file" | |
html_file="flows_docs/${flow_name%.json}.html" | |
npx redoc-cli bundle "$openapi_file" -o "$html_file" | |
done | |
- name: Upload OpenAPI specs artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: OpenAPI Specs | |
path: flows_openapi/ | |
- name: Upload HTML documentation artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: OpenAPI Docs | |
path: flows_docs/ | |
- name: Dispatch event to main repository | |
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT_FOR_DISPATCH }} | |
run: | | |
curl -X POST -H "Accept: application/vnd.github.v3+json" \ | |
-H "Authorization: token $GITHUB_TOKEN" \ | |
https://api.github.com/repos/${{ github.repository }}/dispatches \ | |
-d '{"event_type": "flows_openapi_update", "client_payload": {"pr_number": ${{ github.event.pull_request.number }}, "repository": "${{ github.repository }}", "run_id": "${{ github.run_id }}"}}' | |
handle-dispatch: | |
if: github.event_name == 'repository_dispatch' | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install Python and Node.js | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Install redoc-cli | |
run: npm install -g redoc-cli | |
- name: Install and generate OpenAPI specs | |
run: | | |
mkdir -p flows_openapi | |
mkdir -p flows_docs | |
for file in flows/*; do | |
flow_name=$(basename "$file") | |
openapi_file="flows_openapi/$flow_name" | |
VIX_MODE=SERVER VIX_SERVER_FULL_MODELS=0 python3 -m visionatrix openapi --only-flows --installed --file="$openapi_file" | |
html_file="flows_docs/${flow_name%.json}.html" | |
npx redoc-cli bundle "$openapi_file" -o "$html_file" | |
done | |
- name: Upload OpenAPI specs artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: OpenAPI Specs | |
path: flows_openapi/ | |
- name: Upload HTML documentation artifact | |
uses: actions/upload-artifact@v3 | |
with: | |
name: OpenAPI Docs | |
path: flows_docs/ | |
- name: List artifacts and extract URLs | |
id: list_artifacts | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const run_id = context.runId; | |
const { data: artifacts } = await github.rest.actions.listWorkflowRunArtifacts({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
run_id: run_id | |
}); | |
const openapiArtifact = artifacts.artifacts.find(artifact => artifact.name === 'OpenAPI Specs'); | |
const docsArtifact = artifacts.artifacts.find(artifact => artifact.name === 'OpenAPI Docs'); | |
core.setOutput('openapi_url', openapiArtifact ? openapiArtifact.archive_download_url : ''); | |
core.setOutput('docs_url', docsArtifact ? docsArtifact.archive_download_url : ''); | |
- name: Comment on PR with artifact links and instructions | |
uses: thollander/actions-comment-pull-request@v3 | |
with: | |
message: | | |
✅ **OpenAPI Specifications and Documentation Generated** | |
**Instructions:** | |
- **Reviewers:** | |
- [OpenAPI Spec](${{ steps.list_artifacts.outputs.openapi_url }}) | |
- [HTML Documentation](${{ steps.list_artifacts.outputs.docs_url }}) | |
- **Contributors:** | |
- Download the **OpenAPI Specs** artifact from the [OpenAPI Spec](${{ steps.list_artifacts.outputs.openapi_url }}) | |
- Add the JSON files to the `flows_openapi/` directory in your PR | |
- Commit and push the changes to update your PR | |
pr_number: ${{ github.event.client_payload.pr_number }} |