Skip to content

Commit

Permalink
chore: add static builds to ci to ensure static builds are still work…
Browse files Browse the repository at this point in the history
…ing (#5617)

* chore: add static builds to ci to ensure static builds are still working

* chore: remove unstable opt

Signed-off-by: Claudio Wunder <cwunder@gnome.org>

* fix: attempt to use platform-specific separator

---------

Signed-off-by: Claudio Wunder <cwunder@gnome.org>
  • Loading branch information
ovflowd authored Aug 10, 2023
1 parent 660a44a commit 1fbd908
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ jobs:
# We also use `--omit=dev` to avoid installing devDependencies as we don't need them during the build step
run: npm i --no-audit --no-fund --userconfig=/dev/null --omit=dev

- name: Build Next.js
- name: Build Next.js (ISR)
# We want a ISR build on CI to ensure that regular Next.js builds work as expected.
# We want to enforce that the actual `turbo@latest` package is used instead of a possible hijack from the user
# the `${{ needs.base.outputs.turbo_args }}` is a string substitution happening from the base job
run: npx --package=turbo@latest -- turbo build ${{ needs.base.outputs.turbo_args }}
Expand All @@ -100,9 +101,18 @@ jobs:
# this should be a last resort in case by any chances the build memory gets too high
# but in general this should never happen
NODE_OPTIONS: '--max_old_space_size=4096'
# We want to avoid having Next.js's Telemetry to kick-in during this build
# See https://nextjs.org/telemetry
NEXT_TELEMETRY_DISABLED: 1

- name: Build Next.js (Static)
# We want a Static Buid on CI to ensure that the Static Exports are working as expected
# This build will use the existing cache created on the previous build above (ISR)
# We want to enforce that the actual `turbo@latest` package is used instead of a possible hijack from the user
# the `${{ needs.base.outputs.turbo_args }}` is a string substitution happening from the base job
run: npx --package=turbo@latest -- turbo deploy ${{ needs.base.outputs.turbo_args }}
env:
# We want to ensure we have enough RAM allocated to the Node.js process
# this should be a last resort in case by any chances the build memory gets too high
# but in general this should never happen
NODE_OPTIONS: '--max_old_space_size=4096'

- name: Analyse Build
id: analyse_build
Expand Down
5 changes: 0 additions & 5 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ const nextConfig = {
// since we pass the fully-compiled MDX page from `MDXRemote` through
// a page's static props.
largePageDataBytes: 128 * 100000,
// We disable the bundling and tracing of some files on the Serverless & Edge Runtimes
// as otherwise they would explode the bundle size (server) and the tracing time
outputFileTracingExcludes: {
'*': ['./public/**', 'node_modules/**/@swc/core*'],
},
},
};

Expand Down
6 changes: 6 additions & 0 deletions next.constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ export const DEFAULT_LOCALE_CODE = defaultLocale.code;
*/
export const LEGACY_JAVASCRIPT_FILE = `${BASE_PATH}/static/js/legacyMain.js`;

/**
* This is the current Node.js Working directory. We usually use it to resolve pathnames
* relative to the content of the Node.js Website.
*/
export const CURRENT_WORKING_DIRECTORY = process.cwd();

/**
* This is a list of all static routes or pages from the Website that we do not
* want to allow to be statically built on our Static Export Build.
Expand Down
11 changes: 8 additions & 3 deletions next.dynamic.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import rehypeSlug from 'rehype-slug';
import { serialize } from 'next-mdx-remote/serialize';
import { availableLocales } from './next.locales.mjs';
import { getMarkdownFiles } from './next.helpers.mjs';
import { DEFAULT_LOCALE_CODE, MD_EXTENSION_REGEX } from './next.constants.mjs';
import {
DEFAULT_LOCALE_CODE,
MD_EXTENSION_REGEX,
CURRENT_WORKING_DIRECTORY,
} from './next.constants.mjs';

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

/**
* This method is responsible for generating a Collection of all available paths that
Expand All @@ -41,6 +45,7 @@ const getAllPaths = async () => {
sourcePages.map(filename => {
// remove the index.md(x) suffix from a pathname
let pathname = filename.replace(MD_EXTENSION_REGEX, '');

// remove trailing slash for correct Windows pathing of the index files
if (pathname.length > 1 && pathname.endsWith(sep)) {
pathname = pathname.substring(0, pathname.length - 1);
Expand Down Expand Up @@ -110,7 +115,7 @@ export const getMarkdownFile = (

// gets the full pathname for the file (absolute path)
metadata.filename = join(
process.cwd(),
CURRENT_WORKING_DIRECTORY,
'pages',
localeToUse,
route.filename
Expand Down
5 changes: 4 additions & 1 deletion pages/[...path].tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { sep } from 'node:path';
import Theme from '@/theme';
import * as nextDynamic from '@/next.dynamic.mjs';
import * as nextConstants from '@/next.constants.mjs';
Expand Down Expand Up @@ -28,7 +29,9 @@ const getRouteWrite = (pathname: string) =>

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

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

0 comments on commit 1fbd908

Please sign in to comment.