Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 0 additions & 127 deletions .github/workflows/deploy-aws.yml

This file was deleted.

148 changes: 148 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# Publishes GH release for new versions, with compiled app attached
# - Triggered when a git tag matching X.Y.0 (major or minor) is pushed
# - Or if manually dispatched with any valid and existing tag specified
# - Check out the source at the requested tag
# - Run a clean production build (yarn build → dist/)
# - Bundle dist/ + server.js + package.json + yarn.lock into tar.gz and zip
# - Create a DRAFT GH release with auto-gen changelog and bundled artifacts attached

name: 🚀 Release

on:
push:
tags:
- '*.*.0'
workflow_dispatch:
inputs:
tag:
description: 'Existing git tag to release (e.g. 2.1.0)'
required: true
type: string

permissions:
contents: write

concurrency:
group: release-${{ inputs.tag || github.ref_name }}
cancel-in-progress: false

jobs:
release:
name: 🚀 Build & Publish Release
runs-on: ubuntu-latest
steps:
- name: Resolve tag 🏷️
id: tag
env:
INPUT_TAG: ${{ inputs.tag }}
EVENT_NAME: ${{ github.event_name }}
REF: ${{ github.ref }}
run: |
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
TAG="$INPUT_TAG"
else
TAG="${REF#refs/tags/}"
fi
if ! echo "$TAG" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "::error::Invalid tag '$TAG'. Expected semver (e.g. 2.1.0)."
exit 1
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "Releasing tag: $TAG"

- name: Checkout source at tag 🛎️
uses: actions/checkout@v6
with:
ref: refs/tags/${{ steps.tag.outputs.tag }}
fetch-depth: 0

- name: Setup Node.js 🔧
uses: actions/setup-node@v6
with:
node-version: '22'
cache: 'yarn'

- name: Install dependencies 📦
run: yarn install --frozen-lockfile

- name: Build for production 🏗️
run: yarn build

- name: Verify build output ✅
run: |
if [ ! -d "dist/client" ]; then
echo "::error::Build failed: dist/client directory not created"
exit 1
fi
if [ ! -f "dist/server/entry.mjs" ]; then
echo "::error::Build failed: SSR entry not found"
exit 1
fi
echo "✅ Build successful"

- name: Package release artifacts 🗜️
id: package
env:
TAG: ${{ steps.tag.outputs.tag }}
run: |
STAGING="web-check-${TAG}"
rm -rf "$STAGING"
mkdir -p "$STAGING"
cp -r dist api public "$STAGING/"
cp server.js package.json yarn.lock "$STAGING/"
[ -f LICENSE ] && cp LICENSE "$STAGING/" || true
[ -f README.md ] && cp README.md "$STAGING/" || true

TARBALL="${STAGING}.tar.gz"
ZIPFILE="${STAGING}.zip"
tar -czf "$TARBALL" "$STAGING"
zip -qr "$ZIPFILE" "$STAGING"

ls -lh "$TARBALL" "$ZIPFILE"
echo "tarball=$TARBALL" >> "$GITHUB_OUTPUT"
echo "zipfile=$ZIPFILE" >> "$GITHUB_OUTPUT"

- name: Create draft release 🚀
id: release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ steps.tag.outputs.tag }}
name: Web-Check v${{ steps.tag.outputs.tag }}
draft: true
prerelease: false
generate_release_notes: true
fail_on_unmatched_files: true
files: |
${{ steps.package.outputs.tarball }}
${{ steps.package.outputs.zipfile }}
token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }}

