Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#313 Update generate_openapi_code.sh #547

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 82 additions & 12 deletions scripts/generate_openapi_code.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,87 @@
#!/usr/bin/env bash

# Turn on echo command
set -x
# Turn on command echo and exit on error
set -xe

# Exit on error
set -e
# Define log file for output
LOG_FILE="script.log"
TIME_FORMAT="+%Y-%m-%d %H:%M:%S"

cd typespec/ && \
tsp compile .
cd -
# Function to log actions
log_action() {
echo "$(date "$TIME_FORMAT") - $1" | tee -a "$LOG_FILE"
}

cd agents-api && \
# poetry update && \
poetry run poe codegen && \
poetry run poe format
cd -
# Function to compile TypeSpec project
compile_typespec() {
log_action "Starting TypeSpec compilation"
cd typespec/ || { echo "Error: Failed to navigate to typespec/ directory"; exit 1; }
tsp compile . || { echo "Error: TypeSpec compilation failed"; exit 1; }
cd - > /dev/null
log_action "Finished TypeSpec compilation"
}

# Function to run Poetry tasks
run_poetry_tasks() {
log_action "Navigating to agents-api directory"
cd agents-api || { echo "Error: Failed to navigate to agents-api/ directory"; exit 1; }

# Update dependencies if the flag is set
if [[ "$UPDATE_POETRY" == "true" ]]; then
log_action "Updating Poetry dependencies"
poetry update || { echo "Error: Poetry update failed"; exit 1; }
fi

log_action "Running code generation"
poetry run poe codegen || { echo "Error: Code generation failed"; exit 1; }

log_action "Running code formatting"
poetry run poe format || { echo "Error: Code formatting failed"; exit 1; }

cd - > /dev/null
log_action "Finished Poetry tasks in agents-api"
}

# Function to display script usage
usage() {
echo "Usage: $0 [options]"
echo "Options:"
echo " --update-poetry Update Poetry dependencies before running tasks"
echo " -h, --help Show this help message"
}

# Parse arguments
while [[ "$#" -gt 0 ]]; do
case "$1" in
--update-poetry)
UPDATE_POETRY="true"
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown parameter passed: $1"
usage
exit 1
;;
esac
done

# Start time logging
START_TIME=$(date +%s)

# Main execution
log_action "Script execution started"
compile_typespec
run_poetry_tasks

# End time logging
END_TIME=$(date +%s)
ELAPSED_TIME=$((END_TIME - START_TIME))

log_action "Script execution completed in $ELAPSED_TIME seconds"

# Success exit
exit 0
Loading