Skip to content

Commit 1fbd908

Browse files
authored
chore: add static builds to ci to ensure static builds are still working (#5617)
* chore: add static builds to ci to ensure static builds are still working * chore: remove unstable opt Signed-off-by: Claudio Wunder <[email protected]> * fix: attempt to use platform-specific separator --------- Signed-off-by: Claudio Wunder <[email protected]>
1 parent 660a44a commit 1fbd908

5 files changed

Lines changed: 32 additions & 13 deletions

File tree

.github/workflows/build.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ jobs:
9191
# We also use `--omit=dev` to avoid installing devDependencies as we don't need them during the build step
9292
run: npm i --no-audit --no-fund --userconfig=/dev/null --omit=dev
9393

94-
- name: Build Next.js
94+
- name: Build Next.js (ISR)
95+
# We want a ISR build on CI to ensure that regular Next.js builds work as expected.
9596
# We want to enforce that the actual `turbo@latest` package is used instead of a possible hijack from the user
9697
# the `${{ needs.base.outputs.turbo_args }}` is a string substitution happening from the base job
9798
run: npx --package=turbo@latest -- turbo build ${{ needs.base.outputs.turbo_args }}
@@ -100,9 +101,18 @@ jobs:
100101
# this should be a last resort in case by any chances the build memory gets too high
101102
# but in general this should never happen
102103
NODE_OPTIONS: '--max_old_space_size=4096'
103-
# We want to avoid having Next.js's Telemetry to kick-in during this build
104-
# See https://nextjs.org/telemetry
105-
NEXT_TELEMETRY_DISABLED: 1
104+
105+
- name: Build Next.js (Static)
106+
# We want a Static Buid on CI to ensure that the Static Exports are working as expected
107+
# This build will use the existing cache created on the previous build above (ISR)
108+
# We want to enforce that the actual `turbo@latest` package is used instead of a possible hijack from the user
109+
# the `${{ needs.base.outputs.turbo_args }}` is a string substitution happening from the base job
110+
run: npx --package=turbo@latest -- turbo deploy ${{ needs.base.outputs.turbo_args }}
111+
env:
112+
# We want to ensure we have enough RAM allocated to the Node.js process
113+
# this should be a last resort in case by any chances the build memory gets too high
114+
# but in general this should never happen
115+
NODE_OPTIONS: '--max_old_space_size=4096'
106116

107117
- name: Analyse Build
108118
id: analyse_build

next.config.mjs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ const nextConfig = {
4242
// since we pass the fully-compiled MDX page from `MDXRemote` through
4343
// a page's static props.
4444
largePageDataBytes: 128 * 100000,
45-
// We disable the bundling and tracing of some files on the Serverless & Edge Runtimes
46-
// as otherwise they would explode the bundle size (server) and the tracing time
47-
outputFileTracingExcludes: {
48-
'*': ['./public/**', 'node_modules/**/@swc/core*'],
49-
},
5045
},
5146
};
5247

next.constants.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ export const DEFAULT_LOCALE_CODE = defaultLocale.code;
9191
*/
9292
export const LEGACY_JAVASCRIPT_FILE = `${BASE_PATH}/static/js/legacyMain.js`;
9393

94+
/**
95+
* This is the current Node.js Working directory. We usually use it to resolve pathnames
96+
* relative to the content of the Node.js Website.
97+
*/
98+
export const CURRENT_WORKING_DIRECTORY = process.cwd();
99+
94100
/**
95101
* This is a list of all static routes or pages from the Website that we do not
96102
* want to allow to be statically built on our Static Export Build.

next.dynamic.mjs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ import rehypeSlug from 'rehype-slug';
1010
import { serialize } from 'next-mdx-remote/serialize';
1111
import { availableLocales } from './next.locales.mjs';
1212
import { getMarkdownFiles } from './next.helpers.mjs';
13-
import { DEFAULT_LOCALE_CODE, MD_EXTENSION_REGEX } from './next.constants.mjs';
13+
import {
14+
DEFAULT_LOCALE_CODE,
15+
MD_EXTENSION_REGEX,
16+
CURRENT_WORKING_DIRECTORY,
17+
} from './next.constants.mjs';
1418

1519
// allows us to run a glob to get markdown files based on a language folder
1620
const getPathsByLanguage = async (locale = DEFAULT_LOCALE_CODE, ignored = []) =>
17-
getMarkdownFiles(process.cwd(), `pages/${locale}`, ignored);
21+
getMarkdownFiles(CURRENT_WORKING_DIRECTORY, `pages/${locale}`, ignored);
1822

1923
/**
2024
* This method is responsible for generating a Collection of all available paths that
@@ -41,6 +45,7 @@ const getAllPaths = async () => {
4145
sourcePages.map(filename => {
4246
// remove the index.md(x) suffix from a pathname
4347
let pathname = filename.replace(MD_EXTENSION_REGEX, '');
48+
4449
// remove trailing slash for correct Windows pathing of the index files
4550
if (pathname.length > 1 && pathname.endsWith(sep)) {
4651
pathname = pathname.substring(0, pathname.length - 1);
@@ -110,7 +115,7 @@ export const getMarkdownFile = (
110115

111116
// gets the full pathname for the file (absolute path)
112117
metadata.filename = join(
113-
process.cwd(),
118+
CURRENT_WORKING_DIRECTORY,
114119
'pages',
115120
localeToUse,
116121
route.filename

pages/[...path].tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { sep } from 'node:path';
12
import Theme from '@/theme';
23
import * as nextDynamic from '@/next.dynamic.mjs';
34
import * as nextConstants from '@/next.constants.mjs';
@@ -28,7 +29,9 @@ const getRouteWrite = (pathname: string) =>
2829

2930
// This maps a pathname into an actual route object that can be used
3031
const mapPathnameToRoute = (pathname: string) => ({
31-
params: { path: pathname.split('/') },
32+
// we use a platform-specific separator to split the pathname
33+
// since we're using filepaths here and not URL paths
34+
params: { path: pathname.split(sep) },
3235
});
3336

3437
// This method receives the props from `getStaticProps` and renders/builds the Markdown

0 commit comments

Comments
 (0)