Skip to content

Commit

Permalink
Github Actions to Maintain API Zoo Index (#188)
Browse files Browse the repository at this point in the history
This PR introduces two Github Actions: one for automating the process of
maintaining an up-to-date API Zoo Index and another for automating the
validation of new API documentation added to the API Zoo for duplicates.

#### Automatically update the mongodb index of the API Zoo when new API
documentation is added

- This Github Action is designed to automate the process of updating the
mongodb API Zoo index whenever new API documentation is added to the
`data/apizoo/` directory in the repo. Upon each push to the main branch
that includes changes to `data/apizoo/`, the action sends a request to
the `/api/update` endpoint of the server (which is running on a GCP VM
instance), which in turn updates the mongodb backend store with the new
documentation. This ensures that the API Zoo Index remains current and
reflects the latest additions.

#### Automatically validate new API documentation for duplicates

- This GitHub Action is aimed at automating the maintenance of the
quality of the API Zoo directory by validating new API documentation
against existing entries. The action is triggered by pull requests
affecting the `data/apizoo/` directory and verifies that there are no
duplicates among the newly added APIs by querying the `/api/validate`
endpoint of the server. If duplicate APIs are found, the action posts a
comment on the PR to alert reviewers.

If either of the Github actions fail due to server-side errors
(resulting in a non HTTP-200 response), an issue is automatically
raised.

The first example below shows the issue generated when authorization for
the `/api/update` server endpoint fails (due to the authorization token
being purposefully removed from the request sent by the action):

![Screenshot 2024-02-22 at 1 20 26
AM](https://github.com/ShishirPatil/gorilla/assets/76065183/186aa710-f6e9-4e20-ac98-db8811ed023d)

This second example shows the issue generated when a request to the
`/api/validate` endpoint results in the server responding with an error:

![Screenshot 2024-02-22 at 1 19 48
AM](https://github.com/ShishirPatil/gorilla/assets/76065183/cb610e60-0be1-4443-a4d0-660cd51d27ef)

The screenshot below shows the message that is automatically added to a
PR that attempts to update the API Zoo with duplicate API documentation
entries:

![Screenshot 2024-02-22 at 1 39 34
AM](https://github.com/ShishirPatil/gorilla/assets/76065183/4a93684e-264b-4f3f-aebe-d70290390a77)

---------

Co-authored-by: Raman Varma <[email protected]>
Co-authored-by: Shishir Patil <[email protected]>
  • Loading branch information
3 people authored Mar 15, 2024
1 parent dc7a4b0 commit 191e9fc
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/push-apizoo-updates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Update API Zoo Data

on:
push:
branches:
- main
paths:
- 'data/apizoo/**'

jobs:
send-updates:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
fetch-depth: 2

- name: Install Dependencies
run: sudo apt-get install -y jq curl

- name: Send Updated API Data to Server
run: |
REPO_URL="https://github.com/ShishirPatil/gorilla/blob/main/"
FILES=$(git diff --name-only ${{ github.sha }} ${{ github.event.before }} | grep 'data/apizoo/')
ERROR_FLAG=0
ISSUE_BODY=""
for FILE in $FILES; do
DATA=$(jq -c . < "$FILE")
FILE_URL="${REPO_URL}${FILE}"
JSON_BODY=$(jq --arg file_url "$FILE_URL" 'if type == "array" then map(. + {"file_url": $file_url}) else . + {"file_url": $file_url} end' <<< "$DATA")
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST -H "Content-Type: application/json" -H "Authorization: Bearer ${{ secrets.APIZOO_UPDATE_TOKEN }}" -d "$JSON_BODY" https://apizooindex.gorilla-llm.com/api/update)
BODY=$(echo "$RESPONSE" | head -n -1)
HTTP_STATUS=$(echo "$RESPONSE" | tail -n1)
if [ "$HTTP_STATUS" -ne 200 ]; then
ERROR_FLAG=1
ISSUE_BODY+="**Error adding API documentation in $FILE to the API Zoo Index**\n\n- HTTP Status: $HTTP_STATUS\n- Response:\n\`\`\`\n"
while read -r line; do
ISSUE_BODY+="$line\n"
done <<< "$BODY"
ISSUE_BODY+="\`\`\`\n\n"
fi
done
if [ "$ERROR_FLAG" -eq 1 ]; then
echo "ISSUE_BODY<<EOF" >> $GITHUB_ENV
echo "$ISSUE_BODY" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "ERRORS_DETECTED=true" >> $GITHUB_ENV
fi
- name: Prepare Issue Content If Errors Were Detected
if: env.ERRORS_DETECTED == 'true'
run: |
echo -e "name: API Zoo Index\nabout: Update Error\n\n**Describe the issue**\nError(s) occurred while adding new API documentation to the API Zoo Index.\n\n$ISSUE_BODY" > issue_content.md
echo "::set-output name=issue_file::issue_content.md"
- name: Create GitHub Issue on Error
if: env.ERRORS_DETECTED == 'true'
uses: peter-evans/create-issue-from-file@v5
with:
title: "[API Zoo] Error Updating API Zoo Index"
content-filepath: ./issue_content.md
labels: apizoo-index
token: ${{ secrets.GITHUB_TOKEN }}
76 changes: 76 additions & 0 deletions .github/workflows/validate-apizoo-contribution.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Validate API Zoo PR

on:
pull_request:
branches:
- main
paths:
- 'data/apizoo/**'

jobs:
check-api-update:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install jq
run: sudo apt-get install jq

- name: Check for duplicate APIs
id: check
run: |
FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep 'data/apizoo/')
ERROR_FLAG=0
ISSUE_BODY=""
for FILE in $FILES; do
DATA=$(jq -c . < "$FILE")
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST -H "Content-Type: application/json" -d "$DATA" https://apizooindex.gorilla-llm.com/api/validate)
BODY=$(echo "$RESPONSE" | head -n -1)
HTTP_STATUS=$(echo "$RESPONSE" | tail -n1)
echo "Validation response for $FILE: $RESPONSE"
if [ "$HTTP_STATUS" -ne 200 ]; then
ERROR_FLAG=1
ISSUE_BODY+="**Error validating new API documentation in $FILE for duplicates**\n\n- HTTP Status: $HTTP_STATUS\n- Response:\n\`\`\`\n"
while read -r line; do
ISSUE_BODY+="$line\n"
done <<< "$BODY"
ISSUE_BODY+="\`\`\`\n\n"
fi
if [[ "$RESPONSE" == *"\"duplicate\": true"* ]]; then
echo "::set-output name=duplicate::true"
break
fi
done
if [ "$ERROR_FLAG" -eq 1 ]; then
echo "ISSUE_BODY<<EOF" >> $GITHUB_ENV
echo "$ISSUE_BODY" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "ERRORS_DETECTED=true" >> $GITHUB_ENV
fi
- name: Prepare Issue Content If Errors Were Detected
if: env.ERRORS_DETECTED == 'true'
run: |
echo -e "name: API Zoo Index\nabout: Validation Error\n\n**Describe the issue**\nError(s) occurred while validating new API additions to the API Zoo Index.\n\n$ISSUE_BODY" > issue_content.md
echo "::set-output name=issue_file::issue_content.md"
- name: Create GitHub Issue on Error
if: env.ERRORS_DETECTED == 'true'
uses: peter-evans/create-issue-from-file@v5
with:
title: "[API Zoo] Error Validating New Additions To The API Zoo Index"
content-filepath: ./issue_content.md
labels: apizoo-index
token: ${{ secrets.GITHUB_TOKEN }}

- name: Comment on PR if duplicate API
if: steps.check.outputs.duplicate == 'true'
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
:warning: **Duplicate API detected**: This PR should not be merged.
token: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 191e9fc

Please sign in to comment.