- name: Job summary 📋
if: always()
env:
TAG: ${{ steps.tag.outputs.tag }}
REPO_URL: ${{ github.server_url }}/${{ github.repository }}
RELEASE_URL: ${{ steps.release.outputs.url }}
RELEASE_OUTCOME: ${{ steps.release.outcome }}
run: |
{
echo "## 🚀 Release"
echo ""
echo "| Step | Result |"
echo "|------|--------|"
if [ -n "$TAG" ]; then
echo "| Tag | [\`${TAG}\`](${REPO_URL}/releases/tag/${TAG}) |"
else
echo "| Tag | ❌ Could not resolve |"
fi
if [ "$RELEASE_OUTCOME" = "success" ]; then
if [ -n "$RELEASE_URL" ]; then
echo "| Draft release | ✅ [View draft](${RELEASE_URL}) |"
else
echo "| Draft release | ✅ [View releases](${REPO_URL}/releases) |"
fi
echo "| Artifacts | \`web-check-${TAG}.tar.gz\`, \`web-check-${TAG}.zip\` |"
else
echo "| Draft release | ❌ Failed (outcome: ${RELEASE_OUTCOME:-unknown}) |"
fi
} >> "$GITHUB_STEP_SUMMARY"
16 changes: 15 additions & 1 deletion api/carbon.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ const GRID_INTENSITY = 442;
const RENEWABLE_INTENSITY = 50;
const LITRES_PER_GRAM = 0.5562;

// Reference median grams CO2 per visit, drawn from websitecarbon's published average.
// Used to estimate a percentile rank since we lack their measured-sites dataset
const REFERENCE_MEDIAN_GRAMS = 0.8;

// Approximate percentile via log2 distance from the reference median.
// 1 doubling above median drops 25 points; clamp to [1, 99]
const estimateCleanerThan = (grams) => {
if (!grams || grams <= 0) return 0;
const pct = 50 - 25 * Math.log2(grams / REFERENCE_MEDIAN_GRAMS);
return Math.max(1, Math.min(99, Math.round(pct)));
};

