Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use github api for build #7003

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ 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'
# Used for API requests that require GitHub API scopes
NEXT_GITHUB_API_KEY: ${{ secrets.GITHUB_TOKEN }}

- name: Build Next.js (Static)
# We only run full static builds within Pull Requests. As they're not needed on `merge_group` or `push` events
Expand All @@ -115,6 +117,8 @@ 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'
# Used for API requests that require GitHub API scopes
NEXT_GITHUB_API_KEY: ${{ secrets.GITHUB_TOKEN }}

- name: Sync Orama Cloud
# We only want to sync the Orama Cloud production indexes on `push` events.
Expand Down
14 changes: 12 additions & 2 deletions apps/site/app/[locale]/next-data/api-data/route.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { deflateSync } from 'node:zlib';

import provideReleaseData from '@/next-data/providers/releaseData';
import { VERCEL_REVALIDATE } from '@/next.constants.mjs';
import { GITHUB_API_KEY, VERCEL_REVALIDATE } from '@/next.constants.mjs';
import { defaultLocale } from '@/next.locales.mjs';
import type { GitHubApiFile } from '@/types';
import { getGitHubApiDocsUrl } from '@/util/gitHubUtils';
import { parseRichTextIntoPlainText } from '@/util/stringUtils';

// Defines if we should use the GitHub API Key for the request
// based on the environment variable `GITHUB_API_KEY`
const authorizationHeaders = GITHUB_API_KEY
? { headers: { Authorization: `Bearer ${GITHUB_API_KEY}` } }
: undefined;

// Formats a pathname for an API file from Markdown file basename
const getPathnameForApiFile = (name: string, version: string) =>
`docs/${version}/api/${name.replace('.md', '.html')}`;

Expand All @@ -20,7 +27,10 @@ export const GET = async () => {
release => release.status === 'LTS'
)!;

const gitHubApiResponse = await fetch(getGitHubApiDocsUrl(versionWithPrefix));
const gitHubApiResponse = await fetch(
getGitHubApiDocsUrl(versionWithPrefix),
authorizationHeaders
);

return gitHubApiResponse.json().then((apiDocsFiles: Array<GitHubApiFile>) => {
// maps over each api file and get the download_url, fetch the content and deflates it
Expand Down
8 changes: 8 additions & 0 deletions apps/site/next.constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,11 @@ export const ORAMA_CLOUD_ENDPOINT =
* This is a public API key and can be shared publicly on the frontend.
*/
export const ORAMA_CLOUD_API_KEY = process.env.NEXT_PUBLIC_ORAMA_API_KEY || '';

/**
* A GitHub Access Token for accessing the GitHub API and not being rate-limited
* The current token is registered on the "nodejs-vercel" GitHub Account.
*
* Note: This has no NEXT_PUBLIC prefix as it should not be exposed to the Browser.
*/
export const GITHUB_API_KEY = process.env.NEXT_GITHUB_API_KEY || '';
Loading
Loading