Skip to content

OpenAPI flows

OpenAPI flows #9

Workflow file for this run

name: Flows OpenAPI Specs
on:
pull_request:
paths:
- 'flows/**'
concurrency:
group: flow_openapi-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
jobs:
flow-openapi:
runs-on: ubuntu-22.04
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- 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: Get list of changed flow files
id: changed_files
run: |
# Add the base repository as a new remote
git remote add base https://github.com/${{ github.event.pull_request.base.repo.full_name }}.git
# Fetch the base branch from the base repository
git fetch base ${{ github.event.pull_request.base.ref }} --depth=1
# Get the list of changed files between the PR and the base branch
git diff --name-only --diff-filter=AM base/${{ github.event.pull_request.base.ref }}...HEAD > changed_files_am.txt
# Filter for changes in 'flows/' directory
grep '^flows/' changed_files_am.txt > flows_changed_files_am.txt || true
- name: Show changed flow files
run: cat flows_changed_files_am.txt
- name: Check if any flows were changed
id: check_flows
run: |
if [ -s flows_changed_files_am.txt ]; then
echo "flows_changed=true" >> $GITHUB_OUTPUT
else
echo "flows_changed=false" >> $GITHUB_OUTPUT
fi
- name: Install, check, and generate OpenAPI specs for flows
if: steps.check_flows.outputs.flows_changed == 'true'
run: |
mkdir -p flows_openapi
while read file; 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"
rm -f "vix_flows/$flow_name"
done < flows_changed_files_am.txt
- name: Upload OpenAPI specs as artifact
if: steps.check_flows.outputs.flows_changed == 'true'
uses: actions/upload-artifact@v3
with:
name: OpenAPI Specs
path: flows_openapi/
- name: Comment on PR with artifact link
if: steps.check_flows.outputs.flows_changed == 'true'
uses: thollander/actions-comment-pull-request@v3
with:
message: |
✅ The generated OpenAPI specifications are available as artifacts in the [Actions tab](${{ github.run_url }}). Please download the "OpenAPI Specs" artifact to review them.