fix: github workflow

This commit is contained in:
valknarness
2025-10-26 14:00:45 +01:00
parent c73a14510b
commit 10910d8537
2 changed files with 97 additions and 83 deletions

View File

@@ -59,6 +59,8 @@ jobs:
- name: Build awesome database - name: Build awesome database
id: build id: build
env:
CI: true
run: | run: |
# Capture start time # Capture start time
START_TIME=$(date -u +"%Y-%m-%d %H:%M:%S UTC") START_TIME=$(date -u +"%Y-%m-%d %H:%M:%S UTC")
@@ -68,43 +70,27 @@ jobs:
INDEX_MODE="${{ github.event.inputs.index_mode || 'full' }}" INDEX_MODE="${{ github.event.inputs.index_mode || 'full' }}"
echo "Index mode: $INDEX_MODE" echo "Index mode: $INDEX_MODE"
# Build the index with automated selection # Build the index in non-interactive mode
if [ "$INDEX_MODE" = "sample" ]; then timeout 150m node -e "
# For sample mode, we'll need to modify the script to accept input const indexer = require('./lib/indexer');
echo "Building sample index (10 lists)..." (async () => {
timeout 150m node -e " try {
const indexer = require('./lib/indexer'); await indexer.buildIndex(false, '${INDEX_MODE}');
(async () => { console.log('Index built successfully');
try { process.exit(0);
// Simulate user choosing 'sample' option } catch (error) {
process.stdin.push('sample\n'); console.error('Failed to build index:', error.message);
await indexer.buildIndex(false); console.error(error.stack);
console.log('Sample index built successfully'); process.exit(1);
process.exit(0); }
} catch (error) { })();
console.error('Failed to build index:', error.message); " || {
process.exit(1); EXIT_CODE=$?
} if [ $EXIT_CODE -eq 124 ]; then
})(); echo "Index building timed out after 150 minutes"
" || echo "Index building completed with timeout" fi
else exit $EXIT_CODE
echo "Building full index..." }
timeout 150m node -e "
const indexer = require('./lib/indexer');
(async () => {
try {
// Simulate user choosing 'full' option
process.stdin.push('full\n');
await indexer.buildIndex(false);
console.log('Full index built successfully');
process.exit(0);
} catch (error) {
console.error('Failed to build index:', error.message);
process.exit(1);
}
})();
" || echo "Index building completed with timeout"
fi
# Capture end time # Capture end time
END_TIME=$(date -u +"%Y-%m-%d %H:%M:%S UTC") END_TIME=$(date -u +"%Y-%m-%d %H:%M:%S UTC")

View File

