feat: add CI status badge with commit SHA on homelab experience card
Build & Push Portfolio Image / build-push (push) Successful in 4m8s
Build & Push Portfolio Image / build-push (push) Successful in 4m8s
This commit is contained in:
@@ -63,3 +63,5 @@ jobs:
|
|||||||
docker push "${IMAGE}:${{ steps.sha.outputs.short_sha }}"
|
docker push "${IMAGE}:${{ steps.sha.outputs.short_sha }}"
|
||||||
docker push "${IMAGE}:latest"
|
docker push "${IMAGE}:latest"
|
||||||
echo "✓ Image pushed: ${IMAGE}:${{ steps.sha.outputs.short_sha }}"
|
echo "✓ Image pushed: ${IMAGE}:${{ steps.sha.outputs.short_sha }}"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
import { NextResponse } from 'next/server'
|
import { NextRequest, NextResponse } from 'next/server'
|
||||||
|
|
||||||
const FORGEJO_URL = 'https://forgejo.riotpiao.com'
|
const FORGEJO_URL = 'https://forgejo.riotpiao.com'
|
||||||
const REPO = 'rock/riotpiao.com'
|
const DEFAULT_REPO = 'rock/riotpiao.com'
|
||||||
|
const ALLOWED_REPOS = ['rock/riotpiao.com', 'rock/homelab', 'rock/homelab-frontend', 'rock/poimen', 'rock/poimen-memory', 'rock/poimen-workflows']
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET(request: NextRequest) {
|
||||||
|
const repo = request.nextUrl.searchParams.get('repo') || DEFAULT_REPO
|
||||||
|
if (!ALLOWED_REPOS.includes(repo)) {
|
||||||
|
return NextResponse.json({ error: 'Repo not allowed' }, { status: 403 })
|
||||||
|
}
|
||||||
const token = process.env.FORGEJO_TOKEN
|
const token = process.env.FORGEJO_TOKEN
|
||||||
|
|
||||||
if (!token) {
|
if (!token) {
|
||||||
@@ -15,7 +20,7 @@ export async function GET() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`${FORGEJO_URL}/api/v1/repos/${REPO}/actions/runs?limit=1`,
|
`${FORGEJO_URL}/api/v1/repos/${repo}/actions/runs?limit=1`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `token ${token}`,
|
Authorization: `token ${token}`,
|
||||||
@@ -42,6 +47,7 @@ export async function GET() {
|
|||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
status: latestRun.status,
|
status: latestRun.status,
|
||||||
conclusion: latestRun.conclusion,
|
conclusion: latestRun.conclusion,
|
||||||
|
sha: latestRun.head_sha,
|
||||||
title: latestRun.display_title || latestRun.head_branch,
|
title: latestRun.display_title || latestRun.head_branch,
|
||||||
branch: latestRun.head_branch,
|
branch: latestRun.head_branch,
|
||||||
url: latestRun.html_url,
|
url: latestRun.html_url,
|
||||||
|
|||||||
@@ -1,8 +1,52 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { motion } from 'framer-motion'
|
import { motion } from 'framer-motion'
|
||||||
|
import { useState, useEffect } from 'react'
|
||||||
|
import { GitBranch, CheckCircle, XCircle, Loader2 } from 'lucide-react'
|
||||||
import { useLanguage } from '@/lib/LanguageContext'
|
import { useLanguage } from '@/lib/LanguageContext'
|
||||||
|
|
||||||
|
interface RepoCI {
|
||||||
|
sha: string
|
||||||
|
status: string
|
||||||
|
url: string
|
||||||
|
}
|
||||||
|
|
||||||
|
function CIBadge({ repo, forgejoUrl }: { repo: string; forgejoUrl: string }) {
|
||||||
|
const [ci, setCI] = useState<RepoCI | null>(null)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetch(`/api/ci-status?repo=${repo}`)
|
||||||
|
.then(r => r.json())
|
||||||
|
.then(data => setCI({
|
||||||
|
sha: data.sha?.substring(0, 7) || '',
|
||||||
|
status: data.conclusion || data.status || 'unknown',
|
||||||
|
url: data.url || `${forgejoUrl}/actions`,
|
||||||
|
}))
|
||||||
|
.catch(() => null)
|
||||||
|
}, [repo, forgejoUrl])
|
||||||
|
|
||||||
|
if (!ci || !ci.sha) return null
|
||||||
|
|
||||||
|
const icon = ci.status === 'success'
|
||||||
|
? <CheckCircle size={12} className="text-green-500" />
|
||||||
|
: ci.status === 'failure'
|
||||||
|
? <XCircle size={12} className="text-red-500" />
|
||||||
|
: <Loader2 size={12} className="animate-spin text-yellow-500" />
|
||||||
|
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
href={`${forgejoUrl}/commit/${ci.sha}`}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="flex items-center gap-1.5 px-2 py-1 rounded-full bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 hover:border-blue-400 dark:hover:border-blue-600 transition-colors"
|
||||||
|
>
|
||||||
|
<GitBranch size={10} className="text-gray-400" />
|
||||||
|
<span className="text-xs font-mono text-gray-600 dark:text-gray-300">{ci.sha}</span>
|
||||||
|
{icon}
|
||||||
|
</a>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const colors = [
|
const colors = [
|
||||||
'from-green-500 to-green-600',
|
'from-green-500 to-green-600',
|
||||||
'from-red-500 to-red-600',
|
'from-red-500 to-red-600',
|
||||||
@@ -93,9 +137,14 @@ export function ExperienceTimeline() {
|
|||||||
{item.role}
|
{item.role}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<span className="text-xs font-mono text-gray-500 dark:text-gray-400 whitespace-nowrap ml-4">
|
<div className="flex flex-col items-end gap-1 ml-4">
|
||||||
|
<span className="text-xs font-mono text-gray-500 dark:text-gray-400 whitespace-nowrap">
|
||||||
{item.period}
|
{item.period}
|
||||||
</span>
|
</span>
|
||||||
|
{index === 0 && (
|
||||||
|
<CIBadge repo="rock/homelab" forgejoUrl="https://forgejo.riotpiao.com/rock/homelab" />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p className="text-sm text-gray-700 dark:text-gray-300 mb-3">
|
<p className="text-sm text-gray-700 dark:text-gray-300 mb-3">
|
||||||
|
|||||||
Reference in New Issue
Block a user