Skip to content

Commit

Permalink
Improve CI with caching and lint work (#53)
Browse files Browse the repository at this point in the history
* Cache next.js build

* Add format and lint job

* Run typecheck

* FIx all TS issues

* Declare modules for images
  • Loading branch information
SamyPesse authored Dec 20, 2023
1 parent 2888b95 commit ca3ab04
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 9 deletions.
49 changes: 46 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@ jobs:
- name: Setup bun
uses: oven-sh/setup-bun@v1
- name: Install dependencies
run: bun install
run: bun install --frozen-lockfile
- name: Cache Next.js build
uses: actions/cache@v3
with:
path: |
${{ github.workspace }}/.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/bun.lockb') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/bun.lockb') }}-
- name: Build Next.js with next-on-pages
run: bun run build:cloudflare
- id: cloudflare
Expand Down Expand Up @@ -45,7 +55,7 @@ jobs:
- name: Setup bun
uses: oven-sh/setup-bun@v1
- name: Install dependencies
run: bun install
run: bun install --frozen-lockfile
- name: Run visual tests
run: bun ./tests/visual-testing.ts $DEPLOYMENT_URL
env:
Expand All @@ -64,9 +74,42 @@ jobs:
- name: Setup bun
uses: oven-sh/setup-bun@v1
- name: Install dependencies
run: bun install
run: bun install --frozen-lockfile
- name: Run visual tests
run: bun ./tests/pagespeed-testing.ts $DEPLOYMENT_URL
env:
DEPLOYMENT_URL: ${{needs.deploy.outputs.deployment_url}}
PAGESPEED_API_KEY: ${{ secrets.PAGESPEED_API_KEY }}
format:
runs-on: ubuntu-latest
name: Format
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup bun
uses: oven-sh/setup-bun@v1
- name: Install dependencies
run: bun install --frozen-lockfile
- run: bun format --check .
lint:
runs-on: ubuntu-latest
name: Lint
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup bun
uses: oven-sh/setup-bun@v1
- name: Install dependencies
run: bun install --frozen-lockfile
- run: bun lint
typecheck:
runs-on: ubuntu-latest
name: Typecheck
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup bun
uses: oven-sh/setup-bun@v1
- name: Install dependencies
run: bun install --frozen-lockfile
- run: bun typecheck
6 changes: 4 additions & 2 deletions src/components/DocumentView/Swagger/Swagger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export async function Swagger(props: BlockProps<DocumentBlockSwagger>) {
// ? api.paths?.[block.data.path]?.[block.data.method]
// : null;

const operation = {};
const operation = {
summary: '',
};

return (
<div
Expand All @@ -42,7 +44,7 @@ export async function Swagger(props: BlockProps<DocumentBlockSwagger>) {
'font-mono text-[0.625rem] font-semibold leading-6 rounded-lg px-1.5 ring-1 ring-inset ring-emerald-300 dark:ring-emerald-400/30 bg-emerald-400/10 text-emerald-500 dark:text-emerald-400',
)}
>
{block.data.method.toUpperCase()}
{block.data.method?.toUpperCase()}
</span>
<span
className={tcls('h-0.5 w-0.5 rounded-full bg-zinc-300 dark:bg-zinc-600')}
Expand Down
3 changes: 2 additions & 1 deletion src/components/DocumentView/Table/RecordCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ClassValue, tcls } from '@/lib/tailwind';

import { RecordColumnValue } from './RecordColumnValue';
import { TableRecordKV, TableViewProps } from './Table';
import { getRecordValue } from './utils';

export async function RecordCard(
props: TableViewProps<DocumentTableViewCards> & {
Expand All @@ -15,7 +16,7 @@ export async function RecordCard(
const { view, record, context, isOffscreen } = props;

const coverFile = view.coverDefinition
? (record[1].values[view.coverDefinition]?.[0] as string)
? getRecordValue<string[]>(record[1], view.coverDefinition)?.[0]
: null;
const cover = coverFile
? await resolveContentRef({ kind: 'file', file: coverFile }, context)
Expand Down
12 changes: 12 additions & 0 deletions src/components/DocumentView/Table/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ContentRef, DocumentTableRecord } from '@gitbook/api';

/**
* Get the value for a column in a record.
*/
export function getRecordValue<T extends number | string | boolean | string[] | ContentRef>(
record: DocumentTableRecord,
definitionId: string,
): T {
// @ts-ignore
return record.values[definitionId];
}
14 changes: 11 additions & 3 deletions src/lib/links.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import 'server-only';

import { RevisionPage, RevisionPageDocument, RevisionPageGroup } from '@gitbook/api';
import {
RevisionPage,
RevisionPageDocument,
RevisionPageGroup,
RevisionPageType,
} from '@gitbook/api';
import { headers } from 'next/headers';

import { getPagePath } from './pages';
Expand Down Expand Up @@ -96,9 +101,12 @@ export function pageHref(
if (pdf.includes(page.id)) {
return '#' + pagePDFContainerId(page, anchor);
} else {
if (page.type === RevisionPageType.Group) {
return '#';
}

// Use an absolute URL to the page
// TODO: we need to extend RevisionPageDocument with "urls"
return page.urls?.published || '/todo';
return page.urls.app;
}
}

Expand Down
26 changes: 26 additions & 0 deletions types/images.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
declare module '*.svg' {
const value: {
src: string;
width: number;
height: number;
};
export default value;
}

declare module '*.png' {
const value: {
src: string;
width: number;
height: number;
};
export default value;
}

declare module '*.jpg' {
const value: {
src: string;
width: number;
height: number;
};
export default value;
}

0 comments on commit ca3ab04

Please sign in to comment.