You have tests at three levels, a JavaScript budget and two ways of deploying. All of it depends on someone remembering to run it, in the right order, every time. Continuous integration (CI) takes memory out of the equation: every change is checked the same way, on a clean machine, before it reaches the main branch. Continuous deployment (CD) takes the next step: whatever passes the checks is published without intervention, or at the push of a button.
This lesson sets up AgendaViva's pipeline using GitHub Actions as an example, explains how to keep Next.js and its dependencies up to date without fear, brings together the production checklist, and closes the course with a review of what you've learned and where to go next.
- What gets checked, and in what order
A pipeline is a pyramid lying on its side: first the cheap, fast things that fail often; then the expensive ones, which are only worth running if the earlier ones pass.
| Stage | What it catches | Approximate time | Needs |
|---|---|---|---|
Install with npm ci |
A lockfile that doesn't match | 30 s | |
typecheck |
Types, routes, PageProps |
30 s | |
lint |
React and Next.js rules | 30 s | |
test |
Pure functions, schemas, components, actions | 30 s | |
npm audit |
Known advisories in what goes to production | 10 s | Network |
test:db |
Concurrency, ownership, migrations | 1 min | PostgreSQL |
| Build | Prerendering errors, shells | 1-3 min | PostgreSQL with data |
e2e |
The whole thing in browsers | 3-5 min | The build |
| Budget | Too much JavaScript | 20 s | The server running |
| Deploy | 3-5 min | Everything above |
Remember two things from earlier lessons. next build does not check types with Turbopack or run ESLint (01-02), so a green build says nothing about them. And the build needs a database (05-02), so in CI there's a PostgreSQL service, migrated and seeded with sample data. That build checks; the one that gets deployed is made against the real data (11-04 and 11-05).
- The pipeline
# .github/workflows/check.yaml
name: Check
on:
pull_request:
push:
branches: [main]
concurrency:
group: check-${{ github.ref }}
cancel-in-progress: true # A new change on the same branch makes the previous one obsolete
permissions:
contents: read
jobs:
fast:
runs-on: ubuntu-24.04
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version-file: .nvmrc
cache: npm
- run: npm ci
- run: npm run typecheck
- run: npm run lint
- run: npm test
- run: npm audit --omit=dev --audit-level=high
full:
runs-on: ubuntu-24.04
timeout-minutes: 30
services:
postgres:
image: postgres:18
env:
POSTGRES_USER: agendaviva
POSTGRES_PASSWORD: agendaviva_local # Only exists inside this run
POSTGRES_DB: agendaviva
ports: ['5432:5432']
options: >-
--health-cmd "pg_isready -U agendaviva"
--health-interval 5s --health-timeout 5s --health-retries 10
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version-file: .nvmrc
cache: npm
- run: npm ci
- name: Test databases
run: |
for db in agendaviva_test agendaviva_e2e; do
docker run --rm --network host -e PGPASSWORD=agendaviva_local postgres:18 \
createdb -h localhost -U agendaviva "$db"
done
- run: npm run test:db
- uses: actions/cache@v6
with:
path: .next/cache
key: nextjs-${{ runner.os }}-${{ hashFiles('package-lock.json') }}-${{ hashFiles('app/**', 'components/**', 'lib/**', 'actions/**') }}
restore-keys: nextjs-${{ runner.os }}-${{ hashFiles('package-lock.json') }}-
- run: npx playwright install --with-deps chromium firefox
- run: npm run e2e:all
- name: JavaScript budget
run: |
npm run e2e:server > server.log 2>&1 &
timeout 60 bash -c 'until curl -sf localhost:3100 > /dev/null; do sleep 1; done'
BASE_URL=http://localhost:3100 npm run budget
- if: failure()
uses: actions/upload-artifact@v7
with:
name: playwright-report
path: |
playwright-report/
test-results/
server.log
retention-days: 7- Two jobs in parallel. The fast one gives an answer in a couple of minutes and is usually enough to fix things; the full one takes longer and only blocks merging.
permissions: contents: read. The token the steps receive can only read the repository. What isn't granted can't be stolen through a compromised dependency..nvmrccontaining24makes the Node version the same on your machine, in the pipeline and in the image. Vitest 5 requires at least 22.12 (10-03).- The PostgreSQL service is on the same machine, reachable at
localhost:5432: the addresses in.env.e2eand intests/db/url.tswork unchanged. The databases are created with the client from the PostgreSQL image itself, without depending on what's installed on the machine. - The
.next/cachecache follows the documentation's recipe: the key changes with the dependencies and with the code, and if only the code changed, it starts from the previous one. Without it, Next.js warns that it found no cache and builds from scratch. e2e:allmigrates, seeds, builds withEXPOSE_TESTING_API=1and runs. That build is for testing and is never deployed (10-04).- Reports, only on failure, and for a few days: they may contain screenshots with test data and the server log.
retries: 1in CI (10-04): a test that passes on the second attempt gets flagged. Look at the report every now and then.
Pin third-party actions by their commit hash (uses: action@<sha> # v7.0.1) instead of by the tag, which its author can move. GitHub's official ones are safer, and even so the practice costs nothing: Dependabot updates the hashes too.
2.1. Making it impossible to skip
A pipeline that can be ignored will be ignored. In the repository settings, protect main: both jobs must pass, the change must be up to date with the branch, and someone other than the author must approve it. No exceptions for administrators. If there's ever a real rush, the procedure is to fix it quickly, not to skip the gate.
- Deployment
# .github/workflows/check.yaml (continued, inside jobs)
deploy:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: [fast, full]
runs-on: ubuntu-24.04
timeout-minutes: 20
environment: production
concurrency:
group: production
cancel-in-progress: false # Never cut off a deployment halfway
steps:
- name: Deploy to the server
env:
SSH_KEY: ${{ secrets.SSH_KEY }}
SERVER_FINGERPRINT: ${{ secrets.SERVER_FINGERPRINT }}
run: |
install -m 700 -d ~/.ssh
printf '%s\n' "$SSH_KEY" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
printf '%s\n' "$SERVER_FINGERPRINT" > ~/.ssh/known_hosts
ssh [email protected] "./scripts/deploy.sh ${{ github.sha }}"environment: productionlets you require a person to approve each deployment and keeps its secrets there, out of sight of the checking jobs. To begin with, with approval; once there's trust, without it.- The final build happens on the server, against the real data, with the script from 11-05. The CI machine has no access to the production database, and it's better if it stays that way.
- The server's fingerprint is pinned. Without
known_hosts, the firstsshwould accept any machine claiming to be yours. - The key can only deploy. In the server's
authorized_keys, thecommand="…"option restricts it to running the script, and thedeployuser has no permissions beyond Docker's in that directory, which aren't few: keep an eye on it. - The identifier is the commit hash, which only contains digits and letters: it can be interpolated into the command with no risk of injection. With a commit title or a branch name, never.
On a managed platform, the repository integration deploys every change on its own. Protecting main is still the guarantee: only what could be merged reaches production. Previews are deployed before the checks finish, which is why they mustn't have access to anything real (11-04).
For whatever goes wrong afterwards, one more step in the script: a smoke test against the public address (the home page, an event page, /api/health/ready) and, if it fails, an automatic rollback to the previous version. Start by doing it by hand.
- Upgrading
Next.js publishes patch releases often, a minor every few weeks and a major once a year. The three kinds call for different handling:
| Kind | Example | What it can break | How |
|---|---|---|---|
| Patch | 16.4.5 → 16.4.6 | In theory, nothing | Same day if it's a security fix; otherwise, with the weekly group |
| Minor | 16.4 → 16.5 | Experimental behavior, new warnings | Read the notes, a branch, the full pipeline |
| Major | 16 → 17 | Whatever the migration guide says | Planned, with codemods |
npx next --version # The one that's running
npm outdated next react react-dom # What's available
# Patch within the same minor: npm reads 16.4 as "the latest 16.4.x"
npm install [email protected] [email protected] @next/[email protected] @next/[email protected]
# Minor or major: upgrades and offers the relevant code transformations
npx next upgrade- The family's packages go together.
@next/playwrightmust be on the same major version as Next.js (10-04), and it's best foreslint-config-nextand@next/envto match. - The codemods (
npx @next/codemod <transform> <path>) rewrite code that changes mechanically: that's howmiddleware.tswas renamed toproxy.tsin 16. You run them on a clean branch, read the result and run the pipeline. They have--dryto see what they would do. - Major upgrades have their own guide in the documentation. 05-06 told what it took to get to Cache Components; 17 will turn it on by default, and AgendaViva already uses it, so that part won't affect it.
- Read the notes for every minor, looking for anything you use that's experimental: in our case,
serverActions.bodySizeLimit,exposeTestingApiInProductionBuildand@next/playwright. Stable features shouldn't break in a minor; experimental ones can.
The documentation also offers an upgrade assisted by a coding agent, also experimental. Whatever the tool, the safety net is the same: the tests. If upgrading is scary, the problem isn't the version, it's the missing tests.
4.1. Security patch day
08-06 explained why you need to be prepared and what to do on that day. What the pipeline adds is that the procedure fits in a short while:
- Branch,
npm install [email protected](or whatever version the advisory says), change, merge. - The full pipeline, without skipping anything: about ten minutes.
- The deployment.
- Check the version that's running, not the repository's:
Advisories target a specific minor line. Since July 2026, Next.js publishes its security patches in batches with an announced date, and the December one will be released on the 16.5 line, as mentioned in 08-06. Anyone still on 16.4 that day will have to take two steps at once: a minor and a patch. That's the practical reason for not falling behind on minors, even if they bring nothing you care about.
4.2. Dependencies
# .github/dependabot.yml
version: 2
updates:
- package-ecosystem: npm
directory: /
schedule: { interval: weekly }
cooldown:
default-days: 7 # A freshly published version waits a week
groups:
next:
patterns: ['next', '@next/*', 'eslint-config-next', 'react', 'react-dom']
tests:
patterns: ['vitest', '@vitest/*', 'vite', '@playwright/test', '@testing-library/*', 'jsdom']
opentelemetry:
patterns: ['@opentelemetry/*']
- package-ecosystem: github-actions
directory: /
schedule: { interval: weekly }
- package-ecosystem: docker
directory: /
schedule: { interval: weekly }- Groups: what has to go together arrives in a single change. Next.js and React, for example, or the OpenTelemetry packages, whose versions depend on one another (10-05).
- The cooldown reduces the risk of installing a compromised version before anyone finds out; several supply chain attacks were detected within hours. It doesn't affect security updates, which arrive as soon as they exist.
- Docker too: the Node base image and the PostgreSQL one receive operating system patches. An image that isn't rebuilt for six months piles up vulnerabilities even if the code doesn't change.
- One dependency fewer is one update fewer. Before adding one, the question from 10-02: what would you have to write to not need it?
A ground rule: Dependabot changes are reviewed every week, as a fixed task. When they pile up, they get merged without being read or closed without being merged, and both are worse than not having it.
- Production checklist
This list sums up the course from the point of view of launch day. Each line points to where it was explained.
Configuration
NEXT_PUBLIC_SITE_URLwith the public domain andALLOW_INDEXING=1, at build time (09-04, 11-04).- No testing variables:
EXPOSE_TESTING_API,QUERY_DELAY_MS(10-04). - Different secrets per environment, with a rotation plan (07-03).
NEXT_SERVER_ACTIONS_ENCRYPTION_KEYfixed if there's more than one instance; the image, private (08-06, 11-05).
Security
- The entry points table from 08-06 up to date, with the actions from 11-02 and 11-03.
- CSP, HSTS and the other headers checked with
curlin production (08-05). __Host-andSecureon the session cookie; HTTPS everywhere.npm auditwith no high-severity advisories in what goes to production; Next.js on the latest patch.- External review done (11-01).
Data
- Migrations applied and compatible with the previous version (11-04).
- Daily backups, encrypted, off the machine and restored at least once (11-05).
- Read-only role for building; PostgreSQL not exposed.
- Retention periods and privacy policy approved (11-01).
Performance
- The
next buildtable matching the matrix from 11-01: no public route inƒby accident. - Budget passing; LCP measured on a real phone (10-01, 10-02).
- The event page streams in chunks through everything in front of it (04-04, 11-05).
Operations
- Health checks: an internal one in Docker and an external one every minute (10-05).
- Alerts: errors, latency, bookings at zero, unsent notifications, missing backups (10-05, 11-02).
- Scheduled tasks working, with their log (07-04, 11-04, 11-05).
- Rollback rehearsed; you know what it doesn't undo (11-04).
- A page saying what to do for each alert, and who responds.
robots.txtandsitemap.xmlwith the right domain;noindexonly where it belongs (09-04).
It's gone over before launch and every time something big changes. If a line can't be checked off, you write down why, and who accepted it.
- What you've built
You started with a question: what does Next.js add to React? Eleven modules later, the answer is in AgendaViva:
| Module | What AgendaViva has thanks to it |
|---|---|
| 1 and 2 | A route map with layouts, groups, parameters, loading and error states, and an intercepted quick view |
| 3 | Server by default, small client islands and a data layer that can't reach the browser |
| 4 | Data from PostgreSQL and from an API, without waterfalls, streamed in chunks |
| 5 | A shell served instantly, data with its own lifetime and tags, and precise invalidation |
| 6 | Forms that work without JavaScript, validate on the server and don't lose what was typed |
| 7 | A public API, signed webhooks, a proxy, post-response work and tasks |
| 8 | Revocable sessions, authorization next to the data and defense in layers |
| 9 | Its own look, optimized images and fonts, metadata and structured data |
| 10 | Measurements, a budget, tests at three levels and observability |
| 11 | A complete product, deployed in two ways and with a routine to maintain it |
More than the APIs, which will change, you take away a handful of ideas that outlive the versions:
- Every piece of data has its moment: at build time, on revalidation, during the request. Deciding which is half the design.
- The boundary between server and client is a network boundary: whatever crosses it gets paid for and exposed.
- Security sits next to the data, not in the screens.
- What we owe someone is written in the transaction; the rest can come later.
- A cache without written invalidation is a bug postponed.
- If you don't measure it, you don't know; if you haven't seen it fail, you haven't tested it.
- Where to go next
| If you're interested in… | Next step | Starting point in the course |
|---|---|---|
| Reaching more people | Finish the languages branch and measure whether it pays off |
09-05 |
| Client performance | Try the React Compiler on a branch, measuring before and after | 10-01 |
| Large applications | Several applications under one domain (multi-zones), monorepos | 01-03 |
| Real time | Server-sent events or WebSockets in a separate service | 07-01 |
| Long-running jobs | A real queue, on PostgreSQL or managed | 07-04, 11-02 |
| Platforms | Writing or studying an adapter with the public API | 11-04 |
| React under the hood | The Server Components protocol and the payload | 03-01 |
| Accessibility | Testing with people who use screen readers | 09-01, 10-04 |
Three habits are worth more than any row in the table:
- Read the documentation for the version you use. Every page has a Markdown version and a last-updated date. Many tutorials describe the model before Cache Components; now you know how to recognize them (05-06).
- Follow the Next.js blog and its security advisories, and the release notes for each React version.
- Build something else. A different project, with other constraints, puts what you thought you understood to the test. AgendaViva's decisions were good for AgendaViva; for a shop, an internal dashboard or a blog they'd be different, and now you know how to reason about them.
Common Mistakes and Tips
- A pipeline that can be skipped, or that takes so long people avoid it.
- Building in CI and believing the types have been checked.
- Deploying the test build.
- Broad default permissions in the jobs, and production secrets visible to everyone.
- Third-party actions by tag, unpinned.
- Flaky tests retried silently.
- Upgrading everything at once every six months.
- Ignoring minors until a security patch forces you to jump several.
- Base images that never get rebuilt.
- Merging automatic updates without reading them, or leaving them to rot.
- A checklist nobody goes over after launch.
Exercises
Exercise 1: a failure that only happens in the pipeline
full fails in e2e:all with "The test database name must end in _test"… only in CI. On your machine, everything passes. Explain the most likely cause and the fix.
Solution
The message is thrown by tests/db/url.ts, which runs in Vitest's db project, not in Playwright. Something is running database tests where they don't belong: most likely npm test or the Playwright configuration is picking up files from tests/db/, or someone has defined TEST_DATABASE_URL as a repository or job variable pointing to agendaviva_e2e. On your machine that variable doesn't exist and the default value is used, which ends correctly.
Fix: don't define that variable globally in the pipeline, and check that Playwright's testDir is ./e2e and that Vitest's db project only includes tests/db/. The name check has done its job: without it, the integration test would have emptied the end-to-end flow's database, and the error would have been far more confusing.
Exercise 2: a minor with a surprise
16.5 comes out. Dependabot opens the change with the next group, the pipeline fails at the build with a new error on /events, and the other stages pass. Describe the procedure, without staying on 16.4 indefinitely.
Solution
- Read the error and the release notes: they almost always say what changed and which codemod fixes it.
- Reproduce locally with the same version and
next build --debug-prerender(05-01), which gives readable stack traces. - Decide whose it is. If the error points to something our code was doing wrong and used to get away with, fix the code: it's a gift. If it's a Next.js bug, look for it in their issues and comment with a minimal example.
- In the meantime, keep 16.4 up to date with patches, write the reason down in the change and set a date to review it. Ignore the group in Dependabot for that specific version, not for all of them.
- Don't disable the failing check or add
instant = falseto get out of a jam without understanding why (05-01).
The case isn't rare, and that's why minors are done when they arrive: with only one version of distance, the error has a culprit and some notes to read.
Exercise 3: the final review
Before launch, go over the list from section 5 for your own AgendaViva. Choose the three boxes you couldn't check off today, and for each one write what's missing, how much it would cost and what would happen if you launched anyway.
Solution
It's an exercise without a single solution; what's assessed is the honesty of the result. A typical answer from someone finishing the course:
- Restored backups. Two hours are missing: a clean machine, the script and a stopwatch. Launching without it means not knowing whether the four-hour RTO is four hours or two days.
- External security review. Days and budget are missing. Launching without it means accepting that the only review was done by whoever wrote the code; it can be mitigated by opening to a small group first.
- Approved privacy policy. It doesn't depend on you and can take weeks. Without it you do not launch: processing personal data without informing people isn't a technical risk you can accept, it's a breach of the law.
The third one shows that not all boxes weigh the same. Knowing which one can be postponed with a written-down risk and which one prevents launch is exactly the judgment this course set out to leave you with.
Conclusion
Continuous integration checks every change the same way, on a clean machine and in order of cost: types, rules, tests, database, build, browsers and budget. Continuous deployment publishes whatever passes, with separate credentials and a gate nobody can skip. Upgrading stops being scary when the tests are reliable and the changes small: patches on the same day, minors when they arrive, majors with their guide. And the checklist turns the course into a routine you repeat.
AgendaViva started as a home page with an in-memory array and ends as an application that reads and writes securely, is served almost entirely from a shell, notifies the people it should, measures itself, is tested, is deployed in two ways and maintains itself every week. What matters isn't having written all that code, but knowing why each piece is where it is. With that, you can read the documentation for the next version, understand what changes and decide what to do in your own projects. This is the end of the Next.js course; what you build from here on is yours.
