clear_github_cache.mjs (958B)
1 /** 2 * @license 3 * Copyright 2025 Google Inc. 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 import {exec} from 'child_process'; 8 import {promisify} from 'util'; 9 10 const execAsync = promisify(exec); 11 12 const prefix = process.argv[2]; 13 if (!prefix) { 14 throw new Error('Prefix must be specified'); 15 } 16 try { 17 await execAsync('gh --help'); 18 } catch { 19 console.log('Github CLI not set up'); 20 process.exit(0); 21 } 22 23 try { 24 if (prefix === 'all') { 25 execAsync(`gh cache delete --all`); 26 } else { 27 const c = await execAsync('gh cache list --limit=10000'); 28 const cacheKeys = c.stdout 29 .split('\n') 30 .map(line => { 31 return line.replaceAll(/\s+/g, ' ').split(' ')[1]; 32 }) 33 .filter(line => { 34 return line && line.startsWith(prefix); 35 }); 36 37 Promise.all( 38 cacheKeys.map(cacheKey => { 39 return execAsync(`gh cache delete ${cacheKey}`); 40 }), 41 ); 42 } 43 } catch (error) { 44 console.log(error); 45 process.exit(0); 46 }