From 509795ab826cbccb13c7528a3172abf5f1970742 Mon Sep 17 00:00:00 2001 From: valknarness Date: Sun, 26 Oct 2025 14:05:21 +0100 Subject: [PATCH] Fix workflow database initialization and error handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Initialize database inside indexer process to ensure connection exists - Configure GitHub token in same process as indexer - Make indexer throw errors instead of returning early for CI failure detection - Remove duplicate token configuration step - Pass GITHUB_TOKEN as environment variable to build step 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .github/workflows/build-database.yml | 31 ++++++++++++++++------------ lib/indexer.js | 2 +- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build-database.yml b/.github/workflows/build-database.yml index 4969754..e30d20c 100644 --- a/.github/workflows/build-database.yml +++ b/.github/workflows/build-database.yml @@ -42,25 +42,13 @@ jobs: run: | pnpm install pnpm rebuild better-sqlite3 - - - name: Configure GitHub token for API access - run: | chmod +x awesome - # Set GitHub token for higher rate limits (5000/hour vs 60/hour) - export GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}" - node -e " - const db = require('./lib/database'); - const dbOps = require('./lib/db-operations'); - db.initialize(); - dbOps.setSetting('githubToken', process.env.GITHUB_TOKEN); - db.close(); - console.log('GitHub token configured'); - " - name: Build awesome database id: build env: CI: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | # Capture start time START_TIME=$(date -u +"%Y-%m-%d %H:%M:%S UTC") @@ -72,10 +60,27 @@ jobs: # Build the index in non-interactive mode timeout 150m 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'); + } + + // Build index await indexer.buildIndex(false, '${INDEX_MODE}'); + + // Close database + db.close(); + console.log('Index built successfully'); process.exit(0); } catch (error) { diff --git a/lib/indexer.js b/lib/indexer.js index f198d75..b91b1e2 100644 --- a/lib/indexer.js +++ b/lib/indexer.js @@ -137,7 +137,7 @@ async function buildIndex(force = false, mode = null) { } catch (error) { spinner.fail(chalk.red('✗ Failed to fetch main index')); console.error(chalk.red(error.message)); - return; + throw error; // Throw instead of return so CI fails properly } // Parse links from main index