added full cli package and CI execution
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
name: Daily Health Check
|
||||
|
||||
on:
|
||||
schedule:
|
||||
# Run daily at 6:00 AM UTC
|
||||
- cron: "0 6 * * *"
|
||||
workflow_dispatch: # Allow manual triggering
|
||||
|
||||
jobs:
|
||||
health-check:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "3.12"
|
||||
|
||||
- name: Install uv
|
||||
run: |
|
||||
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
uv sync
|
||||
|
||||
- name: Run health check
|
||||
env:
|
||||
ELOVERBLIK_API_TOKEN: ${{ secrets.ELOVERBLIK_API_TOKEN }}
|
||||
DB_HOST: ${{ secrets.DB_HOST }}
|
||||
DB_NAME: ${{ secrets.DB_NAME }}
|
||||
DB_USER: ${{ secrets.DB_USER }}
|
||||
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
|
||||
DB_PORT: ${{ secrets.DB_PORT }}
|
||||
run: |
|
||||
uv run energy-ingester health-check --verbose
|
||||
|
||||
- name: Report status
|
||||
run: |
|
||||
echo "Health check completed successfully!"
|
||||
|
||||
- name: Notify on failure
|
||||
if: failure()
|
||||
run: |
|
||||
echo "Health check failed! System may be down."
|
||||
# Add notification logic here (email, Slack, etc.)
|
||||
exit 1
|
||||
@@ -0,0 +1,177 @@
|
||||
name: Database Setup
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
action:
|
||||
description: "Database action to perform"
|
||||
required: true
|
||||
default: "setup"
|
||||
type: choice
|
||||
options:
|
||||
- setup
|
||||
- migrate
|
||||
- reset
|
||||
confirm:
|
||||
description: 'Type "yes" to confirm destructive operations'
|
||||
required: false
|
||||
default: "no"
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
database-setup:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "3.12"
|
||||
|
||||
- name: Install uv
|
||||
run: |
|
||||
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
uv sync
|
||||
|
||||
- name: Validate inputs
|
||||
run: |
|
||||
if [[ "${{ github.event.inputs.action }}" == "reset" && "${{ github.event.inputs.confirm }}" != "yes" ]]; then
|
||||
echo "❌ Reset operation requires confirmation. Please type 'yes' in the confirm field."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Database Setup
|
||||
if: github.event.inputs.action == 'setup'
|
||||
env:
|
||||
ELOVERBLIK_API_TOKEN: ${{ secrets.ELOVERBLIK_API_TOKEN }}
|
||||
DB_HOST: ${{ secrets.DB_HOST }}
|
||||
DB_NAME: ${{ secrets.DB_NAME }}
|
||||
DB_USER: ${{ secrets.DB_USER }}
|
||||
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
|
||||
DB_PORT: ${{ secrets.DB_PORT }}
|
||||
run: |
|
||||
echo "🏗️ Setting up database tables..."
|
||||
uv run python -c "
|
||||
from energy_consumption_ingester import DatabaseStorage
|
||||
from dotenv import load_dotenv
|
||||
import sys
|
||||
|
||||
load_dotenv()
|
||||
db = DatabaseStorage.from_env()
|
||||
|
||||
if db.connect():
|
||||
print('✅ Database connection successful')
|
||||
if db.create_tables():
|
||||
print('✅ Database tables created successfully')
|
||||
else:
|
||||
print('❌ Failed to create tables')
|
||||
sys.exit(1)
|
||||
else:
|
||||
print('❌ Failed to connect to database')
|
||||
sys.exit(1)
|
||||
|
||||
db.close()
|
||||
print('🎉 Database setup completed!')
|
||||
"
|
||||
|
||||
- name: Database Migration
|
||||
if: github.event.inputs.action == 'migrate'
|
||||
env:
|
||||
ELOVERBLIK_API_TOKEN: ${{ secrets.ELOVERBLIK_API_TOKEN }}
|
||||
DB_HOST: ${{ secrets.DB_HOST }}
|
||||
DB_NAME: ${{ secrets.DB_NAME }}
|
||||
DB_USER: ${{ secrets.DB_USER }}
|
||||
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
|
||||
DB_PORT: ${{ secrets.DB_PORT }}
|
||||
run: |
|
||||
echo "🔄 Running database migrations..."
|
||||
uv run python -c "
|
||||
from energy_consumption_ingester import DatabaseStorage
|
||||
from dotenv import load_dotenv
|
||||
import sys
|
||||
|
||||
load_dotenv()
|
||||
db = DatabaseStorage.from_env()
|
||||
|
||||
if db.connect():
|
||||
print('✅ Database connection successful')
|
||||
if db.create_tables():
|
||||
print('✅ Database migrations completed')
|
||||
else:
|
||||
print('❌ Migration failed')
|
||||
sys.exit(1)
|
||||
else:
|
||||
print('❌ Failed to connect to database')
|
||||
sys.exit(1)
|
||||
|
||||
db.close()
|
||||
print('🎉 Migration completed!')
|
||||
"
|
||||
|
||||
- name: Database Reset (DESTRUCTIVE)
|
||||
if: github.event.inputs.action == 'reset' && github.event.inputs.confirm == 'yes'
|
||||
env:
|
||||
ELOVERBLIK_API_TOKEN: ${{ secrets.ELOVERBLIK_API_TOKEN }}
|
||||
DB_HOST: ${{ secrets.DB_HOST }}
|
||||
DB_NAME: ${{ secrets.DB_NAME }}
|
||||
DB_USER: ${{ secrets.DB_USER }}
|
||||
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
|
||||
DB_PORT: ${{ secrets.DB_PORT }}
|
||||
run: |
|
||||
echo "🚨 RESETTING DATABASE - THIS WILL DELETE ALL DATA!"
|
||||
uv run python -c "
|
||||
from energy_consumption_ingester import DatabaseStorage
|
||||
from dotenv import load_dotenv
|
||||
import sys
|
||||
|
||||
load_dotenv()
|
||||
db = DatabaseStorage.from_env()
|
||||
|
||||
if db.connect():
|
||||
print('✅ Database connection successful')
|
||||
|
||||
# Drop tables
|
||||
cursor = db.connection.cursor()
|
||||
cursor.execute('DROP TABLE IF EXISTS consumption_readings CASCADE;')
|
||||
cursor.execute('DROP TABLE IF EXISTS metering_points CASCADE;')
|
||||
cursor.execute('DROP FUNCTION IF EXISTS update_updated_at_column() CASCADE;')
|
||||
db.connection.commit()
|
||||
print('🗑️ Existing tables dropped')
|
||||
|
||||
# Recreate tables
|
||||
if db.create_tables():
|
||||
print('✅ Database tables recreated')
|
||||
else:
|
||||
print('❌ Failed to recreate tables')
|
||||
sys.exit(1)
|
||||
else:
|
||||
print('❌ Failed to connect to database')
|
||||
sys.exit(1)
|
||||
|
||||
db.close()
|
||||
print('🎉 Database reset completed!')
|
||||
"
|
||||
|
||||
- name: Test Connection
|
||||
env:
|
||||
ELOVERBLIK_API_TOKEN: ${{ secrets.ELOVERBLIK_API_TOKEN }}
|
||||
DB_HOST: ${{ secrets.DB_HOST }}
|
||||
DB_NAME: ${{ secrets.DB_NAME }}
|
||||
DB_USER: ${{ secrets.DB_USER }}
|
||||
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
|
||||
DB_PORT: ${{ secrets.DB_PORT }}
|
||||
run: |
|
||||
echo "🔍 Testing system health..."
|
||||
uv run energy-ingester health-check --verbose
|
||||
|
||||
- name: Summary
|
||||
run: |
|
||||
echo "✅ Database operation '${{ github.event.inputs.action }}' completed successfully!"
|
||||
echo "💡 You can now run the hourly sync or manual sync operations."
|
||||
@@ -0,0 +1,47 @@
|
||||
name: Hourly Energy Data Sync
|
||||
|
||||
on:
|
||||
schedule:
|
||||
# Run every hour at minute 5 (to avoid peak times)
|
||||
- cron: "5 * * * *"
|
||||
workflow_dispatch: # Allow manual triggering
|
||||
|
||||
jobs:
|
||||
sync-energy-data:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "3.12"
|
||||
|
||||
- name: Install uv
|
||||
run: |
|
||||
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
uv sync
|
||||
|
||||
- name: Run incremental sync
|
||||
env:
|
||||
ELOVERBLIK_API_TOKEN: ${{ secrets.ELOVERBLIK_API_TOKEN }}
|
||||
DB_HOST: ${{ secrets.DB_HOST }}
|
||||
DB_NAME: ${{ secrets.DB_NAME }}
|
||||
DB_USER: ${{ secrets.DB_USER }}
|
||||
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
|
||||
DB_PORT: ${{ secrets.DB_PORT }}
|
||||
run: |
|
||||
uv run energy-ingester sync-incremental --verbose
|
||||
|
||||
- name: Notify on failure
|
||||
if: failure()
|
||||
run: |
|
||||
echo "Energy data sync failed! Check logs and database connectivity."
|
||||
# Add notification logic here (email, Slack, etc.)
|
||||
exit 1
|
||||
@@ -0,0 +1,53 @@
|
||||
name: Manual Full Sync
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
days:
|
||||
description: "Number of days to sync"
|
||||
required: true
|
||||
default: "30"
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
full-sync:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: "3.12"
|
||||
|
||||
- name: Install uv
|
||||
run: |
|
||||
curl -LsSf https://astral.sh/uv/install.sh | sh
|
||||
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
uv sync
|
||||
|
||||
- name: Run full sync
|
||||
env:
|
||||
ELOVERBLIK_API_TOKEN: ${{ secrets.ELOVERBLIK_API_TOKEN }}
|
||||
DB_HOST: ${{ secrets.DB_HOST }}
|
||||
DB_NAME: ${{ secrets.DB_NAME }}
|
||||
DB_USER: ${{ secrets.DB_USER }}
|
||||
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
|
||||
DB_PORT: ${{ secrets.DB_PORT }}
|
||||
run: |
|
||||
uv run energy-ingester sync --days ${{ github.event.inputs.days }} --verbose
|
||||
|
||||
- name: Summary
|
||||
run: |
|
||||
echo "Full sync completed for ${{ github.event.inputs.days }} days!"
|
||||
|
||||
- name: Notify on failure
|
||||
if: failure()
|
||||
run: |
|
||||
echo "Full sync failed!"
|
||||
exit 1
|
||||
@@ -0,0 +1,13 @@
|
||||
name: Python Code Quality
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
python-code-quality:
|
||||
uses: brian/CI-templates/.gitea/workflows/python/[email protected]
|
||||
with:
|
||||
python-version: ${{ vars.PYTHON_VERSION }}
|
||||
@@ -1,47 +0,0 @@
|
||||
name: Database Setup Automation
|
||||
|
||||
on:
|
||||
# Trigger the workflow manually from the Gitea UI
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
create_db_and_user:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
container:
|
||||
image: node:20-alpine
|
||||
|
||||
steps:
|
||||
- name: Install PostgreSQL Client
|
||||
run: |
|
||||
# Install psql client on Alpine Linux
|
||||
apk add --no-cache postgresql-client
|
||||
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Configure and Create PostgreSQL Resources
|
||||
# Set environment variables from the Gitea Secrets
|
||||
env:
|
||||
POSTGRES_HOST: ${{ secrets.POSTGRES_HOST }}
|
||||
POSTGRES_PORT: ${{ secrets.POSTGRES_PORT }}
|
||||
POSTGRES_ADMIN_USER: ${{ secrets.POSTGRES_ADMIN_USER }}
|
||||
POSTGRES_ADMIN_PASSWORD: ${{ secrets.POSTGRES_ADMIN_PASSWORD }}
|
||||
NEW_DB_NAME: ${{ secrets.NEW_DB_NAME }}
|
||||
NEW_DB_USER: ${{ secrets.NEW_DB_USER }}
|
||||
NEW_DB_PASSWORD: ${{ secrets.NEW_DB_PASSWORD }}
|
||||
|
||||
run: |
|
||||
echo "Running database creation script..."
|
||||
|
||||
# Add executable permission to the script
|
||||
chmod +x ./scripts/create_db_user.sh
|
||||
|
||||
# Export the admin password so psql can use it automatically
|
||||
export PGPASSWORD=$POSTGRES_ADMIN_PASSWORD
|
||||
|
||||
# Execute the script
|
||||
./scripts/create_db_user.sh
|
||||
|
||||
# Unset the password variable for security
|
||||
unset PGPASSWORD
|
||||
Reference in New Issue
Block a user