Improve CI with caching and lint work (#53)

* Cache next.js build

* Add format and lint job

* Run typecheck

* FIx all TS issues

* Declare modules for images
This commit is contained in:
Samy Pessé
2023-12-20 16:07:18 +01:00
committed by GitHub
parent 2888b95b36
commit ca3ab044c3
6 changed files with 101 additions and 9 deletions
+46 -3
View File
@@ -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
@@ -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:
@@ -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
@@ -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
@@ -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')}
@@ -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> & {
@@ -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)
@@ -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];
}
+11 -3
View File
@@ -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';
@@ -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;
}
}
+26
View File
@@ -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;
}