Skip to content
Merged
Show file tree
Hide file tree
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
45 changes: 45 additions & 0 deletions .github/scripts/cleanup-test-indexes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const { algoliasearch } = require('algoliasearch');

const BATCH_SIZE = 20;

async function main() {
const client = algoliasearch(process.env.APP_ID, process.env.API_KEY);

const { items } = await client.listIndices();
const names = items.map((i) => i.name).filter((n) => n.includes('sf_phpunit_'));

if (names.length === 0) {
console.log('Nothing to delete.');
return;
}

console.log(`Deleting ${names.length} indexes in batches of ${BATCH_SIZE}...`);

const tasks = [];
for (let i = 0; i < names.length; i += BATCH_SIZE) {
const batch = names.slice(i, i + BATCH_SIZE);
const batchTasks = await Promise.all(
batch.map(async (name) => {
const { taskID } = await client.deleteIndex({ indexName: name });
return { name, taskID };
})
);
tasks.push(...batchTasks);
console.log(` requested ${Math.min(i + BATCH_SIZE, names.length)}/${names.length}`);
}

console.log('Waiting for all tasks to complete...');
await Promise.all(
tasks.map(async ({ name, taskID }) => {
await client.waitForTask({ indexName: name, taskID });
console.log(` confirmed ${name}`);
})
);

console.log('All deletes confirmed.');
}

main().catch((err) => {
console.error(err);
process.exit(1);
});
10 changes: 10 additions & 0 deletions .github/scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "search-bundle-ci-scripts",
"private": true,
"dependencies": {
"algoliasearch": "^5"
},
"devDependencies": {
"@types/node": "^24"
}
}
21 changes: 21 additions & 0 deletions .github/workflows/cleanup-test-indexes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Cleanup test indexes

on:
schedule:
- cron: '0 3 * * 0'
workflow_dispatch:

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '24'
- run: npm install algoliasearch@^5 --no-save
- name: Delete sf_phpunit_* indexes
env:
APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
run: node .github/scripts/cleanup-test-indexes.js
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ clover.xml
/tests/QualityTools/composer.lock
.phpunit.result.cache
phpunit.xml.dist.bak
/.github/scripts/node_modules/
/.github/scripts/package-lock.json
Loading