From 8e8cfe73542df4f9985a3d6dcda2e51f2116851b Mon Sep 17 00:00:00 2001 From: obrera <24781037+obrera@users.noreply.github.com> Date: Wed, 18 Feb 2026 13:49:00 +0000 Subject: [PATCH] feat: stamp git commit SHA in builds --- .github/workflows/docker.yml | 2 ++ Dockerfile | 4 +++- astro.config.mjs | 7 +++++++ src/integrations/build-stamp.ts | 22 ++++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/integrations/build-stamp.ts diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index ed2db01..731d4ec 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -75,6 +75,8 @@ jobs: labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max + build-args: | + COMMIT_SHA=${{ github.sha }} - name: Deploy to Dokploy if: github.event_name != 'pull_request' diff --git a/Dockerfile b/Dockerfile index da317c1..7cb092d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,14 @@ FROM oven/bun:latest AS build +ARG COMMIT_SHA=unknown + WORKDIR /workspace COPY package.json bun.lock ./ RUN bun install --frozen-lockfile COPY . . -RUN bun run build +RUN COMMIT_SHA="${COMMIT_SHA}" bun run build FROM beeman/static-server:latest diff --git a/astro.config.mjs b/astro.config.mjs index 91d95eb..1ab5c46 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -3,14 +3,20 @@ import { defineConfig } from 'astro/config'; import starlight from '@astrojs/starlight'; import tailwindcss from '@tailwindcss/vite'; import umami from '@yeskunall/astro-umami'; +import { buildStamp } from './src/integrations/build-stamp'; import { rawMarkdown } from './src/integrations/raw-markdown'; +const commitSha = process.env.COMMIT_SHA || 'dev'; + // https://astro.build/config export default defineConfig({ site: 'https://colmena.dev', integrations: [ starlight({ title: 'colmena', + head: [ + { tag: 'meta', attrs: { name: 'x-commit', content: commitSha } }, + ], social: [ { icon: 'github', label: 'GitHub', href: 'https://github.com/colmena' }, ], @@ -38,6 +44,7 @@ export default defineConfig({ customCss: ['./src/styles/global.css'], }), rawMarkdown(), + buildStamp({ sha: commitSha, repo: 'colmena/colmena-dev' }), umami({ id: '3d447655-7d7a-4ba8-806e-74eb1831f7b8', endpointUrl: 'https://stats.colmena.dev', diff --git a/src/integrations/build-stamp.ts b/src/integrations/build-stamp.ts new file mode 100644 index 0000000..bdab300 --- /dev/null +++ b/src/integrations/build-stamp.ts @@ -0,0 +1,22 @@ +import { writeFileSync } from 'node:fs'; +import { join } from 'node:path'; +import type { AstroIntegration } from 'astro'; + +export function buildStamp(options: { sha: string; repo: string }): AstroIntegration { + return { + name: 'build-stamp', + hooks: { + 'astro:build:done': ({ dir }) => { + const { sha, repo } = options; + writeFileSync( + join(dir.pathname, 'version.json'), + JSON.stringify({ + sha, + url: sha !== 'dev' ? `https://github.com/${repo}/commit/${sha}` : null, + built: new Date().toISOString(), + }), + ); + }, + }, + }; +}