-
Notifications
You must be signed in to change notification settings - Fork 7
168 lines (145 loc) · 5.78 KB
/
initial_setup_test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
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