Skip to content

Commit

Permalink
Merge pull request #1686 from Agenta-AI/add-check-app-accessibility
Browse files Browse the repository at this point in the history
add action to check the app accessibility after serving
  • Loading branch information
aakrem authored May 21, 2024
2 parents f4e608b + 8fc7a38 commit 8f47307
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
40 changes: 40 additions & 0 deletions .github/actions/check-app-accessibility/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: 'Check App Accessibility'
description: 'Parse logs and check if the app is running'
inputs:
log-file:
description: 'The path to the log file containing the serve output'
required: true
runs:
using: "composite"
steps:
- name: Parse logs and check if app is running
id: check-app
shell: bash
run: |
echo "Serve output:"
cat ${{ inputs.log-file }}
APP_URL=$(grep -oP 'You can access it here: \K.+' ${{ inputs.log-file }} | head -n 1)
echo "Extracted app URL: $APP_URL"
if [ -z "$APP_URL" ]; then
echo "Error: Failed to extract app URL from logs."
exit 1
fi
APP_URL="${APP_URL%/}/openapi.json"
echo "Checking if $APP_URL is accessible"
retries=6
for i in $(seq 1 $retries); do
status_code=$(curl --max-time 60 --write-out %{http_code} --silent --output /dev/null --verbose $APP_URL)
echo "Attempt $i: Status code: $status_code"
if [ "$status_code" -eq 200 ]; then
echo "$APP_URL is accessible"
exit 0
else
echo "Attempt $i failed: $APP_URL is not accessible"
sleep 10 # Wait before retrying
fi
done
echo "Error: $APP_URL is not accessible after $retries attempts"
exit 1
16 changes: 14 additions & 2 deletions .github/workflows/cli-commands-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,16 @@ jobs:
- name: Run agenta variant serve
run: |
cd examples/baby_name_generator
agenta variant serve --file_name app.py
agenta variant serve --file_name app.py 2>&1 | tee ../../serve_output.log
shell: bash
continue-on-error: false

- name: Check if app is running
uses: ./.github/actions/check-app-accessibility
with:
log-file: serve_output.log
continue-on-error: false

- name: Run agenta variant serve with overwrite
run: |
cd examples/baby_name_generator
Expand Down Expand Up @@ -90,10 +96,16 @@ jobs:
- name: Run agenta variant serve
run: |
cd examples/baby_name_generator
agenta variant serve --file_name app.py
agenta variant serve --file_name app.py 2>&1 | tee ../../serve_output.log
shell: bash
continue-on-error: false

- name: Check if app is running
uses: ./.github/actions/check-app-accessibility
with:
log-file: serve_output.log
continue-on-error: false

- name: Run agenta variant serve with overwrite
run: |
cd examples/baby_name_generator
Expand Down

0 comments on commit 8f47307

Please sign in to comment.