Skip to content
Merged
Changes from all commits
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
97 changes: 97 additions & 0 deletions .github/workflows/save_data_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Test Storage (DB rotation)

on:
workflow_dispatch:
inputs:
status:
description: "Workflow status for the script"
required: true
type: choice
options: [successful, failed, cancelled]
default: successful
rotate_limit_kb:
description: "Rotate threshold in KiB (small -> force rotation quickly)"
required: true
default: "50"

permissions:
contents: write

jobs:
storage_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install sqlite3 (if missing)
run: |
if ! command -v sqlite3 >/dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y sqlite3
fi

- name: Fetch data storage branch
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git fetch --all
git checkout save_historical_data && git pull || git checkout -b save_historical_data

- name: Select persistent DB (rotate if near limit)
shell: bash
run: |
set -euo pipefail

DB_DIR="TSF"
DB_PREFIX="MemoryEfficientTestResultData"
LIMIT_BYTES=$(( ${{ inputs.rotate_limit_kb }} * 1024 ))
today=$(date -u +%F)

latest=$(git ls-tree -r --name-only origin/save_historical_data "$DB_DIR" \
| grep -E "^${DB_DIR}/${DB_PREFIX}_[0-9]{4}-[0-9]{2}-[0-9]{2}(_[0-9]{3})?\.db$" \
| sort | tail -n 1 || true)

if [ -z "${latest}" ]; then
new="${DB_DIR}/${DB_PREFIX}_${today}.db"
sqlite3 "$new" "PRAGMA user_version = 1;"
echo "TSF_PERSIST_DB=${new}" >> "$GITHUB_ENV"
echo "Created initial DB: $new"
exit 0
fi

git checkout save_historical_data -- "$latest"
size=$(stat -c%s "$latest")
echo "Current DB: $latest (${size} bytes), limit=${LIMIT_BYTES}"

if [ "$size" -ge "$LIMIT_BYTES" ]; then
base="${DB_DIR}/${DB_PREFIX}_${today}.db"
new="$base"
if [ -e "$new" ]; then
i=1
while [ -e "${DB_DIR}/${DB_PREFIX}_${today}_$(printf '%03d' "$i").db" ]; do
i=$((i+1))
done
new="${DB_DIR}/${DB_PREFIX}_${today}_$(printf '%03d' "$i").db"
fi
sqlite3 "$new" "PRAGMA user_version = 1;"
echo "Rotated -> $new"
latest="$new"
fi

echo "TSF_PERSIST_DB=${latest}" >> "$GITHUB_ENV"
echo "Using DB: $latest"

- name: Prepare minimal artifacts folder (empty is fine)
run: |
mkdir -p my_artifacts

- name: Run capture script (writes to TSF_PERSIST_DB)
run: |
python3 TSF/scripts/capture_test_data_memory_sensitive.py ${{ inputs.status }}

- name: Commit and Push DB
run: |
git checkout save_historical_data
git add "$TSF_PERSIST_DB"
git commit -m "Test storage update" || echo "No changes"
git push origin save_historical_data
Loading