|
| 1 | +name: Test - OpenAI API Coverage - Nightly / Manual |
| 2 | +on: |
| 3 | + schedule: |
| 4 | + - cron: '0 20 * * 1,2,3' # At 8 PM UTC on Monday, Tuesday, and Wednesday which is 3 AM UTC+7 Tuesday, Wednesday, and Thursday |
| 5 | + workflow_dispatch: |
| 6 | + inputs: |
| 7 | + endpoints: |
| 8 | + description: 'comma-separated list (see available at coverage/endpoint_mapping.json e.g. GET /users,POST /transform)' |
| 9 | + required: false |
| 10 | + default: all |
| 11 | + type: string |
| 12 | + push: |
| 13 | + branches: |
| 14 | + - feat/cortex_openai_coverage |
| 15 | + |
| 16 | +env: |
| 17 | + OPENAI_API_PYTHON_TAG: v1.23.2 |
| 18 | + |
| 19 | +jobs: |
| 20 | + openai-python-tests: |
| 21 | + runs-on: [self-hosted, Linux, ubuntu-desktop] |
| 22 | + steps: |
| 23 | + - name: Getting the repo |
| 24 | + uses: actions/checkout@v3 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: Installing node |
| 29 | + uses: actions/setup-node@v3 |
| 30 | + with: |
| 31 | + node-version: 20 |
| 32 | + |
| 33 | + - name: "Cleanup cache" |
| 34 | + continue-on-error: true |
| 35 | + run: | |
| 36 | + npm cache clean --force |
| 37 | +
|
| 38 | + - name: Install dependencies |
| 39 | + run: | |
| 40 | + npm install -g @stoplight/prism-cli |
| 41 | +
|
| 42 | + - run: yarn install && yarn build |
| 43 | + working-directory: ./cortex-js |
| 44 | + |
| 45 | + - run: |
| 46 | + | |
| 47 | + node cortex-js/dist/src/command.js serve --host 127.0.0.1 --port 4010 > cortex.log & cortex_pid=$! |
| 48 | + sleep 1 |
| 49 | + wget -O api.json http://127.0.0.1:4010/api-json |
| 50 | + kill $cortex_pid |
| 51 | + |
| 52 | + - name: Create python virtual environment and run test |
| 53 | + run: | |
| 54 | + python3 -m venv /tmp/jan |
| 55 | + source /tmp/jan/bin/activate |
| 56 | +
|
| 57 | + # Clone openai-api-python repo |
| 58 | + git clone https://github.com/openai/openai-python.git -b $OPENAI_API_PYTHON_TAG |
| 59 | + cd openai-python |
| 60 | + |
| 61 | + pip install -r requirements-dev.lock |
| 62 | + pip install pytest-reportportal pytest-html |
| 63 | + |
| 64 | + # Create pytest.ini file with content |
| 65 | + cp ../coverage/pytest.ini pytest.ini |
| 66 | + echo "rp_api_key=${{ secrets.RP_API_KEY }}" >> pytest.ini |
| 67 | + echo "rp_endpoint=${{ secrets.RP_ENDPOINT }}" >> pytest.ini |
| 68 | + |
| 69 | + # Append to conftest.py |
| 70 | + cp ../coverage/conftest.py tests/conftest.py |
| 71 | + cp ../coverage/endpoint_mapping.json tests/endpoints_mapping.json |
| 72 | + |
| 73 | + prism mock ../api.json > prism.log & prism_pid=$! |
| 74 | + # pytest --endpoint "$ENDPOINTS" --reportportal --html=report.html && kill $prism_pid |
| 75 | + pytest --endpoint all --reportportal --html=report.html && kill $prism_pid |
| 76 | + deactivate |
| 77 | + # env: |
| 78 | + # ENDPOINTS: ${{ github.event.inputs.endpoints }} |
| 79 | + |
| 80 | + |
| 81 | + - name: Collect RP artifacts |
| 82 | + run: | |
| 83 | + wget -O total-coverage.json "${{ secrets.RP_ENDPOINT }}/api/v1/openai-api-test/widget/27" --header 'authorization: bearer ${{ secrets.RP_API_KEY }}' |
| 84 | + wget -O today-endpoint.json "${{ secrets.RP_ENDPOINT }}/api/v1/openai-api-test/widget/multilevel/32" --header 'authorization: bearer ${{ secrets.RP_API_KEY }}' |
| 85 | + cat total-coverage.json |
| 86 | + current_date=$(date +"%m-%d-%Y") |
| 87 | + cp today-endpoint.json $current_date.json |
| 88 | + cat $current_date.json |
| 89 | +
|
| 90 | + - name: Upload report json files to S3 |
| 91 | + run: | |
| 92 | + current_date=$(date +"%m-%d-%Y") |
| 93 | + aws s3api put-object --endpoint-url https://${{ secrets.CLOUDFLARE_ACCOUNT_ID }}.r2.cloudflarestorage.com --bucket ${{ secrets.CLOUDFLARE_R2_BUCKET_NAME }} --key "openai-api-collection-test/$current_date.json" --body "./$current_date.json" --content-type "application/json" |
| 94 | + aws s3api put-object --endpoint-url https://${{ secrets.CLOUDFLARE_ACCOUNT_ID }}.r2.cloudflarestorage.com --bucket ${{ secrets.CLOUDFLARE_R2_BUCKET_NAME }} --key "openai-api-collection-test/total-coverage.json" --body "./total-coverage.json" --content-type "application/json" |
| 95 | + env: |
| 96 | + AWS_ACCESS_KEY_ID: ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY_ID }} |
| 97 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.CLOUDFLARE_R2_SECRET_ACCESS_KEY }} |
| 98 | + AWS_DEFAULT_REGION: auto |
| 99 | + AWS_EC2_METADATA_DISABLED: "true" |
| 100 | + |
| 101 | + - name: Upload Artifact |
| 102 | + uses: actions/upload-artifact@v2 |
| 103 | + with: |
| 104 | + name: report |
| 105 | + path: | |
| 106 | + openai-python/report.html |
| 107 | + openai-python/prism.log |
| 108 | + openai-python/cortex.log |
| 109 | + openai-python/total-coverage.json |
| 110 | + openai-python/today-endpoint.json |
| 111 | +
|
| 112 | + - name: Clean up |
| 113 | + if: always() |
| 114 | + run: | |
| 115 | + rm -rf /tmp/jan |
| 116 | + rm -rf openai-python |
| 117 | + rm -rf report.html |
| 118 | + rm -rf report.zip |
| 119 | + |
0 commit comments