Skip to content

send-docs

send-docs #1395

name: Receive Documentation
on:
repository_dispatch:
types: [send-docs]
permissions:
contents: write
jobs:
process-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Receive and Persist JSON OpenAPI specs
env:
AUTHOR: ${{ github.event.client_payload.author }}
OPENAPI_COMPRESSED: ${{ github.event.client_payload.file_content_base_64 }}
APP_NAME: ${{ github.event.client_payload.app_name }}
WEB_OPENAPI_PATH: ${{ github.workspace }}/web/openapi_specs
run: |
author=$GITHUB_AUTHOR
echo "::notice:: Process triggered by $AUTHOR"
# Replace - by _ in order to avoid some errors at generating packages.
APP_NAME=$(echo $APP_NAME | sed s/-/_/g)
if [[ $APP_NAME == "" ]]; then
echo "::error:: APP_NAME cannot be empty"
exit 1
fi
openapi_filename="$APP_NAME"_openapi_specification.json
openapi_filepath=$WEB_OPENAPI_PATH/$openapi_filename
echo "Persisting openapi specs in $openapi_filepath"
OPENAPI=$(echo $OPENAPI_COMPRESSED | base64 -d | unxz -c)
echo $OPENAPI > $openapi_filepath
echo "----"
echo "API_ROOT_DIR=${{ github.workspace }}/apis" >> $GITHUB_ENV
echo "CLIENT_ROOT_DIR=${{ github.workspace }}/agentverse-client" >> $GITHUB_ENV
echo "::notice::Update for $APP_NAME"
echo "APP_NAME=$APP_NAME" >> $GITHUB_ENV
echo "openapi_filepath=$openapi_filepath" >> $GITHUB_ENV
echo "openapi_filename=$openapi_filename" >> $GITHUB_ENV
- name: Check registered apps and get client path
run: |
app_key="${{ github.event.client_payload.app_name }}"
registered_apps="${{ vars.APP_MAPPING }}"
# decode
registered_apps=$(echo $registered_apps | xxd -r -p)
# get path from json
client_path=$(echo $registered_apps | jq -rc '.["'$app_key'"]')
if [ $client_path = "null" ]
then
exit 1
else
client_path=$(echo $client_path | sed s/-/_/g)
echo "CLIENT_PATH=$client_path" >> $GITHUB_ENV
fi
- name: Create scaffolding & register docs
run: |
echo "API_ROOT_DIR: $API_ROOT_DIR"
# TODO: What to do with conflict?
if [ ! -d $API_ROOT_DIR/$APP_NAME ]
then
echo "::notice:: Creating dir $API_ROOT_DIR/$APP_NAME"
mkdir $API_ROOT_DIR/$APP_NAME
else
echo "API $API_ROOT_DIR/$APP_NAME already exists."
fi
# Add file to register docs into fastapi
cat <<- EOF > $API_ROOT_DIR/$APP_NAME/register_api_docs.py
api_id: str = '$APP_NAME'
openapi_specs_name: str = '$openapi_filename'
docs_endpoint_name: str = '/$APP_NAME/'
EOF
# SYNC CLIENT GENERATION
# ---
- name: "SYNC CLIENT: Prepare openapi config file"
env:
CLIENT_ROOT_PROJECT_NAME: "agentverse_client"
LIBRARY: urllib3
PACKAGE_NAME: agentverse_client.${{env.CLIENT_PATH}}
run: |
config_file_path="./generator_config_file.yaml"
# CONFIG FILE DEFINITION
cat <<- EOF -> $config_file_path
templateDir: custom_templates
generatorName: python
inputSpec: $openapi_filepath
additionalProperties:
packageName: $PACKAGE_NAME
projectName: $APP_NAME
generateSourceCodeOnly: true
library: $LIBRARY
basePath: https://agentverse.ai # This and serverURL have to be the same value
serverURL: https://agentverse.ai # This and basePath have to be the same value
files:
configuration.mustache:
templateType: SupportingFiles
destinationFilename: "agentverse_client/$CLIENT_PATH/configuration.py"
configOptions:
packageVersion: "1.0.0"
EOF
cat $config_file_path
echo "config_file_path=$config_file_path" >> $GITHUB_ENV
echo $OPENAPI > ./openapi.json
- name: "SYNC CLIENT: Generate client"
uses: openapi-generators/openapitools-generator-action@v1
env:
API_TAG: ${{ github.event.client_payload.api_tag }}
with:
generator: python
generator-tag: 'v7.11.0'
config-file: ${{ env.config_file_path }}
openapi-file: ./web/openapi_specs/${{ env.openapi_filename }}
command-args: "--global-property models,supportingFiles,apis='$API_TAG' -o ./agentverse-client"
# ---
# ASYNC CLIENT GENERATION
# ---
- name: "ASYNC CLIENT: Prepare openapi config file"
env:
CLIENT_ROOT_PROJECT_NAME: "agentverse_client"
LIBRARY: asyncio
ROOT_PACKAGE_NAME: agentverse_client
ASYNC_CLIENT_DIR_NAME: aio
PACKAGE_NAME: ${{ env.CLIENT_PATH }}
run: |
echo "ROOT_PACKAGE_NAME=$ROOT_PACKAGE_NAME" >> $GITHUB_ENV
echo "ASYNC_CLIENT_DIR_NAME=$ASYNC_CLIENT_DIR_NAME" >> $GITHUB_ENV
ASYNC_PACKAGE_NAME="$ROOT_PACKAGE_NAME".$CLIENT_PATH."$ASYNC_CLIENT_DIR_NAME"
config_file_path="./generator_config_file.yaml"
# CONFIG FILE DEFINITION
cat <<- EOF -> $config_file_path
templateDir: custom_templates
generatorName: python
inputSpec: $openapi_filepath
additionalProperties:
packageName: $ASYNC_PACKAGE_NAME
projectName: $APP_NAME
generateSourceCodeOnly: true
library: $LIBRARY
basePath: https://agentverse.ai # This and serverURL have to be the same value
serverURL: https://agentverse.ai # This and basePath have to be the same value
files:
configuration.mustache:
templateType: SupportingFiles
destinationFilename: "agentverse_client/$CLIENT_PATH/$ASYNC_CLIENT_DIR_NAME/configuration.py"
configOptions:
packageVersion: "1.0.0"
EOF
cat $config_file_path
echo "config_file_path=$config_file_path" >> $GITHUB_ENV
echo $OPENAPI > ./openapi.json
- name: "ASYNC CLIENT: Generate client"
uses: openapi-generators/openapitools-generator-action@v1
env:
API_TAG: ${{ github.event.client_payload.api_tag }}
ASYNC_OUTPUT_LOCATION: "./tmp_async_agentverse-client"
with:
generator: python
generator-tag: 'v7.11.0'
config-file: ${{ env.config_file_path }}
openapi-file: ./web/openapi_specs/${{ env.openapi_filename }}
command-args: "--global-property models,supportingFiles,apis='$API_TAG' -o $ASYNC_OUTPUT_LOCATION"
# ---
# Moving async client to the root client dir.
# ---
- name: Move async client to the root client dir.
env:
ASYNC_OUTPUT_LOCATION: "./tmp_async_agentverse-client"
run: |
ASYNC_PACKAGE_NAME="$ROOT_PACKAGE_NAME".$CLIENT_PATH."$ASYNC_CLIENT_DIR_NAME"
rm -fR $CLIENT_ROOT_DIR/agentverse_client/$CLIENT_PATH/$ASYNC_CLIENT_DIR_NAME
mv "$ASYNC_OUTPUT_LOCATION"/"$ROOT_PACKAGE_NAME"/$CLIENT_PATH/"$ASYNC_CLIENT_DIR_NAME" $CLIENT_ROOT_DIR/agentverse_client/$CLIENT_PATH
# ---
- name: Persist changes with Git
run: |
echo "Commiting dir $API_ROOT_DIR/$APP_NAME, ${{ github.workspace }}/web/ and ${{ env.CLIENT_ROOT_DIR }}"
git config --local user.name "fetchbot"
git config --local user.email "fetchbot@fetch.ai"
# Pull before pushing changes to avoid conflicts
git stash
git pull
if git stash list | grep -q 'stash@'; then
echo "Stash entries found, popping the latest one"
git stash pop
echo "Stash popped successfully"
else
echo "No stash entries found, skipping stash pop"
fi
git add $API_ROOT_DIR/$APP_NAME ${{ github.workspace }}/web/ ${{ env.CLIENT_ROOT_DIR }}
git commit -m "Adding or updating docs and client for $APP_NAME" || echo "No changes to commit"
git push