Something went wrong. Try again.
Small repo for scanning Tangled for repos with github workflows, but no tangled workflows, and whether the workflows currently can be converted with https://github.com/43081j/tangleflow or not.
Something went wrong. Try again.
2.5 kB · 88 lines
TypeScript
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889import type { Repo } from './discover.ts';import { readRepoFile, listGithubWorkflowFiles } from './tangled.ts';import { readFileSync } from 'node:fs';import { findPackageJSON } from 'node:module';import { convertWorkflowToTangled } from 'tangleflow';import { parse } from 'yaml';
/** * The conversion outcome of one workflow file. `owner` is the handle of the * account that owns the repo. */export type Result = { owner: string; repo: string; file: string; error: string | null;};
/** * One scan run. Results from different tangleflow versions are not * comparable. `date` is the UTC day of the scan. */export type Scan = { tangleflowVersion: string; date: string; results: Result[];};
/** * Try converting every GitHub workflow in `repo` and record whether each * one succeeded. */async function scanRepo(repo: Repo): Promise<Result[]> { const files = await listGithubWorkflowFiles(repo.repoDid); return Promise.all( files.map(async (file) => { const yamlText = await readRepoFile(repo.repoDid, file); let error: string | null = null;
try { const workflow = parse(yamlText); convertWorkflowToTangled(workflow); } catch (err) { error = err instanceof Error ? err.message : String(err); }
return { owner: repo.handle, repo: `${repo.handle}/${repo.name}`, file, error, }; }), );}
/** * Scan every repo and stamp the results with the tangleflow version and the * UTC day. A repo the mirror cannot read is skipped with a warning. */export async function scanRepos(repos: Repo[]): Promise<Scan> { const date = new Date().toISOString().slice(0, 10);
const path = findPackageJSON('tangleflow', import.meta.url); if (!path) throw new Error('tangleflow package.json not found'); const pkg = JSON.parse(readFileSync(path, 'utf8')) as { version: string };
const results: Result[] = []; let skipped = 0; for (const repo of repos) { try { results.push(...(await scanRepo(repo))); } catch (err) { skipped++; console.warn(`skipping ${repo.handle}/${repo.name}: ${String(err)}`); } } const failed = results.filter((result) => result.error).length; console.log( `${repos.length - skipped} of ${repos.length} repos scanned; ` + `${results.length} workflow files, ${failed} failed`, ); return { tangleflowVersion: pkg.version, date, results, };}