Add badges for repo status - #42
Conversation
These badges are meant to be used by other BioJulia repos to signal the status of the repo.
|
Here's the code used to generate the badges (I've used Claude to generate the code), just so that we can redo it in case we want to update the badges. // Generates the BioJulia status badges with the helix logo inline.
//
// badge-maker's public API (`makeBadge` from 'badge-maker') rejects `logoWidth`,
// and defaults the logo box to 14x14. The helix is ~2.66:1, so in a square box
// it would letterbox down to ~5px tall. We import the internal renderer directly
// to pass an aspect-correct logoWidth instead.
import { readFileSync, writeFileSync } from 'node:fs'
import makeBadge from '/usr/lib/node_modules/badge-maker/lib/make-badge.js'
const LOGO_HEIGHT = 14 // badge-maker's fixed logo height
const logoSvg = readFileSync(new URL('./assets/biojulia-helix.svg', import.meta.url), 'utf8')
const [, w, h] = logoSvg.match(/viewBox="0 0 ([\d.]+) ([\d.]+)"/)
const [vbW, vbH] = [Number(w), Number(h)]
const logoWidth = Math.round(LOGO_HEIGHT * (vbW / vbH))
// The helix drawing itself: the source file's root <svg> wrapper and XML
// declaration stripped, ids dropped so several badges can coexist in one
// document (nothing in the logo references them via url(#...)), whitespace
// collapsed to match badge-maker's own output.
const logoBody = logoSvg
.replace(/<\?xml[^>]*\?>/, '')
.replace(/^\s*<svg\b[^>]*>/, '')
.replace(/<\/svg>\s*$/, '')
.replace(/\s+id="[^"]*"/g, '')
.replace(/\s+/g, ' ') // the source puts each attribute on its own line
.replace(/>\s+</g, '><')
.trim()
// badge-maker can only embed a logo as a data URI. Swap that <image> for the
// logo's own elements wrapped in a <g transform>, which renders in contexts
// where data URIs are stripped or unsupported. A nested <svg> would express
// the same geometry more directly, but sanitizers (GitHub's among them) drop
// nested <svg> nodes, so the transform is computed by hand instead: a uniform
// scale, centered in the box, reproducing preserveAspectRatio="xMidYMid meet".
function inlineLogo(svg) {
const replaced = svg.replace(
/<image\s+x="([\d.]+)"\s+y="([\d.]+)"\s+width="([\d.]+)"\s+height="([\d.]+)"\s+href="data:[^"]*"\s*\/>/,
(_, x, y, width, height) => {
const scale = Math.min(width / vbW, height / vbH)
const tx = Number(x) + (width - vbW * scale) / 2
const ty = Number(y) + (height - vbH * scale) / 2
const round = n => +n.toFixed(4)
return `<g transform="translate(${round(tx)},${round(ty)}) scale(${round(scale)})">${logoBody}</g>`
},
)
if (replaced === svg) throw new Error('logo <image> element not found — badge-maker output changed?')
if (replaced.includes('data:')) throw new Error('a data URI survived inlining')
return replaced
}
// Shields' named colors, so the badges read the same way as every other
// status badge in a README.
const badges = [
{ message: 'maintained', color: 'brightgreen', file: 'biojulia-maintained.svg' },
{
message: 'functional; maintainer needed',
color: 'yellow',
file: 'biojulia-functional-maintainer-needed.svg',
},
{ message: 'deprecated', color: 'red', file: 'biojulia-deprecated.svg' },
]
for (const { message, color, file } of badges) {
const svg = inlineLogo(
makeBadge({
label: 'BioJulia',
message,
labelColor: '#555',
color,
style: 'flat',
logo: 'data:image/svg+xml;base64,PLACEHOLDER', // swapped out by inlineLogo
logoWidth,
}),
)
writeFileSync(new URL(`./${file}`, import.meta.url), svg + '\n')
console.log(`${file.padEnd(34)} ${svg.match(/width="(\d+)"/)[1]}px ${svg.length}b`)
} |
|
Is there a reason not to use shields.io. I think they have a way we can use custom svgs for the icons... |
|
It's possible, but the custom icon is inserted as a binary blob in the url, which makes it long and ugly. That said, whichever solution works for me. |
|
Here's the markdown (it became weird if I quote for some reason).  |
|
Oh no - I agree that's gross. I thought you could just use a link to the asset. I like the larger icons in your SVG icons better anyway. We should also come up with and codify
|
Good points. I guess we can write this down in https://github.com/BioJulia/Contributing. And maybe refer to that from relevant pages on biojulia.dev and perhaps https://github.com/BioJulia/BioJuliaTemplate.jl. Here are my thoughts. The wording etc. can be improved. "Maintained": At least one person consider themselves an active maintainer. A user can expect answers to opened issues/PRs. "Functional; Maintainer needed": The package is expected to work, but we are searching for a maintainer. A user cannot be sure that issues/PRs will be answered, in particular not more technical ones. If it's not possible to reach any maintainer for ~1 month, the package status can be changed to this. "Deprecated": The package is no longer modern, either because it doesn't work on recent Julia releases or because it has been superseded by other Julia packages. If it's not possible to reach any maintainer for ~1 month, the package status can be changed to this. The repo must be in BioJulia, JuliaHealth, EcoJulia (or other relevant GitHub organizations, such as lab orgs, we should include an exhaustive list) to be eligible for a badge. This is to ensure that we can change the badge to another one in case the maintainer is unreachable for whatever reason. This is always a bit tricky, because it's impossible to encode exact rules that always work. But the community should try to work it out given the descriptions above. If there are disagreements, a decision taken by the admins of the organization (together with BioJulia admins if outside) should be followed. |
|
Agree with this - we can work out specific language in a PR to Contributing. Regarding (3), I agree it's difficult, and in the absence of specific conflict, I think we can keep it fairly vague at first. If there's no response from a maintainer for a month or more, and there's a compelling reason, we can change it. If there's no response for 6 months or more, we don't even need a compelling reason. If the maintainer pops back up, we can always change it back. |
|
It doesn't seem like anything here should cause the build to fail. But in any case, I think we're going to re-work this back to a Franklin/Xranklin site, the failures look like a node/vitepress problem |
These badges are meant to be used by other BioJulia repos to signal the status of the repo. See #41.
I've just added them to a
badgesfolder here. But if there's any better place to host that gives a better URL to link to, I'm happy to upload them somewhere else.