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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
- name: Build website (client + SSG)
run: pnpm build.client && pnpm build.server
working-directory: website
env:
GITHUB_TOKEN: ${{ github.token }} # the changelog reads the GitHub releases

- name: Typecheck test app
run: pnpm build.types && pnpm lint
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ jobs:
GH_TOKEN: ${{ github.token }}

# The docs show the new version: the version menu, the install commands and
# the changelog read npm when they build.
# the changelog read npm and the GitHub releases when they build.
website:
needs: published
uses: ./.github/workflows/website.yml
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ jobs:
- name: Production settings
run: npx --yes [email protected] pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}

# The changelog reads the GitHub releases when it builds: with a token,
# GitHub counts the requests against it, not against the runner's address.
- name: Build
run: npx --yes [email protected] build --prod --token=${{ secrets.VERCEL_TOKEN }}
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Deploy
run: npx --yes [email protected] deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ files — no functions. Build settings live in `vercel.json` at the repo root. P
from GitHub Actions (`.github/workflows/website.yml`, Vercel CLI) after each release and on pushes to
`v2` that touch `website/`; Vercel's Git integration only builds previews for other branches
(`website/scripts/vercel-preview.sh`). Versions, dist-tags and dates on the site come from npm at
build time (`website/src/lib/npm.ts`). Details: `website/README.md`.
build time (`website/src/lib/npm.ts`); the changelog's notes are the published GitHub releases, read
at build time too (`website/src/lib/github.ts`). Details: `website/README.md`.

## Releases

Expand Down
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ version (`2.0.0-beta.2`…), commits it, tags it and pushes. The tag runs
Trusted Publishing (a prerelease under its identifier, like `beta`; a plain version under
`latest`);
3. it drafts a GitHub release with the changelog generated from the commits. Edit its notes while it
waits: the generator only lists `feat`, `fix` and `perf` commits, and only marks a change as
breaking when its commit has a `!` or a `BREAKING CHANGE:` footer.
waits: they are also the website's changelog for that version, and the generator only lists
`feat`, `fix` and `perf` commits, and only marks a change as breaking when its commit has a `!` or
a `BREAKING CHANGE:` footer.

Nothing is public until a maintainer approves the staged version with 2FA (npm 11.15 or later):

Expand Down
12 changes: 9 additions & 3 deletions website/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,20 @@ pnpm preview # production build served locally by Vite

From the repo root, `pnpm build.website` runs the whole chain (library + client + SSG), as Vercel does.

## Versions come from npm
## Versions come from npm, release notes from GitHub

The version menu, the install commands, the banners, the Qwik v2 badge and the changelog's versions,
dist-tags and dates are read from the npm registry when the site builds (`vite.config.ts` →
`src/lib/npm.ts` → `src/lib/release.ts`). Only the release notes are written by hand, in
`src/lib/changelog.ts`, per `major.minor` series. Offline, a local build shows the repo's version as
`src/lib/npm.ts` → `src/lib/release.ts`). Offline, a local build shows the repo's version as
unreleased; in CI (`CI` set) the build fails instead.

The changelog's notes are the published GitHub releases, as GitHub renders them (`vite.config.ts` →
`src/lib/github.ts` → `src/lib/release-notes.ts`): to change what the site says about a version, edit
its release on GitHub and redeploy. A release is a draft until its version is approved on npm, so the
site never shows notes for a version that isn't out (see `CONTRIBUTING.md` → Releases). Set
`GITHUB_TOKEN` to read them with a token. Offline or rate-limited, a local or preview build goes on
without notes; in GitHub Actions the build fails instead.

## Deployment (Vercel)

The site is fully prerendered, so Vercel serves `dist/` as static files: no functions.
Expand Down
4 changes: 2 additions & 2 deletions website/src/components/docs/inline.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { JSXOutput } from "@qwik.dev/core";

