This repository demonstrates how to fix BUILD_ID in Next.js applications (v14, v15, v16) to enable consistent artifact comparison across builds. By setting a custom generateBuildId function, you can control the build ID using environment variables.
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
generateBuildId: async () => {
return process.env.CI_BUILD_ID || null;
},
};
export default nextConfig;/** @type {import('next').NextConfig} */
const nextConfig = {
generateBuildId: async () => {
return process.env.CI_BUILD_ID || null;
},
};
export default nextConfig;Diff Viewer Repo: https://github.com/Himenon/diff-artifacts-example-diff-viewer
name: Build and Compare Artifacts on Pull Request
on:
pull_request:
jobs:
build:
# ...
steps:
# some build steps
- uses: Himenon/diff-artifact/[email protected]
with:
path: |
apps/nextjs14-project/.next
apps/nextjs15-project/.next
apps/nextjs16-project/.next
diff-artifacts:
needs: build
# ...
permissions:
pull-requests: write
contents: read
actions: read
steps:
# Setup for pre-push-shell command
- name: Diff Artifacts
uses: Himenon/diff-artifact/[email protected]
with:
app-id: ${{ secrets.APP_ID }}
app-private-key: ${{ secrets.APP_PRIVATE_KEY }}
diff-viewer-owner: "Himenon"
diff-viewer-repo-name: "diff-artifacts-example-diff-viewer"
gitignore-patterns: |
node_modules
cache
trace
trace-build
# Needs Setup clone git repository, pnpm and install oxfmt
pre-push-shell: "pnpm exec oxfmt"name: "Close DIFF_VIEWER_REPO PRs on PR close"
on:
pull_request:
types:
- closed
jobs:
close-diff-viewer-pr:
name: Close diff viewer PR
runs-on: ubuntu-slim
timeout-minutes: 3
steps:
- uses: Himenon/diff-artifact/[email protected]
with:
app-id: ${{ secrets.APP_ID }}
app-private-key: ${{ secrets.APP_PRIVATE_KEY }}
diff-viewer-owner: Himenon
diff-viewer-repo-name: diff-artifacts-example-diff-viewername: Build & Push Diff Artifact
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
# some build steps ...
- uses: Himenon/diff-artifact/[email protected]
with:
path: |
apps/nextjs14-project/.next
apps/nextjs15-project/.next
apps/nextjs16-project/.next