-
Notifications
You must be signed in to change notification settings - Fork 892
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The script has been enhanced by organizing the tasks into functions for improved readability and modularity. A logging system was introduced to capture and store actions in both the console and a log file for better traceability. Error handling was added to ensure that any failures are caught with custom error messages, improving the robustness of the script. Additionally, an optional feature allows updating Poetry dependencies via a command-line flag, adding flexibility. The script now tracks the total execution time, providing insights into performance. Overall, the improvements make the script more structured, flexible, and user-friendly.
- Loading branch information
1 parent
50a95ca
commit 9f5d9c8
Showing
1 changed file
with
82 additions
and
12 deletions.
There are no files selected for viewing
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
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 |