/**
* Renders a tiny markdown subset used by data-driven copy (changelog entries,
* API tables): `code` and **bold**. Everything else is plain text.
* Renders a tiny markdown subset used by data-driven copy (API tables):
* `code` and **bold**. Everything else is plain text.
*/
export function inline(text: string): JSXOutput {
return text.split(/(`[^`]+`|\*\*[^*]+\*\*)/g).map((part, i) => {
Expand Down
197 changes: 0 additions & 197 deletions website/src/lib/changelog.ts

This file was deleted.

68 changes: 68 additions & 0 deletions website/src/lib/github.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// The release notes of qwik-sonner: the body of each published GitHub release, as GitHub renders it. vite.config.ts
// reads them when the site builds, next to npm.ts, so the changelog shows what each release says.
// Plain functions, no Vite globals: vite.config.ts runs them in Node.

export interface ReleaseNotes {
/** the notes as HTML, rendered and sanitized by GitHub; empty when the release has none */
html: string;
/** the release's page on GitHub */
url: string;
}

/** The notes of each published release, by version (the tag without its `v`). */
export type Releases = Record<string, ReleaseNotes>;

const RELEASES = "https://api.github.com/repos/diecodev/qwik-sonner/releases";
const PER_PAGE = 100;

interface GitHubRelease {
tag_name: string;
draft: boolean;
html_url: string;
body_html?: string | null;
}

const readPage = async (page: number): Promise<GitHubRelease[]> => {
const headers: Record<string, string> = {
// `body_html`: the body as GitHub renders it on the release page
Accept: "application/vnd.github.html+json",
"X-GitHub-Api-Version": "2022-11-28",
"User-Agent": "qwik-sonner-website",
};
// without a token GitHub allows 60 requests an hour per address, shared by every build on it
if (process.env.GITHUB_TOKEN) headers.Authorization = `Bearer ${process.env.GITHUB_TOKEN}`;
const response = await fetch(`${RELEASES}?per_page=${PER_PAGE}&page=${page}`, {
headers,
signal: AbortSignal.timeout(10_000),
});
if (!response.ok) throw new Error(`${response.status} ${response.statusText}`);
return (await response.json()) as GitHubRelease[];
};

/**
* Reads the published releases (drafts wait for the approval on npm, see CONTRIBUTING.md). Offline or rate-limited,
* a local or preview build goes on without notes; in GitHub Actions (production deploys and the CI) it fails, so a
* deploy never drops the notes.
*/
export const readReleases = async (): Promise<Releases> => {
try {
const releases: GitHubRelease[] = [];
for (let page = 1; ; page++) {
const batch = await readPage(page);
releases.push(...batch);
if (batch.length < PER_PAGE) break;
}
return Object.fromEntries(
releases
.filter((release) => !release.draft && release.tag_name.startsWith("v"))
.map((release) => [
release.tag_name.slice(1),
{ html: release.body_html?.trim() ?? "", url: release.html_url },
]),
);
} catch (error) {
if (process.env.GITHUB_ACTIONS) throw new Error(`couldn't read ${RELEASES}: ${error}`);
console.warn(`couldn't read ${RELEASES} (${error}): the changelog shows no release notes`);
return {};
}
};
39 changes: 0 additions & 39 deletions website/src/lib/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,42 +119,3 @@ export const lineOf = (npm: Npm, major: number): Line => {
const name = tag ?? parts(version).pre[0] ?? "next";
return { ...base, prerelease: true, spec: `qwik-sonner@${name}` };
};

/** A section of the changelog: a `major.minor` series and its versions on npm. */
export interface Series {
major: number;
minor: number;
/** the newest version of the series on npm, or the repo's (or `major.minor.0`) before any */
version: string;
/** dist-tags pointing at `version` */
tags: string[];
/** the day it came out, `null` while it isn't on npm */
date: string | null;
/** the other versions of the series, newest first */
earlier: { version: string; date: string }[];
}

export const seriesOf = (npm: Npm, major: number, minor: number): Series => {
const inSeries = (version: string) => {
const [x, y] = parts(version).core;
return x === major && y === minor;
};
const published = Object.keys(npm.dates).filter(inSeries).sort(newestFirst);
const version = published[0] ?? (inSeries(npm.version) ? npm.version : `${major}.${minor}.0`);
return {
major,
minor,
version,
tags: tagsOf(npm, version),
date: npm.dates[version] ?? null,
earlier: published.slice(1).map((other) => ({ version: other, date: npm.dates[other] })),
};
};

/** Every `major.minor` series on npm plus the repo's, newest first: `["2.0", "1.0", "0.4", …]`. */
export const seriesKeys = (npm: Npm) => {
const keys = new Set(
[...Object.keys(npm.dates), npm.version].map((v) => parts(v).core.slice(0, 2).join(".")),
);
return [...keys].sort((a, b) => newestFirst(`${a}.0`, `${b}.0`));
};
Loading
Loading