// Stream the response, cap at MAX_BYTES so huge pages can't blow memory or time
const fetchByteCount = async (url) => {
const r = await fetch(url, {
Expand Down Expand Up @@ -66,11 +78,13 @@ const carbonHandler = async (url) => {
}
if (!bytes) return { skipped: 'Site returned no content, cannot calculate carbon' };
log.debug(`measured ${bytes} bytes for ${url}`);
const statistics = computeCarbon(bytes);
return {
url,
bytes,
green: false,
statistics: computeCarbon(bytes),
statistics,
cleanerThan: estimateCleanerThan(statistics.co2.grid.grams),
scanUrl: url,
};
};
Expand Down
16 changes: 8 additions & 8 deletions astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { defineConfig } from 'astro/config';
import { loadEnv } from 'vite';

// Integrations
import svelte from '@astrojs/svelte';
import react from '@astrojs/react';
import partytown from '@astrojs/partytown';
import sitemap from '@astrojs/sitemap';

// Adapters
Expand All @@ -12,12 +12,12 @@ import netlifyAdapter from '@astrojs/netlify';
import nodeAdapter from '@astrojs/node';
import cloudflareAdapter from '@astrojs/cloudflare';

// Helper function to unwrap both Vite and Node environment variables
const unwrapEnvVar = (varName, fallbackValue) => {
const classicEnvVar = process?.env && process.env[varName];
const viteEnvVar = import.meta.env[varName];
return classicEnvVar || viteEnvVar || fallbackValue;
};
// Pre-load .env so values are available in this config, before Vite
const fileEnv = loadEnv(process.env.NODE_ENV || 'development', process.cwd(), '');

// Read an env var, preferring shell over .env, with a final fallback
const unwrapEnvVar = (varName, fallbackValue) =>
process.env[varName] ?? fileEnv[varName] ?? fallbackValue;

// Determine the deploy target (vercel, netlify, cloudflare, node)
const deployTarget = unwrapEnvVar('PLATFORM', 'node').toLowerCase();
Expand All @@ -35,7 +35,7 @@ const base = unwrapEnvVar('BASE_URL', '/');
const isBossServer = unwrapEnvVar('BOSS_SERVER', false);

// Initialize Astro integrations
const integrations = [svelte(), react(), partytown(), sitemap()];
const integrations = [svelte(), react(), sitemap()];

// Set the appropriate adapter, based on the deploy target
function getAdapter(target) {
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"puppeteer-core": "^24.42.0",
"react": "^19.2.5",
"react-dom": "^19.2.5",
"react-masonry-css": "^1.0.16",
"react-router-dom": "^7.14.2",
"react-simple-maps": "^3.0.0",
"react-toastify": "^11.1.0",
Expand All @@ -73,7 +72,6 @@
"@astrojs/cloudflare": "^13.3.1",
"@astrojs/netlify": "^7.0.8",
"@astrojs/node": "^10.0.6",
"@astrojs/partytown": "^2.1.7",
"@astrojs/sitemap": "^3.7.2",
"@astrojs/svelte": "^8.1.0",
"@astrojs/ts-plugin": "^1.10.7",
Expand Down
Binary file removed public/fonts/Hubot-Sans/Hubot-Sans.ttf
Binary file not shown.
Binary file removed public/fonts/Hubot-Sans/Hubot-Sans.woff2
Binary file not shown.
Binary file removed public/fonts/Hubot-Sans/OTF/HubotSans-Black.otf
Binary file not shown.
Binary file not shown.
Binary file removed public/fonts/Hubot-Sans/OTF/HubotSans-Bold.otf
Binary file not shown.
Binary file not shown.
Binary file removed public/fonts/Hubot-Sans/OTF/HubotSans-ExtraBold.otf
Binary file not shown.
Binary file not shown.
Binary file removed public/fonts/Hubot-Sans/OTF/HubotSans-ExtraLight.otf
Binary file not shown.
Binary file not shown.
Binary file removed public/fonts/Hubot-Sans/OTF/HubotSans-Italic.otf
Binary file not shown.
Binary file removed public/fonts/Hubot-Sans/OTF/HubotSans-Light.otf
Binary file not shown.
Binary file not shown.
Binary file removed public/fonts/Hubot-Sans/OTF/HubotSans-Medium.otf
Binary file not shown.
Binary file not shown.
Binary file removed public/fonts/Hubot-Sans/OTF/HubotSans-Regular.otf
Binary file not shown.
Binary file removed public/fonts/Hubot-Sans/OTF/HubotSans-SemiBold.otf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed public/fonts/Hubot-Sans/TTF/HubotSans-Black.ttf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed public/fonts/Hubot-Sans/TTF/HubotSans-ExtraLight.ttf
Binary file not shown.
Binary file not shown.
Binary file removed public/fonts/Hubot-Sans/TTF/HubotSans-Light.ttf
Binary file not shown.
Binary file not shown.
Binary file removed public/fonts/Hubot-Sans/TTF/HubotSans-Medium.ttf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed public/fonts/Hubot-Sans/WOFF2/HubotSans-Black.woff2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed public/fonts/Hubot-Sans/WOFF2/HubotSans-Light.woff2
Binary file not shown.
Binary file not shown.
Binary file removed public/fonts/Hubot-Sans/WOFF2/HubotSans-Medium.woff2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed public/fonts/Inter-Black.ttf
Binary file not shown.
Binary file removed public/fonts/Inter-Bold.ttf
Binary file not shown.
Binary file removed public/fonts/Inter-ExtraBold.ttf
Binary file not shown.
Binary file removed public/fonts/Inter-ExtraLight.ttf
Binary file not shown.
Binary file removed public/fonts/Inter-Light.ttf
Binary file not shown.
Binary file removed public/fonts/Inter-Medium.ttf
Binary file not shown.
Binary file removed public/fonts/Inter-Regular.ttf
Binary file not shown.
Binary file removed public/fonts/Inter-SemiBold.ttf
Binary file not shown.
Binary file removed public/fonts/Inter-Thin.ttf
Binary file not shown.
Binary file removed public/fonts/Inter-VariableFont_slnt,wght.ttf
Binary file not shown.
Binary file added public/fonts/PTMono-Regular.woff2
Binary file not shown.
7 changes: 7 additions & 0 deletions src/client/analysis/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Days until an ISO/parseable date string, or null when unparseable
export const daysUntil = (raw: unknown): number | null => {
if (typeof raw !== 'string') return null;
const t = Date.parse(raw);
if (!Number.isFinite(t)) return null;
return Math.floor((t - Date.now()) / 86_400_000);
};
Loading