Test - OpenAI API Coverage - Nightly / Manual #2
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: Test - OpenAI API Coverage - Nightly / Manual | |
on: | |
schedule: | |
- cron: '0 20 * * 1,2,3,4,5,6' | |
workflow_dispatch: | |
inputs: | |
endpoints: | |
description: 'comma-separated list (see available at coverage/endpoint_mapping.json e.g. GET /users,POST /transform)' | |
required: false | |
default: all | |
type: string | |
branch: | |
description: 'Target github branch - default is dev' | |
required: false | |
default: dev | |
type: string | |
env: | |
OPENAI_API_PYTHON_TAG: v1.33.0 | |
TARGET_BRANCH: ${{ github.event.inputs.branch }} | |
jobs: | |
openai-python-tests: | |
runs-on: ubuntu-20-04-openai-api-collection-test | |
steps: | |
- name: Getting the repo | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
# ref: ${{ env.TARGET_BRANCH }} | |
- name: Installing node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- run: npm install -g yarn && yarn install && yarn build | |
working-directory: ./platform | |
- name: install python venv | |
run: | | |
sudo apt-get update | |
sudo apt-get install python3-venv -y | |
python3 -m venv /tmp/jan | |
- name: Run test | |
run: | | |
node platform/dist/src/command.js --address 127.0.0.1 --port 4010 > cortex.log | |
sleep 3 | |
wget --no-verbose -O api.json http://127.0.0.1:4010/api-json | |
cat api.json | |
source /tmp/jan/bin/activate | |
# Clone openai-api-python repo | |
git clone https://github.com/openai/openai-python.git -b $OPENAI_API_PYTHON_TAG | |
cd openai-python | |
pip3 install -r requirements-dev.lock | |
pip3 install pytest-reportportal pytest-html | |
cat ../coverage/conftest.py >> tests/conftest.py | |
cat ../coverage/endpoint_mapping.json >> tests/endpoints_mapping.json | |
cat ../coverage/pytest.ini >> pytest.ini | |
echo "rp_api_key = ${{ secrets.RP_API_KEY }}" >> pytest.ini | |
echo "rp_endpoint = ${{ secrets.RP_ENDPOINT }}" >> pytest.ini | |
pytest --endpoint "$ENDPOINTS" --reportportal --html=report.html -v || true | |
deactivate | |
env: | |
ENDPOINTS: ${{ github.event.inputs.endpoints }} | |
TEST_API_BASE_URL: http://127.0.0.1:4010/v1 | |
- name: Collect RP artifacts | |
run: | | |
wget --no-verbose -O total-coverage.json "${{ secrets.RP_ENDPOINT }}/api/v1/openai-api-test/widget/27" --header 'authorization: bearer ${{ secrets.RP_API_KEY }}' | |
wget --no-verbose -O today-endpoint.json "${{ secrets.RP_ENDPOINT }}/api/v1/openai-api-test/widget/multilevel/32" --header 'authorization: bearer ${{ secrets.RP_API_KEY }}' | |
echo "Overall coverage" | |
cat total-coverage.json | |
current_date=$(date +"%m-%d-%Y") | |
cp today-endpoint.json $current_date.json | |
echo "Endpoint today" | |
cat $current_date.json | |
- name: Upload report json files to S3 | |
run: | | |
current_date=$(date +"%m-%d-%Y") | |
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" | |
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" | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.CLOUDFLARE_R2_SECRET_ACCESS_KEY }} | |
AWS_DEFAULT_REGION: auto | |
AWS_EC2_METADATA_DISABLED: "true" | |
- name: Upload Artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: report | |
path: | | |
openai-python/report.html | |
openai-python/cortex.log | |
openai-python/total-coverage.json | |
openai-python/today-endpoint.json | |
api.json | |
- name: Clean up | |
if: always() | |
run: | | |
node platform/dist/src/command.js stop | |
rm -rf /tmp/jan | |
rm -rf openai-python | |
rm -rf report.html | |
rm -rf report.zip |