From 5f13a98397e647a9b49c979830e5b3c7e86a4a8b Mon Sep 17 00:00:00 2001 From: Ivan Matveev Date: Sun, 31 May 2026 14:29:58 +0200 Subject: [PATCH] ci: add dynamic Skylos badge --- .changeset/skylos-badge.md | 5 +++++ .github/badges/skylos.json | 6 ++++++ .github/workflows/ci.yml | 29 +++++++++++++++++++++++++++++ README.md | 2 ++ scripts/update-skylos-badge.mjs | 27 +++++++++++++++++++++++++++ 5 files changed, 69 insertions(+) create mode 100644 .changeset/skylos-badge.md create mode 100644 .github/badges/skylos.json create mode 100644 scripts/update-skylos-badge.mjs diff --git a/.changeset/skylos-badge.md b/.changeset/skylos-badge.md new file mode 100644 index 0000000..3c0286a --- /dev/null +++ b/.changeset/skylos-badge.md @@ -0,0 +1,5 @@ +--- +"@vndv/pi-codegraph": patch +--- + +Add an automatically updated Skylos grade badge to the README. diff --git a/.github/badges/skylos.json b/.github/badges/skylos.json new file mode 100644 index 0000000..ce53aa5 --- /dev/null +++ b/.github/badges/skylos.json @@ -0,0 +1,6 @@ +{ + "schemaVersion": 1, + "label": "Skylos", + "message": "A+ (99)", + "color": "brightgreen" +} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0c40ab6..b8abbca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,4 +26,33 @@ jobs: - run: npm ci --ignore-scripts - run: npm run ci - run: pip install skylos + - run: skylos . -a --format json --output skylos-results.json - run: skylos . --gate + - run: node scripts/update-skylos-badge.mjs skylos-results.json + + skylos-badge: + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + needs: test + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd + with: + fetch-depth: 0 + - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 + with: + python-version: "3.11" + - run: pip install skylos + - run: skylos . -a --format json --output skylos-results.json + - run: node scripts/update-skylos-badge.mjs skylos-results.json + - run: | + if git diff --quiet -- .github/badges/skylos.json; then + echo "Skylos badge already up to date." + exit 0 + fi + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add .github/badges/skylos.json + git commit -m "docs: update Skylos badge" + git push diff --git a/README.md b/README.md index bcf6e9b..60b96cc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # pi-codegraph ### CodeGraph tools for pi +[![Skylos Grade](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/vndv/pi-codegraph/main/.github/badges/skylos.json)](https://github.com/duriantaco/skylos) + [Install](#install) · [Usage](#usage) · [How it works](#how-it-works) Ask pi structural questions about your codebase without falling back to slow grep/read loops. diff --git a/scripts/update-skylos-badge.mjs b/scripts/update-skylos-badge.mjs new file mode 100644 index 0000000..ce14908 --- /dev/null +++ b/scripts/update-skylos-badge.mjs @@ -0,0 +1,27 @@ +import { readFile, writeFile } from 'node:fs/promises'; + +const inputPath = process.argv[2]; + +if (!inputPath) { + console.error('Usage: node scripts/update-skylos-badge.mjs '); + process.exit(1); +} + +const results = JSON.parse(await readFile(inputPath, 'utf8')); +const overall = results.grade?.overall; + +if (!overall || typeof overall.score !== 'number' || typeof overall.letter !== 'string') { + console.error('Skylos results are missing grade.overall.score or grade.overall.letter.'); + process.exit(1); +} + +const score = Math.round(overall.score); +const color = score >= 90 ? 'brightgreen' : score >= 80 ? 'green' : score >= 70 ? 'yellow' : score >= 60 ? 'orange' : 'red'; +const badge = { + schemaVersion: 1, + label: 'Skylos', + message: `${overall.letter} (${score})`, + color, +}; + +await writeFile(new URL('../.github/badges/skylos.json', import.meta.url), `${JSON.stringify(badge, null, 2)}\n`);