diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1a40b66..315101a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -107,3 +107,26 @@ jobs: --title "v$RELEASE_VERSION" \ "${KIND[@]}" \ --notes-file "$RUNNER_TEMP/release/release-notes.md" + + # Cloudflare Pages deploys the `site` branch as the live docs, so the docs + # change with the release that publishes their API. A job of its own, so a + # failure can be rerun without publishing again. Forced, because a docs + # fix cherry-picked onto `site` between releases has been merged to `main` + # first, so a release made after it includes it. + docs-site: + needs: publish + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: write + steps: + - name: Move the docs site to the release + env: + GH_TOKEN: ${{ github.token }} + RELEASE_COMMIT: ${{ github.sha }} + run: | + if ! gh api -X PATCH "repos/$GITHUB_REPOSITORY/git/refs/heads/site" \ + -f sha="$RELEASE_COMMIT" -F force=true; then + echo "::error::The package is published, but the docs site wasn't moved. Rerun this job, or run: git push --force origin $RELEASE_COMMIT:refs/heads/site" + exit 1 + fi diff --git a/AGENTS.md b/AGENTS.md index e613663..5a203ec 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -77,6 +77,9 @@ to static files. It's a package in the pnpm workspace and isn't published. `/llms.txt` and `/llms-full.txt` list the current line's pages. Link between pages with root-relative paths, which the Markdown turns into full URLs. +- The live docs deploy from the `site` branch, which the Release workflow + moves to each released commit; `main` and pull requests deploy as + previews. Don't push `site` yourself. - `pnpm run check` doesn't build the site. After changing `site/`, run `pnpm run build:site`, which builds the package, then prerenders the site into `site/dist/client`. `pnpm --dir site run dev` serves it while you diff --git a/CHANGELOG.md b/CHANGELOG.md index e5fead8..2f8ef5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ All notable changes to `@monarcode/effetch`, newest first. [llms.txt](https://effetch.pages.dev/llms.txt) and [llms-full.txt](https://effetch.pages.dev/llms-full.txt) list the pages for LLMs. +- Releases update the documentation site: the live docs show the newest + release's API, and `main` deploys as a preview. ### Changed diff --git a/site/src/lib/shared.ts b/site/src/lib/shared.ts index e34d5ed..8473d9a 100644 --- a/site/src/lib/shared.ts +++ b/site/src/lib/shared.ts @@ -14,14 +14,25 @@ export function pageMeta(title: string, description: string) { export const NOT_FOUND_PATH = "/404"; export const NOT_FOUND_MARK = "effetch-not-found"; +/** Set by `vite.config.ts` from the build's environment. */ +declare const __SOURCE_REF__: string; +declare const __SITE_URL__: string; + export const gitConfig = { user: "monarcode", repo: "effetch", - branch: "main", + /** + * The commit the site was built from, so a page's GitHub link shows the + * source it was built from: on the live site, the release's. + */ + ref: __SOURCE_REF__, }; -/** Where the site is served. Link previews and `llms.txt` need full URLs. */ -export const SITE_URL = "https://effetch.pages.dev"; +/** + * Where this build is served: the live site, or a preview's own address. + * `llms.txt` and the pages' Markdown need full URLs. + */ +export const SITE_URL = __SITE_URL__; /** The URL of a page's Markdown, for LLMs and the copy button. */ export function getPageMarkdownUrl(page: { slugs: string[] }) { diff --git a/site/src/routes/docs/$.tsx b/site/src/routes/docs/$.tsx index c57a2d0..d905626 100644 --- a/site/src/routes/docs/$.tsx +++ b/site/src/routes/docs/$.tsx @@ -126,7 +126,7 @@ function Content({ diff --git a/site/vite.config.ts b/site/vite.config.ts index b2f0b85..24e071d 100644 --- a/site/vite.config.ts +++ b/site/vite.config.ts @@ -21,8 +21,19 @@ const { version } = JSON.parse( readFileSync(new URL("../package.json", import.meta.url), "utf8"), ) as { version: string }; +// The live site, or, on a Cloudflare Pages preview (`main` and pull +// requests), the preview's own address, so its Markdown links stay on it. +const PRODUCTION = "https://effetch.pages.dev"; +const preview = + process.env.CF_PAGES_BRANCH && process.env.CF_PAGES_BRANCH !== "site"; +const siteUrl = (preview && process.env.CF_PAGES_URL) || PRODUCTION; + export default defineConfig(({ command }) => ({ - define: { __PACKAGE_VERSION__: JSON.stringify(version) }, + define: { + __PACKAGE_VERSION__: JSON.stringify(version), + __SOURCE_REF__: JSON.stringify(process.env.CF_PAGES_COMMIT_SHA || "main"), + __SITE_URL__: JSON.stringify(siteUrl), + }, plugins: [ // The pages' MDX options run here, in the build, never in the browser. fumadocsMdx({