From a750b1a9e9aa100a820fbeeb05fbcad6741d0a72 Mon Sep 17 00:00:00 2001 From: Diecodev Date: Thu, 29 Oct 2026 12:02:51 -0500 Subject: [PATCH] =?UTF-8?q?ci:=20=F0=9F=9A=80=20deploy=20the=20website=20a?= =?UTF-8?q?fter=20each=20release,=20from=20GitHub=20Actions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Vercel built the website on every push, a library change or a release commit too, and before the new version was on npm. The website now deploys from GitHub Actions (website.yml, with the Vercel CLI: the build runs with the CI's pnpm and Node, and Vercel serves it), only: - after each release, once the version is public on npm: release.yml waits for the approval (`npm stage approve`, up to 6 hours), publishes the GitHub release that was a draft, and calls it; - on a push to main that changes website/ or vercel.json; - by hand. Vercel builds nothing from Git for main any more. A branch that changes website/ or vercel.json, compared with main, still gets a preview from its Git integration (website/scripts/vercel-preview.sh, its Ignored Build Step); the rest are skipped. The deploy needs VERCEL_TOKEN, VERCEL_ORG_ID and VERCEL_PROJECT_ID as secrets, `.vercel` is ignored, and CONTRIBUTING and the website's README describe the flow. --- .github/workflows/release.yml | 31 ++++++++++++++++++++- .github/workflows/website.yml | 46 +++++++++++++++++++++++++++++++ .gitignore | 3 ++ CONTRIBUTING.md | 14 +++++++--- vercel.json | 2 ++ website/README.md | 28 +++++++++++++------ website/scripts/vercel-preview.sh | 9 ++++++ 7 files changed, 120 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/website.yml create mode 100755 website/scripts/vercel-preview.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a5dc09b..d26fc50 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -93,7 +93,36 @@ jobs: - uses: actions/setup-node@v7 with: node-version: 26 - # a draft: publish it once the staged version is approved on npm + # a draft until the staged version is approved on npm: the job below publishes it - run: npx changelogithub@15.0.5 --draft ${{ contains(github.ref_name, '-') && '--prerelease' || '' }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + published: + name: Wait for the approval on npm + needs: github_release + runs-on: ubuntu-latest + # as long as GitHub lets a job run; past it, publish the release and run the Website workflow by hand + timeout-minutes: 360 + permissions: + contents: write + steps: + # the version answers once a maintainer approves it (`npm stage approve`): a staged one isn't public + - name: Wait for the version on npm + run: | + VERSION="${GITHUB_REF_NAME#v}" + until curl --silent --fail --output /dev/null "https://registry.npmjs.org/qwik-date/$VERSION"; do + sleep 30 + done + echo "qwik-date@$VERSION is on npm" + + - name: Publish the GitHub release + run: gh release edit "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --draft=false + env: + GH_TOKEN: ${{ github.token }} + + # the docs show the new version (the menu, the install commands, the changelog read npm when they build) + website: + needs: published + uses: ./.github/workflows/website.yml + secrets: inherit diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml new file mode 100644 index 0000000..0826957 --- /dev/null +++ b/.github/workflows/website.yml @@ -0,0 +1,46 @@ +name: Website + +on: + # a change to the docs goes to production on its own + push: + branches: [main] + paths: + - "website/**" + - "vercel.json" + - ".github/workflows/website.yml" + # release.yml, once the new version is public on npm + workflow_call: + # by hand, e.g. when the approval on npm took longer than release.yml waits + workflow_dispatch: + +concurrency: + group: website-production + # never stop a deploy halfway: a newer one waits for it + cancel-in-progress: false + +permissions: + contents: read + +jobs: + deploy: + name: Deploy to Vercel + runs-on: ubuntu-latest + timeout-minutes: 15 + # the Vercel project, read by the CLI + env: + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + steps: + - uses: actions/checkout@v7 + - uses: ./.github/actions/setup + + # Vercel builds nothing from Git for main (vercel.json): the build runs here, with the CI's pnpm and Node, and + # Vercel only serves it + - name: Production settings + run: npx --yes vercel@65.7.0 pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }} + + - name: Build + run: npx --yes vercel@65.7.0 build --prod --token=${{ secrets.VERCEL_TOKEN }} + + - name: Deploy + run: npx --yes vercel@65.7.0 deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }} diff --git a/.gitignore b/.gitignore index d2bc427..74f4559 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,6 @@ bun.lockb # Tests playwright-report test-results + +# Vercel CLI +.vercel diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5addd37..e32d919 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -55,9 +55,12 @@ headless parts and `useCalendar()` fields are data in `website/src/data/`: the p `llms-full.txt` read them. After changing them, or the use cases in `website/scripts/llms-full.md`, run `pnpm -C website llms` to write `website/public/llms-full.txt` again. -Vercel builds it on every push (`vercel.json`). pnpm's version is the one in `package.json`'s -`packageManager`, for Vercel, the CI and your installs alike: to update it, change that line and run -`pnpm install`, which records it in the lockfile. +Vercel hosts it. Production deploys from GitHub Actions (`.github/workflows/website.yml`): after each +release, once the new version is on npm, and on each push to `main` that changes `website/` or +`vercel.json`. Vercel builds nothing from Git for `main`; a branch that changes the website gets a +preview, seen in Vercel's dashboard only (`website/scripts/vercel-preview.sh`). pnpm's version is the +one in `package.json`'s `packageManager`, for the deploys, the CI and your installs alike: to update it, +change that line and run `pnpm install`, which records it in the lockfile. ## Before opening a pull request @@ -86,4 +89,7 @@ npm stage list qwik-date npm stage approve # asks for the one-time password ``` -Then publish the draft release on GitHub. To drop a staged version, `npm stage reject `. +The release workflow waits for that (up to 6 hours), then publishes the GitHub release and deploys the +website, which reads the new version from npm. If the approval takes longer, publish the draft release +by hand and run the Website workflow (Actions → Website → Run workflow). To drop a staged version, +`npm stage reject `. diff --git a/vercel.json b/vercel.json index ad71ea7..cfb24a5 100644 --- a/vercel.json +++ b/vercel.json @@ -1,6 +1,8 @@ { "$schema": "https://openapi.vercel.sh/vercel.json", "framework": null, + "git": { "deploymentEnabled": { "main": false } }, + "ignoreCommand": "sh website/scripts/vercel-preview.sh", "buildCommand": "pnpm build.website", "outputDirectory": "website/dist", "trailingSlash": true, diff --git a/website/README.md b/website/README.md index 7c25fbb..12370c1 100644 --- a/website/README.md +++ b/website/README.md @@ -20,9 +20,24 @@ From the repo root, `pnpm build.website` runs the whole chain (library + client ## Deployment (Vercel) -The site is fully prerendered, so Vercel serves `dist/` as static files: no functions. Its GitHub -integration builds every push (production for `main`, a preview for the other branches); there is no -GitHub Actions workflow for it. +The site is fully prerendered, so Vercel serves `dist/` as static files: no functions. + +**Production** deploys from GitHub Actions ([`website.yml`](../.github/workflows/website.yml)), which +builds with the Vercel CLI (`vercel build --prod`, then `vercel deploy --prebuilt --prod`): + +- after each release, once the new version is public on npm (`release.yml` calls it); +- on each push to `main` that changes `website/` or `vercel.json`; +- by hand (Actions → Website → Run workflow). + +It needs three repository secrets: `VERCEL_TOKEN`, `VERCEL_ORG_ID` (the team's ID) and +`VERCEL_PROJECT_ID`. + +**Previews** come from Vercel's Git integration, which builds nothing for `main` +(`git.deploymentEnabled`). Its Ignored Build Step, [`scripts/vercel-preview.sh`](./scripts/vercel-preview.sh), +skips every branch that doesn't change `website/` or `vercel.json` compared with `main`. The previews +are only seen in Vercel's dashboard: in the project's Git settings, the pull request and commit comments, +the `deployment_status` events and the commit statuses are off. A pull request from a fork waits for a +maintainer to authorize it there (Git Fork Protection, in the Security settings). The build settings live in [`vercel.json`](../vercel.json) at the repo root: @@ -34,11 +49,8 @@ The build settings live in [`vercel.json`](../vercel.json) at the repo root: | Build command | `pnpm build.website` | | Output directory | `website/dist` | -Both run the pnpm of `package.json`'s `packageManager`: Vercel reads it and picks pnpm 12 (without it, -it would pick pnpm 10 for this lockfile), which then switches to that exact version. +pnpm is the one in `package.json`'s `packageManager`: the CI's setup installs it, and Vercel reads it +for the previews (without it, it would pick pnpm 10 for this lockfile). `trailingSlash` matches the URLs of the pages (`/calendar/`), `404.html` answers the missing ones, and `/build/` and `/assets/` (hashed file names) are cached for a year. - -One-time setup in the dashboard: import the `diecodev/qwik-date` repo, keep the root directory as the -repo root, and add the custom domain `qwik-date.dieco.dev` (a `CNAME` to Vercel at the DNS provider). diff --git a/website/scripts/vercel-preview.sh b/website/scripts/vercel-preview.sh new file mode 100755 index 0000000..66a6e1c --- /dev/null +++ b/website/scripts/vercel-preview.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# Vercel's Ignored Build Step (`ignoreCommand` in vercel.json), for the previews: Vercel builds nothing from Git for +# main, whose deploys come from .github/workflows/website.yml. Exit 0 skips the build and 1 builds it: a branch gets +# a preview only when it changes the website or vercel.json, compared with main. When that can't be told, it builds. +repo="https://github.com/${VERCEL_GIT_REPO_OWNER:-diecodev}/${VERCEL_GIT_REPO_SLUG:-qwik-date}.git" +git fetch --quiet --depth=50 "$repo" main || exit 1 +base=$(git merge-base HEAD FETCH_HEAD) || exit 1 +git diff --quiet "$base" HEAD -- website vercel.json && exit 0 +exit 1