Test Initial Setup Github Actions Workflow Setup and Bugfixing #14
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
name: Test Initial Setup | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
workflow_dispatch: | |
inputs: | |
use-cache: | |
description: "Use cached dependencies" | |
required: false | |
default: "true" | |
jobs: | |
initial_setup: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Check out the repository | |
- name: Check Out Repository | |
uses: actions/checkout@v2 | |
# Step 2: Set Up Python | |
- name: Set Up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.x" | |
cache: "pip" | |
# Step 4: Create Virtual Environment | |
- name: Create Virtual Environment | |
run: | | |
set -e | |
python -m venv venv | |
echo "Virtual environment created." | |
# Step 5: Install Python Dependencies | |
- name: Install Python Dependencies | |
run: | | |
set -e | |
source venv/bin/activate | |
pip install --upgrade pip | |
pip install -r requirements.txt | |
# Step 6: Set Up .env File | |
- name: Set Up .env File | |
run: | | |
set -e | |
source venv/bin/activate | |
cp .env.template .env | |
PROJECT_ROOT=$(pwd) | |
sed -i "s|/path/to/your/project/root|$PROJECT_ROOT|g" .env | |
# Step 7: Configure Database and Show Table Info | |
- name: Configure Database and Show Table Info | |
run: | | |
set -e | |
source venv/bin/activate | |
sed -i 's|path: "data/NBA_AI_2023_2024.sqlite"|path: "data/NBA_AI_BASE.sqlite"|g' config.yaml | |
# Display database tables and record counts in a formatted table | |
DB_PATH="data/NBA_AI_BASE.sqlite" | |
echo -e "\nDatabase Tables and Record Counts:" | |
echo "------------------------------------" | |
printf "%-20s | %-10s\n" "Table Name" "Record Count" | |
echo "------------------------------------" | |
for table in $(sqlite3 $DB_PATH ".tables"); do | |
count=$(sqlite3 $DB_PATH "SELECT COUNT(*) FROM $table;") | |
printf "%-20s | %-10s\n" "$table" "$count" | |
done | |
echo "------------------------------------" | |
# Step 8: Launch the Application and Get Basic Info with Retry Logic | |
- name: Launch Application and Get Basic Info | |
run: | | |
set -e | |
source venv/bin/activate | |
# Start the app in the background and log output to app.log | |
python start_app.py > app.log 2>&1 & | |
APP_PID=$! | |
sleep 10 # Increased delay for initialization | |
# Retry loop for HTTP status check | |
MAX_RETRIES=5 | |
RETRY_DELAY=5 | |
STATUS_CODE=0 | |
for ((i=1; i<=MAX_RETRIES; i++)); do | |
STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:5000) | |
if [ "$STATUS_CODE" -eq 200 ]; then | |
echo "Web app is responding with 200 OK" | |
break | |
else | |
echo "Attempt $i: Web app not responding yet. Status code: $STATUS_CODE" | |
sleep $RETRY_DELAY | |
fi | |
done | |
# If the status code isn't 200 after retries, exit with an error | |
if [ "$STATUS_CODE" -ne 200 ]; then | |
echo "Web app did not respond with 200 OK after $MAX_RETRIES attempts." | |
kill $APP_PID | |
exit 1 | |
fi | |
# Extract <title> tag content | |
TITLE=$(curl -s http://127.0.0.1:5000 | grep -oP '(?<=<title>)(.*?)(?=</title>)') | |
echo "Page Title: $TITLE" | |
# Step 9: Verify Content Load with Puppeteer and Monitor Logs | |
- name: Verify Content Load with Puppeteer and Monitor Logs | |
run: | | |
# Install Node.js and Puppeteer for testing | |
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo bash - | |
sudo apt-get install -y nodejs | |
npm install puppeteer | |
# Run Puppeteer script inline and monitor logs in parallel | |
node -e " | |
const puppeteer = require('puppeteer'); | |
(async () => { | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
try { | |
console.log('Navigating to the web app...'); | |
await page.goto('http://127.0.0.1:5000', { waitUntil: 'networkidle2' }); | |
console.log('Waiting for main data to load via JS...'); | |
await page.waitForResponse(response => | |
response.url().includes('get-game-data') && response.status() === 200, | |
{ timeout: 60000 } // 10-minute timeout | |
); | |
console.log('Main data loaded. Waiting additional 10 seconds for images and assets...'); | |
await page.waitForTimeout(10000); | |
console.log('All main data and assets should be loaded.'); | |
process.exit(0); // Exit successfully | |
} catch (error) { | |
console.error('Content did not fully load within the expected duration:', error); | |
process.exit(1); // Exit with failure | |
} finally { | |
await browser.close(); | |
} | |
})(); | |
" & | |
# Store Puppeteer's process ID | |
PUPPETEER_PID=$! | |
# Monitor application logs incrementally during Puppeteer execution | |
while kill -0 $PUPPETEER_PID 2> /dev/null; do | |
echo "------------------------------------" | |
echo "Latest application logs:" | |
cat app.log # Display all lines of the log for incremental updates | |
sleep 5 # Wait a few seconds before checking again | |
done | |
# Wait for Puppeteer to finish, whether it succeeded or failed | |
wait $PUPPETEER_PID | |
# Step 10: Stop the Application | |
- name: Stop Application | |
if: ${{ always() }} | |
run: kill $APP_PID || true |