Skip to content

Commit

Permalink
Complete Released Packages (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
leordev authored Oct 18, 2024
1 parent 01b4523 commit 86acb3c
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 24 deletions.
35 changes: 35 additions & 0 deletions projects-dashboard/src/components/LanguageIcon.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
import type { Language } from "../content/config";
type Props = {
language: Language;
};
const { language } = Astro.props;
const iconMap = {
javascript: { icon: "js", color: "#c9af00" },
typescript: { icon: "ts", color: "#3178c6" },
kotlin: { icon: "kt", color: "#6b47d2" },
swift: { icon: "swift", color: "#f05138" },
rust: { icon: "rs", color: "#dea584" },
go: { icon: "go", color: "#00ADD8" },
java: { icon: "java", color: "#b07219" },
python: { icon: "py", color: "#3572A5" },
};
---

<div class="language-icon" style={{ backgroundColor: iconMap[language].color }}>
{iconMap[language].icon}
</div>

<style>
.language-icon {
display: inline-block;
padding: 0.2em 0.5em;
font-size: 0.6em;
background-color: lightgray;
color: white;
margin-left: 0.2em;
}
</style>
4 changes: 4 additions & 0 deletions projects-dashboard/src/components/ProjectDetails.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
import type { CollectionEntry } from 'astro:content';
import ProjectBadge from './ProjectBadge.astro';
import ProjectDetailsPackages from './ProjectDetailsPackages.astro';
type Props = CollectionEntry<'project'>['data'];
const { title, description, repo, ciChecks, licenses, securityScans, scoreCards, sastChecks, tests, packages } = Astro.props;
Expand Down Expand Up @@ -39,6 +42,7 @@ const { title, description, repo, ciChecks, licenses, securityScans, scoreCards,
{tests.map(test => <ProjectBadge repo={repo} badge={test} />)}
</div>}
</div>
{packages && packages.length > 0 && <ProjectDetailsPackages packages={packages} repo={repo} />}
</div>

<style>
Expand Down
100 changes: 100 additions & 0 deletions projects-dashboard/src/components/ProjectDetailsPackages.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
import type { CollectionEntry } from "astro:content";
import LanguageIcon from "./LanguageIcon.astro";
import ProjectBadge from "./ProjectBadge.astro";
type Props = {
packages: NonNullable<CollectionEntry<"project">["data"]["packages"]>;
repo: CollectionEntry<"project">["data"]["repo"];
};
const { packages, repo } = Astro.props;
---

<div class="project-details-packages">
<table>
<thead>
<tr>
<th class="package-name-col">Released Packages</th>
<th class="latest-release-col">Latest Release</th>
<th class="artifacts-col">Artifacts</th>
</tr>
</thead>
<tbody>
{
packages.map((pkg) => (
<tr>
<td class="package-name-col">
<a
href={`https://github.com/${repo.owner}/${repo.name}${pkg.repoPath ? `/tree/main/${pkg.repoPath}` : ""}`}
target="_blank"
>
{pkg.packageName}
</a>
<LanguageIcon language={pkg.language} />
</td>
<td class="latest-release-col">
<ProjectBadge
repo={repo}
badge={{
type: "github-tag",
value: pkg.ghTagFilter,
}}
/>
</td>
<td class="artifacts-col">
{pkg.artifacts.map((artifact) => (
<ProjectBadge
repo={repo}
badge={{ type: artifact.type, value: artifact.value }}
/>
))}
</td>
</tr>
))
}
</tbody>
</table>
</div>

<style>
.project-details-packages {
margin-top: 1.5em;
font-size: 0.8em;
border-left: 4px solid #999;
padding: 0 0;
min-height: 96px;
}

.project-details-packages table {
border-spacing: 1em 0;
}

.project-details-packages td {
vertical-align: top;
text-align: left;
padding-top: 0.5em;
}

.project-details-packages th {
font-size: 1em;
}

.package-name-col {
min-width: 200px;
width: 20%;
}

.latest-release-col {
min-width: 200px;
width: 20%;
}

.artifacts-col {
width: auto;
display: flex;
flex-wrap: wrap;
gap: 0.2em 0.5em;
}
</style>
28 changes: 18 additions & 10 deletions projects-dashboard/src/content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const languageSchema = z.enum([

export type Language = z.infer<typeof languageSchema>;

const artifactTypeSchema = z.enum(["npm", "maven", "pip", "reference-docs"]);
const artifactTypeSchema = z.enum(["npm", "maven", "reference-docs"]);

export type ArtifactType = z.infer<typeof artifactTypeSchema>;

Expand All @@ -36,18 +36,26 @@ const packageSchema = z.object({
repoPath: z.string().optional(),
language: languageSchema,
artifacts: z.array(artifactSchema),
ghTagFilter: z.string().optional(),
});

const badgeTypeSchema = z.enum([
"github-actions",
"github-license",
"github-tag",
"fossa-license",
"fossa-security",
"ossf",
"codecov",
"tbd-vectors",
"npm",
"maven",
"reference-docs",
]);

export type BadgeType = z.infer<typeof badgeTypeSchema>;
const badgeSchema = z.object({
type: z.enum([
"github-actions",
"github-license",
"fossa-license",
"fossa-security",
"ossf",
"codecov",
"tbd-vectors",
]),
type: badgeTypeSchema,
label: z.string().optional(),
value: z.string().optional(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ tests:
- type: "codecov"
packages:
- packageName: "xyz.block.tbdex"
repoPath: "packages/common"
repoPath: "bound/kt"
language: "kotlin"
artifacts:
- type: "maven"
value: "xyz.block.tbdex"
value: "xyz.block/tbdex"
- type: "reference-docs"
value: "https://tbd54566975.github.io/tbdex-rs/kt/v4.0.0/" # TODO: get version dynamically
---
12 changes: 4 additions & 8 deletions projects-dashboard/src/content/project/TBD54566975_web5-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ packages:
- packageName: "@web5/common"
repoPath: "packages/common"
language: "typescript"
ghTagFilter: "@web5/common@*"
artifacts:
- type: "npm"
value: "@web5/common"
- packageName: "@web5/credentials"
repoPath: "packages/credentials"
language: "typescript"
ghTagFilter: "@web5/credentials@*"
artifacts:
- type: "npm"
value: "@web5/credentials"
Expand All @@ -43,6 +45,7 @@ packages:
- packageName: "@web5/crypto"
repoPath: "packages/crypto"
language: "typescript"
ghTagFilter: "@web5/crypto@*"
artifacts:
- type: "npm"
value: "@web5/crypto"
Expand All @@ -51,14 +54,7 @@ packages:
- packageName: "@web5/dids"
repoPath: "packages/dids"
language: "typescript"
artifacts:
- type: "npm"
value: "@web5/dids"
- type: "reference-docs"
value: "https://tbd54566975.github.io/web5-js/modules/_web5_dids.html"
- packageName: "@web5/dids"
repoPath: "packages/dids"
language: "typescript"
ghTagFilter: "@web5/dids@*"
artifacts:
- type: "npm"
value: "@web5/dids"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,22 @@ sastChecks:
value: "codeql.yml"
tests:
- type: "codecov"
packages:
- packageName: "java-kotlin-maven-example-api"
repoPath: "api"
language: "java"
artifacts:
- type: "maven"
value: "xyz.block/java-kotlin-maven-example-api"
- packageName: "java-kotlin-maven-example-impl"
repoPath: "impl"
language: "java"
artifacts:
- type: "maven"
value: "xyz.block/java-kotlin-maven-example-impl"
- packageName: "java-kotlin-maven-example-parent"
language: "java"
artifacts:
- type: "maven"
value: "xyz.block/java-kotlin-maven-example-parent"
---
55 changes: 51 additions & 4 deletions projects-dashboard/src/lib/badge.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { BadgeType } from "../content/config";

interface Repo {
owner: string;
name: string;
Expand All @@ -13,8 +15,8 @@ function getDefaultBadgeSource(

function getGithubActionsBadge(
repo: Repo,
value: string,
label: string
value = "ci.yml",
label = "ci"
): [string, string] {
const badgeSrc = `https://img.shields.io/github/actions/workflow/status/${repo.owner}/${repo.name}/${value}?style=flat-square&branch=main&logo=github&label=${label}&logoColor=FFFFFF`;
const href = `https://github.com/${repo.owner}/${repo.name}/actions/workflows/${value}`;
Expand All @@ -27,6 +29,15 @@ function getGithubLicenseBadge(repo: Repo): [string, string] {
return [badgeSrc, href];
}

function getGithubTagBadge(repo: Repo, value?: string): [string, string] {
let badgeSrc = `https://img.shields.io/github/v/release/${repo.owner}/${repo.name}?logo=github&label=tag&style=flat-square&color=4c1`;
if (value) {
badgeSrc += `&filter=${value}`;
}
const href = `https://github.com/${repo.owner}/${repo.name}/releases`;
return [badgeSrc, href];
}

function getFossaBadge(repo: Repo, issueType: string): [string, string] {
const badgeSrc = `https://app.fossa.com/api/projects/custom%2B588%2Fgithub.com%2F${repo.owner}%2F${repo.name}.svg?type=shield&issueType=${issueType}`;
const href = `https://app.fossa.com/projects/custom%2B588%2Fgithub.com%2F${repo.owner}%2F${repo.name}?ref=badge_shield&issueType=${issueType}`;
Expand All @@ -51,17 +62,47 @@ function getTbdVectorsBadge(repo: Repo): [string, string] {
return [badgeSrc, href];
}

function getNpmBadge(value?: string): [string, string] {
if (!value) {
throw new Error("NPM package artifact value is required for badge");
}
const badgeSrc = `https://img.shields.io/npm/v/${value}.svg?style=flat-square&logo=npm&label=npm ${value}&logoColor=FFFFFF&color=4c1`;
const href = `https://www.npmjs.com/package/${value}`;
return [badgeSrc, href];
}

function getMavenBadge(value?: string): [string, string] {
if (!value) {
throw new Error("Maven package artifact value is required for badge");
}
const artifactName = value.split("/")[1];
const badgeSrc = `https://img.shields.io/maven-central/v/${value}?color=b07219&label=mvn ${artifactName}&logo=apachemaven&style=flat-square`
const href = `https://central.sonatype.com/artifact/${value}`;
return [badgeSrc, href];
}

function getReferenceDocsBadge(value?: string): [string, string] {
if (!value) {
throw new Error("Reference docs URL is required for badge");
}
const badgeSrc = `https://img.shields.io/badge/API Reference Docs-purple?style=flat-square`;
const href = value;
return [badgeSrc, href];
}

export function getBadgeInfo(
repo: Repo,
type: string,
type: BadgeType,
label?: string,
value?: string
): [string, string] {
switch (type) {
case "github-actions":
return getGithubActionsBadge(repo, value ?? "ci.yml", label ?? "gh");
return getGithubActionsBadge(repo, value, label);
case "github-license":
return getGithubLicenseBadge(repo);
case "github-tag":
return getGithubTagBadge(repo, value);
case "fossa-license":
return getFossaBadge(repo, "license");
case "fossa-security":
Expand All @@ -72,6 +113,12 @@ export function getBadgeInfo(
return getCodecovBadge(repo);
case "tbd-vectors":
return getTbdVectorsBadge(repo);
case "npm":
return getNpmBadge(value);
case "maven":
return getMavenBadge(value);
case "reference-docs":
return getReferenceDocsBadge(value);
default:
return [
getDefaultBadgeSource(type, label ?? "badge", value ?? "value"),
Expand Down

0 comments on commit 86acb3c

Please sign in to comment.