chore: cleanup

This commit is contained in:
valknarness
2025-11-03 19:49:34 +01:00
parent a36a7dac35
commit 50e96855f0
2 changed files with 0 additions and 506 deletions

View File

@@ -1,258 +0,0 @@
name: Build Awesome Database
on:
# Disabled: Database is now built on VPS via systemd timer
# schedule:
# # Run daily at 02:00 UTC
# - cron: '0 2 * * *'
workflow_dispatch: # Allow manual triggering (kept for emergency use)
inputs:
index_mode:
description: 'Indexing mode'
required: false
default: 'full'
type: choice
options:
- full
- sample
incremental:
description: 'Incremental mode (skip unchanged repos)'
required: false
default: true
type: boolean
permissions:
contents: read
actions: write
jobs:
build-database:
runs-on: ubuntu-latest
timeout-minutes: 360 # 6 hours (GitHub Actions maximum for free tier)
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 10
- name: Install dependencies
run: |
pnpm install
pnpm rebuild better-sqlite3
chmod +x awesome
- name: Build awesome database
id: build
env:
CI: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
INCREMENTAL: ${{ github.event.inputs.incremental || 'true' }}
run: |
# Pass env vars!
CI=${CI:-false}
# Capture start time
START_TIME=$(date -u +"%Y-%m-%d %H:%M:%S UTC")
echo "start_time=$START_TIME" >> $GITHUB_OUTPUT
# Determine index mode and incremental setting
INDEX_MODE="${{ github.event.inputs.index_mode || 'full' }}"
INCREMENTAL="${{ github.event.inputs.incremental }}"
# Default to true if not specified (for scheduled runs)
if [ -z "$INCREMENTAL" ]; then
INCREMENTAL="true"
fi
echo "Index mode: $INDEX_MODE"
echo "Incremental: $INCREMENTAL"
# Build the index in non-interactive mode (350m timeout, job timeout is 360m)
timeout 350m node -e "
const db = require('./lib/database');
const dbOps = require('./lib/db-operations');
const indexer = require('./lib/indexer');
(async () => {
try {
// Initialize database
db.initialize();
// Set GitHub token if available
if (process.env.GITHUB_TOKEN) {
dbOps.setSetting('githubToken', process.env.GITHUB_TOKEN);
console.log('GitHub token configured');
} else {
console.warn('⚠️ WARNING: No GitHub token found! Rate limit will be 60/hour instead of 5000/hour');
}
// Build index with incremental flag
const incremental = process.env.INCREMENTAL === 'true';
await indexer.buildIndex(false, '${INDEX_MODE}', incremental);
// Close database
db.close();
console.log('Index built successfully');
process.exit(0);
} catch (error) {
console.error('Failed to build index:', error.message);
console.error(error.stack);
process.exit(1);
}
})();
" || {
EXIT_CODE=$?
if [ $EXIT_CODE -eq 124 ]; then
echo "❌ Index building timed out after 350 minutes"
echo "This may indicate rate limiting issues or too many lists to index"
fi
exit $EXIT_CODE
}
# Capture end time
END_TIME=$(date -u +"%Y-%m-%d %H:%M:%S UTC")
echo "end_time=$END_TIME" >> $GITHUB_OUTPUT
- name: Gather database statistics
id: stats
run: |
# Get database stats
STATS=$(node -e "
const db = require('./lib/database');
const dbOps = require('./lib/db-operations');
db.initialize();
const stats = dbOps.getIndexStats();
const dbPath = require('path').join(require('os').homedir(), '.awesome', 'awesome.db');
const fs = require('fs');
const fileSize = fs.existsSync(dbPath) ? fs.statSync(dbPath).size : 0;
const fileSizeMB = (fileSize / (1024 * 1024)).toFixed(2);
console.log(JSON.stringify({
totalLists: stats.totalLists || 0,
totalRepos: stats.totalRepositories || 0,
totalReadmes: stats.totalReadmes || 0,
sizeBytes: fileSize,
sizeMB: fileSizeMB
}));
db.close();
")
echo "Database statistics:"
echo "$STATS" | jq .
# Extract values for outputs
TOTAL_LISTS=$(echo "$STATS" | jq -r '.totalLists')
TOTAL_REPOS=$(echo "$STATS" | jq -r '.totalRepos')
TOTAL_READMES=$(echo "$STATS" | jq -r '.totalReadmes')
SIZE_MB=$(echo "$STATS" | jq -r '.sizeMB')
echo "total_lists=$TOTAL_LISTS" >> $GITHUB_OUTPUT
echo "total_repos=$TOTAL_REPOS" >> $GITHUB_OUTPUT
echo "total_readmes=$TOTAL_READMES" >> $GITHUB_OUTPUT
echo "size_mb=$SIZE_MB" >> $GITHUB_OUTPUT
- name: Prepare database artifact
run: |
# Copy database from home directory
DB_PATH="$HOME/.awesome/awesome.db"
if [ ! -f "$DB_PATH" ]; then
echo "Error: Database file not found at $DB_PATH"
exit 1
fi
# Create artifact directory
mkdir -p artifacts
# Copy database with timestamp
BUILD_DATE=$(date -u +"%Y%m%d-%H%M%S")
cp "$DB_PATH" "artifacts/awesome-${BUILD_DATE}.db"
cp "$DB_PATH" "artifacts/awesome-latest.db"
# Create metadata file
cat > artifacts/metadata.json <<EOF
{
"build_date": "$(date -u +"%Y-%m-%d %H:%M:%S UTC")",
"build_timestamp": "$(date -u +%s)",
"git_sha": "${{ github.sha }}",
"workflow_run_id": "${{ github.run_id }}",
"total_lists": ${{ steps.stats.outputs.total_lists }},
"total_repos": ${{ steps.stats.outputs.total_repos }},
"total_readmes": ${{ steps.stats.outputs.total_readmes }},
"size_mb": ${{ steps.stats.outputs.size_mb }},
"node_version": "$(node --version)",
"index_mode": "${{ github.event.inputs.index_mode || 'full' }}"
}
EOF
echo "Artifact prepared: awesome-${BUILD_DATE}.db"
ls -lh artifacts/
- name: Upload database artifact
uses: actions/upload-artifact@v4
with:
name: awesome-database-${{ github.run_id }}
path: |
artifacts/awesome-*.db
artifacts/metadata.json
retention-days: 90
compression-level: 9
- name: Create build summary
run: |
cat >> $GITHUB_STEP_SUMMARY <<EOF
# 🎉 Awesome Database Build Complete
## 📊 Statistics
| Metric | Value |
|--------|-------|
| 📚 Total Lists | ${{ steps.stats.outputs.total_lists }} |
| 📦 Total Repositories | ${{ steps.stats.outputs.total_repos }} |
| 📖 Total READMEs | ${{ steps.stats.outputs.total_readmes }} |
| 💾 Database Size | ${{ steps.stats.outputs.size_mb }} MB |
## ⏱️ Build Information
- **Started:** ${{ steps.build.outputs.start_time }}
- **Completed:** ${{ steps.build.outputs.end_time }}
- **Workflow Run:** [\#${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
- **Commit:** \`${{ github.sha }}\`
- **Index Mode:** ${{ github.event.inputs.index_mode || 'full' }}
## 📥 Download Instructions
\`\`\`bash
# Using GitHub CLI
gh run download ${{ github.run_id }} -n awesome-database-${{ github.run_id }}
# Or using our helper script
curl -sSL https://raw.githubusercontent.com/${{ github.repository }}/main/scripts/download-db.sh | bash
\`\`\`
## 🔗 Artifact Link
[Download Database Artifact](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
EOF
- name: Notify on failure
if: failure()
run: |
cat >> $GITHUB_STEP_SUMMARY <<EOF
# ❌ Database Build Failed
The automated database build encountered an error.
**Workflow Run:** [\#${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
Please check the logs for details.
EOF

View File

@@ -1,248 +0,0 @@
name: Cleanup Old Artifacts
on:
schedule:
# Run daily at 03:00 UTC (after database build)
- cron: '0 3 * * *'
workflow_dispatch: # Allow manual triggering
inputs:
retention_days:
description: 'Keep artifacts newer than X days'
required: false
default: '30'
type: string
dry_run:
description: 'Dry run (list only, do not delete)'
required: false
default: false
type: boolean
permissions:
actions: write
contents: read
jobs:
cleanup:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup GitHub CLI
run: |
# GitHub CLI is pre-installed on ubuntu-latest
gh --version
- name: List and cleanup old artifacts
env:
GH_TOKEN: ${{ github.token }}
run: |
# Configuration
RETENTION_DAYS="${{ github.event.inputs.retention_days || '30' }}"
DRY_RUN="${{ github.event.inputs.dry_run || 'false' }}"
CUTOFF_DATE=$(date -u -d "$RETENTION_DAYS days ago" +%s)
echo "🧹 Artifact Cleanup Configuration"
echo "=================================="
echo "Retention days: $RETENTION_DAYS"
echo "Cutoff date: $(date -u -d "@$CUTOFF_DATE" '+%Y-%m-%d %H:%M:%S UTC')"
echo "Dry run: $DRY_RUN"
echo ""
# Get all artifacts
echo "📦 Fetching artifacts..."
ARTIFACTS=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${{ github.repository }}/actions/artifacts?per_page=100" \
| jq -r '.artifacts[]')
if [ -z "$ARTIFACTS" ]; then
echo "No artifacts found"
exit 0
fi
# Initialize counters
TOTAL_COUNT=0
DELETE_COUNT=0
KEEP_COUNT=0
SPACE_FREED=0
# Create summary arrays
declare -a TO_DELETE
declare -a TO_KEEP
# Process each artifact
while IFS= read -r artifact; do
ID=$(echo "$artifact" | jq -r '.id')
NAME=$(echo "$artifact" | jq -r '.name')
SIZE=$(echo "$artifact" | jq -r '.size_in_bytes')
CREATED=$(echo "$artifact" | jq -r '.created_at')
EXPIRED=$(echo "$artifact" | jq -r '.expired')
# Convert created_at to timestamp
CREATED_TS=$(date -u -d "$CREATED" +%s)
TOTAL_COUNT=$((TOTAL_COUNT + 1))
# Check if artifact should be deleted
if [ "$EXPIRED" = "true" ] || [ $CREATED_TS -lt $CUTOFF_DATE ]; then
DELETE_COUNT=$((DELETE_COUNT + 1))
SPACE_FREED=$((SPACE_FREED + SIZE))
SIZE_MB=$(echo "scale=2; $SIZE / 1024 / 1024" | bc)
AGE_DAYS=$(echo "($CUTOFF_DATE - $CREATED_TS) / 86400" | bc)
TO_DELETE+=("| $NAME | $SIZE_MB MB | $(date -u -d "$CREATED" '+%Y-%m-%d') | $AGE_DAYS days old |")
if [ "$DRY_RUN" = "false" ]; then
echo "🗑️ Deleting: $NAME (ID: $ID, Size: $SIZE_MB MB, Age: $AGE_DAYS days)"
gh api \
--method DELETE \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${{ github.repository }}/actions/artifacts/$ID" \
&& echo " ✓ Deleted" || echo " ✗ Failed to delete"
else
echo "🔍 Would delete: $NAME (ID: $ID, Size: $SIZE_MB MB, Age: $AGE_DAYS days)"
fi
else
KEEP_COUNT=$((KEEP_COUNT + 1))
SIZE_MB=$(echo "scale=2; $SIZE / 1024 / 1024" | bc)
AGE_DAYS=$(echo "($(date +%s) - $CREATED_TS) / 86400" | bc)
TO_KEEP+=("| $NAME | $SIZE_MB MB | $(date -u -d "$CREATED" '+%Y-%m-%d') | $AGE_DAYS days old |")
fi
done < <(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${{ github.repository }}/actions/artifacts?per_page=100" \
| jq -c '.artifacts[]')
# Calculate space freed in MB
SPACE_FREED_MB=$(echo "scale=2; $SPACE_FREED / 1024 / 1024" | bc)
echo ""
echo "📊 Cleanup Summary"
echo "=================="
echo "Total artifacts: $TOTAL_COUNT"
echo "Deleted/Would delete: $DELETE_COUNT"
echo "Kept: $KEEP_COUNT"
echo "Space freed: $SPACE_FREED_MB MB"
# Create GitHub Actions summary
cat >> $GITHUB_STEP_SUMMARY <<EOF
# 🧹 Artifact Cleanup Report
## Configuration
- **Retention Period:** $RETENTION_DAYS days
- **Cutoff Date:** $(date -u -d "@$CUTOFF_DATE" '+%Y-%m-%d %H:%M:%S UTC')
- **Mode:** $([ "$DRY_RUN" = "true" ] && echo "🔍 Dry Run" || echo "🗑️ Delete")
## Summary
| Metric | Value |
|--------|-------|
| 📦 Total Artifacts | $TOTAL_COUNT |
| 🗑️ Deleted | $DELETE_COUNT |
| ✅ Kept | $KEEP_COUNT |
| 💾 Space Freed | $SPACE_FREED_MB MB |
EOF
# Add deleted artifacts table if any
if [ $DELETE_COUNT -gt 0 ]; then
cat >> $GITHUB_STEP_SUMMARY <<EOF
## 🗑️ Deleted Artifacts
| Name | Size | Created | Age |
|------|------|---------|-----|
EOF
printf '%s\n' "${TO_DELETE[@]}" >> $GITHUB_STEP_SUMMARY
fi
# Add kept artifacts table if any
if [ $KEEP_COUNT -gt 0 ]; then
cat >> $GITHUB_STEP_SUMMARY <<EOF
## ✅ Kept Artifacts (Recent)
| Name | Size | Created | Age |
|------|------|---------|-----|
EOF
# Show only first 10 kept artifacts
printf '%s\n' "${TO_KEEP[@]:0:10}" >> $GITHUB_STEP_SUMMARY
if [ $KEEP_COUNT -gt 10 ]; then
echo "" >> $GITHUB_STEP_SUMMARY
echo "*...and $((KEEP_COUNT - 10)) more*" >> $GITHUB_STEP_SUMMARY
fi
fi
cat >> $GITHUB_STEP_SUMMARY <<EOF
## 📋 Next Scheduled Run
This workflow runs daily at 03:00 UTC to maintain artifact storage.
**Manual trigger:** You can also run this workflow manually from the Actions tab with custom retention settings.
EOF
- name: Cleanup workflow runs
if: github.event.inputs.dry_run != 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
echo ""
echo "🧹 Cleaning up old workflow runs..."
# Keep only last 50 workflow runs
RUNS_TO_DELETE=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${{ github.repository }}/actions/runs?per_page=100" \
| jq -r '.workflow_runs[50:] | .[].id')
if [ -z "$RUNS_TO_DELETE" ]; then
echo "No old workflow runs to delete"
else
DELETE_COUNT=0
for RUN_ID in $RUNS_TO_DELETE; do
# Only delete runs older than 30 days
RUN_DATE=$(gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${{ github.repository }}/actions/runs/$RUN_ID" \
| jq -r '.created_at')
RUN_TS=$(date -u -d "$RUN_DATE" +%s)
CUTOFF=$(date -u -d "30 days ago" +%s)
if [ $RUN_TS -lt $CUTOFF ]; then
echo "Deleting workflow run: $RUN_ID"
gh api \
--method DELETE \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${{ github.repository }}/actions/runs/$RUN_ID" \
&& DELETE_COUNT=$((DELETE_COUNT + 1)) || echo "Failed to delete run $RUN_ID"
fi
done
echo "Deleted $DELETE_COUNT old workflow runs"
fi
- name: Report failures
if: failure()
run: |
cat >> $GITHUB_STEP_SUMMARY <<EOF
# ❌ Cleanup Failed
The artifact cleanup workflow encountered an error.
Please check the logs for details.
EOF