diff --git a/.env.example b/.env.example index 8714d91..a1c7ab4 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,7 @@ APP_NAME="Keyring Example" APP_ENV=local APP_KEY= +# For local work only: on a server, APP_ENV=production and APP_DEBUG=false. APP_DEBUG=true APP_URL=http://localhost:8000 @@ -17,10 +18,12 @@ APP_URL=http://localhost:8000 # FRONTEND_URL=http://localhost:3000 # A proxy in front of the app (tailscale serve, a load balancer, a headless -# frontend's server), believed about HTTPS, the host, the path prefix and the -# visitor's address: comma-separated addresses, or *. Unset, headless mode -# trusts a proxy on this machine (127.0.0.1,::1) and Inertia mode none, so in -# headless mode anything on loopback that forwards to Laravel is trusted. +# frontend's server), believed about HTTPS, the host and the visitor's +# address, and in headless mode the path prefix: comma-separated addresses, or +# *. Unset, headless mode trusts a proxy on this machine (127.0.0.1,::1) and +# Inertia mode none, so in headless mode anything on loopback that forwards to +# Laravel is trusted: keep Laravel's port reachable by the frontend's server +# only, or pin this. # TRUSTED_PROXIES=127.0.0.1 APP_LOCALE=en diff --git a/.github/workflows/kits.yml b/.github/workflows/kits.yml index a5cf3ad..bd0ee1d 100644 --- a/.github/workflows/kits.yml +++ b/.github/workflows/kits.yml @@ -13,6 +13,11 @@ on: permissions: contents: read +env: + # The current LTS, pinned so every job builds and tests with the same + # Node: bump it on purpose, not whenever lts/* moves. + NODE_VERSION: '26.13.1' + concurrency: group: kits-${{ github.ref }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} @@ -76,7 +81,7 @@ jobs: - uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 with: - node-version: lts/* + node-version: ${{ env.NODE_VERSION }} cache: npm - run: composer install --no-interaction --no-progress @@ -86,11 +91,15 @@ jobs: run: node --test bin/ - run: npm run build - run: npm test + # Its tests run packages/ui-react's too. After the build, + # test/build.test.mjs checks how the built server starts and + # what it passes on to Laravel. - name: TanStack Start kit run: | npm test -w kits/tanstack-start npm run types:check -w kits/tanstack-start npm run build -w kits/tanstack-start + node --test kits/tanstack-start/test/build.test.mjs # Its tests run packages/ui-vue's too, and its typecheck the # shared components it imports; vue-tsc checks the rest. # test:build builds it, then checks what the built server sends. @@ -108,12 +117,14 @@ jobs: # against the same screenshots, made in this same image (the README's # "Screenshots"), so the browser, its fonts and its libraries render them # pixel for pixel. Its version is the @playwright/test in - # package-lock.json. + # package-lock.json, and it's pinned by digest, so a re-pushed tag can't + # change what runs: `docker buildx imagetools inspect` gives the digest + # of a new version's tag. browser: name: Browser tests (${{ matrix.kit }}) runs-on: ubuntu-latest container: - image: mcr.microsoft.com/playwright:v1.65.0-noble + image: mcr.microsoft.com/playwright:v1.65.0-noble@sha256:9beb546099e11f52d62e505537914870e01a67e0e6b00ae41da4775324e73dbe strategy: fail-fast: false matrix: @@ -130,7 +141,7 @@ jobs: - uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 with: - node-version: lts/* + node-version: ${{ env.NODE_VERSION }} cache: npm - run: composer install --no-interaction --no-progress @@ -166,7 +177,7 @@ jobs: - uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 with: - node-version: lts/* + node-version: ${{ env.NODE_VERSION }} cache: npm # The export formats the files it rewrites with the monorepo's tools. @@ -278,14 +289,26 @@ jobs: echo 'github.com ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl' > "$hosts" export GIT_SSH_COMMAND="ssh -i $key -o IdentitiesOnly=yes -o UserKnownHostsFile=$hosts -o StrictHostKeyChecking=yes" + # A release is vMAJOR.MINOR.PATCH (prereleases never get + # here), which also keeps the tag from reading as an option. + semver='^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$' + + if ! [[ "$TAG" =~ $semver ]]; then + echo "::error::$TAG isn't a release tag like v1.2.3." + exit 1 + fi + # Keep the repository's history: each release is one commit # on top of the last, and an empty repository gets its first. target="$RUNNER_TEMP/target" git clone --depth 1 "git@github.com:$REPOSITORY.git" "$target" cd "$target" + git checkout -B main find . -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} + - tar -xzf "$RUNNER_TEMP/export.tgz" -C . + # The export never has a .git, and one in the archive + # mustn't replace this clone's. + tar -xzf "$RUNNER_TEMP/export.tgz" -C . --exclude=./.git --exclude=.git git add -A # A re-run: the tag is there already. Fine if it holds these @@ -302,6 +325,20 @@ jobs: exit 1 fi + # Never an older release over a newer one: past a re-run, + # which is checked first, so an older release can be re-run, + # the tag has to be newer than every release tag there. + latest=$(git ls-remote --tags --refs origin 'refs/tags/v*' \ + | sed 's#^.*refs/tags/##' \ + | { grep -E "$semver" || true; } \ + | sort -V | tail -n 1) + + if [ -n "$latest" ] && + [ "$(printf '%s\n%s\n' "$latest" "$TAG" | sort -V | tail -n 1)" != "$TAG" ]; then + echo "::error::$REPOSITORY already has $latest, which is newer than $TAG." + exit 1 + fi + git config user.name 'github-actions[bot]' git config user.email '41898282+github-actions[bot]@users.noreply.github.com' @@ -311,5 +348,5 @@ jobs: git commit -q -m "chore(release): $TAG from $SOURCE" fi - git tag -a "$TAG" -m "$TAG from $SOURCE" + git tag -a -m "$TAG from $SOURCE" -- "$TAG" git push --atomic origin main "refs/tags/$TAG" diff --git a/README.md b/README.md index 0fe832c..e90e0c4 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ An exported kit gets the package back in its own source, with the imports rewrit `@keyringjs/ui-vue` is the same for Vue kits, the Nuxt kit's for now: `@keyringjs/ui-react`'s primitives, app components, layouts, Keyring's settings components and the challenge's factors, written for Vue with [shadcn-vue](https://www.shadcn-vue.com) on Reka UI, with the same markup and classes, so it matches the same screenshots. Its files have Vue's names, and are imported with their extension (`@keyringjs/ui-vue/components/InputError.vue`, `@keyringjs/ui-vue/composables/useAppearance`, `@keyringjs/ui-vue/button`). Its adapter, `@keyringjs/ui-vue/adapter`, is the part of Inertia's Vue API the components use (`Link`, `Form`, `usePage()`, `router`), which an app provides with `provideAdapter()`, and its components import Keyring's helpers from `@keyringjs/keyring/vue`, which the Nuxt kit points at its headless entry (see [its README](kits/nuxt/README.md#shared-components)). The Nuxt kit's export gets them in `frontend/app`. -What stays in the Inertia app: the pages, `pages.test.tsx`, the toaster (`resources/js/components/ui/sonner.tsx`, which shows Inertia's flashed toasts), `toUrl()` (`resources/js/lib/url.ts`), the header layout and its header, and the delete-account card. `components.json` (and the `paths` in `tsconfig.json`) point shadcn's CLI at the package, so `npx shadcn add ` writes new primitives to `packages/ui-react/src/components/ui`. An exported kit gets the usual `components.json` back, pointing at its own `resources/js/components/ui`. +What stays in the Inertia app: the pages, `pages.test.tsx`, the toaster (`resources/js/components/ui/sonner.tsx`, which shows Inertia's flashed toasts), `toUrl()` and `sameOriginUrl()` (`resources/js/lib/url.ts`, which the export keeps in place of the package's own `lib/url.ts`, so the two have to match), the header layout and its header, and the delete-account card. `components.json` (and the `paths` in `tsconfig.json`) point shadcn's CLI at the package, so `npx shadcn add ` writes new primitives to `packages/ui-react/src/components/ui`. An exported kit gets the usual `components.json` back, pointing at its own `resources/js/components/ui`. ## The demo @@ -140,13 +140,13 @@ The output is what the kit's repository gets: a complete Laravel app with no wor 1. Copies every file git tracks, as it is in the working tree (clean, unless `--allow-dirty`; untracked files never come along), except `kits/`, `packages/`, `bin/`, `.github/` and the kit's `exclude` list. Symlinks stay symlinks. 2. Inlines the workspace packages the kit uses: copies their files (minus the entry's `exclude`) into the app, rewrites imports of them (`@keyringjs/ui-react/button` becomes `@/components/ui/button` again), and adds their dependencies to the `package.json` of the app they're inlined into. 3. Copies the kit's own files over the result. -4. Leaves out text tagged monorepo-only: a line whose comment (`//`, `#`, `/*`, ` To see how they look, open `http://localhost:8000/emails` while running locally: a gallery of every email the app sends, Keyring's and Laravel's verification and password reset emails, each with sample content (see [Emails](#emails)). @@ -364,6 +372,8 @@ Each link signs the browser out first, then signs in or starts the sign in as on The same backend serves frontends Laravel doesn't serve, such as a TanStack Start or Nuxt app on one origin that passes everything under `/backend` on to Laravel. Set `APP_FRONTEND=headless` and `APP_URL` to the frontend's address: Laravel then renders no pages, the app's pages and Keyring's answer JSON requests with their name and props, `GET /api/me` has the shared props, and Keyring sends users to the frontend's pages. [docs/headless-api.md](docs/headless-api.md) lists the settings and every endpoint with its JSON. Inertia stays the default, and Inertia visits get what they always have. +Headless, Laravel trusts a proxy on loopback by default (`TRUSTED_PROXIES` is `127.0.0.1,::1`), since that's how the frontend's server on the same host passes on the browser's host, scheme and address. Anything else that reaches Laravel's port from loopback is believed too, so Laravel's port must only be reachable by the frontend's server (listening on `127.0.0.1`, with no tunnel or published port in front of it), or `TRUSTED_PROXIES` should be pinned to the address the frontend's server connects from. + Headless mode needs Keyring 0.4 or later, and the headless kits `@keyringjs/keyring` 0.2 or later, neither released yet. Until they are, `composer.json` stays on Keyring `^0.3`, which runs the Inertia app but not headless mode. @@ -436,7 +446,7 @@ The specs don't know which kit they drive: the paths, labels and words are the s ### Screenshots -`tests/e2e/screenshots.spec.ts` shoots every page (the guest pages, the second step and step-up, the dashboard and the settings pages, a held user's security page, and the pages emailed links open), in light and dark, at a desktop's and a phone's width. Every kit compares against the same screenshots, in `tests/e2e/screenshots`, made from the Inertia kit, so a page that drifts from the other kits' fails. They're made with the browser in Playwright's Docker image (`mcr.microsoft.com/playwright:v-noble`), the one CI's browser job runs in, so they match to the pixel: no more than 50 pixels of a page may differ, which one missing control or changed word is far over. Only times and IP addresses are masked, each on its own (`components/keyring/details.tsx` puts them in a `