@@ -89,29 +89,42 @@ function isAwesomeList(url, name, description) {
} }
// Build the complete index // Build the complete index
async function buildIndex(force = false) { async function buildIndex(force = false, mode = null) {
console.clear(); console.clear();
console.log(purpleGold('\n🚀 AWESOME INDEX BUILDER 🚀\n')); console.log(purpleGold('\n🚀 AWESOME INDEX BUILDER 🚀\n'));
// Check if running in CI/non-interactive mode
const isNonInteractive = process.env.CI === 'true' || mode !== null;
if (force) { if (force) {
const { confirm } = await inquirer.prompt([ if (isNonInteractive) {
{ // Clear index data without confirmation in CI
type: 'confirm', console.log(chalk.gray('\nClearing existing index...'));
name: 'confirm', const dbInstance = require('./database').getDb();
message: chalk.yellow('⚠️ Force rebuild will clear all indexed data (bookmarks will be preserved). Continue?'), dbInstance.exec('DELETE FROM readmes');
default: false dbInstance.exec('DELETE FROM repositories');
} dbInstance.exec('DELETE FROM awesome_lists');
]); console.log(chalk.green('✓ Index cleared\n'));
} else {
const { confirm } = await inquirer.prompt([
{
type: 'confirm',
name: 'confirm',
message: chalk.yellow('⚠️ Force rebuild will clear all indexed data (bookmarks will be preserved). Continue?'),
default: false
}
]);
if (!confirm) return; if (!confirm) return;
// Clear index data (keep bookmarks) // Clear index data (keep bookmarks)
console.log(chalk.gray('\nClearing existing index...')); console.log(chalk.gray('\nClearing existing index...'));
const dbInstance = require('./database').getDb(); const dbInstance = require('./database').getDb();
dbInstance.exec('DELETE FROM readmes'); dbInstance.exec('DELETE FROM readmes');
dbInstance.exec('DELETE FROM repositories'); dbInstance.exec('DELETE FROM repositories');
dbInstance.exec('DELETE FROM awesome_lists'); dbInstance.exec('DELETE FROM awesome_lists');
console.log(chalk.green('✓ Index cleared\n')); console.log(chalk.green('✓ Index cleared\n'));
}
} }
// Fetch main awesome list // Fetch main awesome list
@@ -132,46 +145,61 @@ async function buildIndex(force = false) {
const awesomeLists = parseMarkdownLinks(mainReadme); const awesomeLists = parseMarkdownLinks(mainReadme);
console.log(chalk.green(`✓ Found ${awesomeLists.length} awesome lists!\n`)); console.log(chalk.green(`✓ Found ${awesomeLists.length} awesome lists!\n`));
// Ask user what to index let indexChoice = mode;
const { indexChoice } = await inquirer.prompt([
{ // Ask user what to index (only if interactive)
type: 'list', if (!isNonInteractive) {
name: 'indexChoice', const result = await inquirer.prompt([
message: 'What would you like to index?', {
choices: [ type: 'list',
{ name: '🎯 Index everything (recommended for first run)', value: 'full' }, name: 'indexChoice',
{ name: '📋 Index lists only (metadata, no READMEs)', value: 'lists' }, message: 'What would you like to index?',
{ name: '🎲 Index a random sample (10 lists)', value: 'sample' }, choices: [
{ name: '🔍 Select specific categories', value: 'select' }, { name: '🎯 Index everything (recommended for first run)', value: 'full' },
{ name: '← Back', value: 'cancel' } { name: '📋 Index lists only (metadata, no READMEs)', value: 'lists' },
] { name: '🎲 Index a random sample (10 lists)', value: 'sample' },
} { name: '🔍 Select specific categories', value: 'select' },
]); { name: '← Back', value: 'cancel' }
]
}
]);
indexChoice = result.indexChoice;
}
if (indexChoice === 'cancel') return; if (indexChoice === 'cancel') return;
// Default to 'full' if no mode specified
if (!indexChoice) indexChoice = 'full';
console.log(chalk.cyan(`Index mode: ${indexChoice}\n`));
let listsToIndex = awesomeLists; let listsToIndex = awesomeLists;
if (indexChoice === 'sample') { if (indexChoice === 'sample') {
listsToIndex = awesomeLists.sort(() => 0.5 - Math.random()).slice(0, 10); listsToIndex = awesomeLists.sort(() => 0.5 - Math.random()).slice(0, 10);
} else if (indexChoice === 'select') { } else if (indexChoice === 'select') {
const categories = [...new Set(awesomeLists.map(l => l.category).filter(Boolean))]; if (isNonInteractive) {
const { selectedCategories } = await inquirer.prompt([ console.log(chalk.yellow('Select mode not available in non-interactive mode, using full'));
{ indexChoice = 'full';
type: 'checkbox', } else {
name: 'selectedCategories', const categories = [...new Set(awesomeLists.map(l => l.category).filter(Boolean))];
message: 'Select categories to index:', const { selectedCategories } = await inquirer.prompt([
choices: categories, {
pageSize: 15 type: 'checkbox',
name: 'selectedCategories',
message: 'Select categories to index:',
choices: categories,
pageSize: 15
}
]);
if (selectedCategories.length === 0) {
console.log(chalk.yellow('No categories selected'));
return;
} }
]);
if (selectedCategories.length === 0) { listsToIndex = awesomeLists.filter(l => selectedCategories.includes(l.category));
console.log(chalk.yellow('No categories selected'));
return;
} }
listsToIndex = awesomeLists.filter(l => selectedCategories.includes(l.category));
} }
console.log(pinkPurple(`\n✨ Starting index of ${listsToIndex.length} awesome lists ✨\n`)); console.log(pinkPurple(`\n✨ Starting index of ${listsToIndex.length} awesome lists ✨\n`));