Skip to content

Commit

Permalink
Add GitHub Action for typeschecking in CI
Browse files Browse the repository at this point in the history
This involved a bunch of flaililng until I followed links from a issue
to this merged PR:
https://github.com/gatsbyjs/gatsby/pull/36405/files#diff-9b4482a4b0c980ba8a14df389f19ca9f9cc347b0e9b2e2ea54e8c516e92cb27e

Make the option in gatsby-config an object and then there is a property
to generate types on build (which is needed to use in CI).

fix: typechecking needs some files from build

fix: Adjust npm typecheck script

fix: Run build not build-pages in typescript workflow

fix: add debugging step for types in GH Actions

fix: try again to build types in CI

fix: found the option to generate types for build 🫠

fix: whoops, deleted build step by accident
  • Loading branch information
trevormunoz committed Jul 30, 2024
1 parent c1085ff commit cbdb0d6
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 49 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/run-typescript.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Run Typescript Checks

on:
pull_request:
branches: [main]
workflow_dispatch:
secrets:
AIRTABLE_TOKEN:
required: true

jobs:
typescript-check:
runs-on: ubuntu-latest
env:
AIRTABLE_TOKEN: ${{ secrets.AIRTABLE_TOKEN }}
AIRTABLE_PEOPLE_BASE_ID: appk2btw36qEO3vFo
AIRTABLE_RESEARCH_BASE_ID: appTv9J1zxqaNgBHi
AIRTABLE_EVENTS_BASE_ID: tbl6CURONRn8ML6le
AIRTABLE_POSTS_BASE_ID: appsY0VXF7pbv3mKR
AIRTABLE_MITH_BASE_ID: appMWsw8HKjjokBg2

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install dependencies and build
run: |
npm ci
npm run build
- name: Check for gatsby-types.d.ts
run: |
ls -l src/gatsby-types.d.ts
cat src/gatsby-types.d.ts | head -n 20
- name: Run TypeScript check
run: npm run check
5 changes: 4 additions & 1 deletion .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ jobs:
secrets:
AIRTABLE_TOKEN: ${{ secrets.AIRTABLE_TOKEN }}

typescript-check:
uses: ./.github/workflows/run-typescript.yml

build:
needs: test
needs: [test, typescript-check]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
84 changes: 37 additions & 47 deletions gatsby-config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import "dotenv/config";
import type { GatsbyConfig } from "gatsby";
import "dotenv/config"
import type { GatsbyConfig } from "gatsby"


const baseId = process.env.AIRTABLE_MITH_BASE_ID;
const baseId = process.env.AIRTABLE_MITH_BASE_ID
const basePath = process.env.BASEPATH

const config: GatsbyConfig = {
pathPrefix: basePath,
graphqlTypegen: true,
graphqlTypegen: {
generateOnBuild: true,
},
siteMetadata: {
title: `MITH`,
siteUrl: "https://mith.umd.edu",
Expand Down Expand Up @@ -79,7 +80,7 @@ const config: GatsbyConfig = {
tableView: `All Research Items`,
queryName: `ResearchItems`,
separateNodeType: true,
mapping: {
mapping: {
image: `fileNode`,
description: `text/markdown`,
excerpt: `text/markdown`,
Expand All @@ -101,19 +102,19 @@ const config: GatsbyConfig = {
`linked_sponsors`,
`linked_posts`,
`linked_events`,
`related_research`
]
`related_research`,
],
},
{
baseId,
tableName: `Events`,
tableView: `All Events`,
queryName: `Events`,
separateNodeType: true,
mapping: {
mapping: {
excerpt: `text/markdown`,
description: `text/markdown`,
image: `fileNode`
image: `fileNode`,
},
tableLinks: [
`linked_research_item`,
Expand All @@ -129,42 +130,39 @@ const config: GatsbyConfig = {
`methods`,
`disciplines`,
`tags`,
`event_types`
]
`event_types`,
],
},
{
baseId,
tableName: `Links`,
tableView: `All Links`,
queryName: `Links`,
separateNodeType: true,
tableLinks: [
`linked_research_items`,
`linked_events`
]
tableLinks: [`linked_research_items`, `linked_events`],
},
{
baseId,
tableName: `Partners_Sponsors`,
tableView: `All Partners & Sponsors`,
queryName: `PartnersSponsors`,
separateNodeType: true,
mapping: {
mapping: {
logo: `fileNode`,
},
tableLinks: [
`linked_research_items_as_partner`,
`linked_events_as_partner`,
`linked_research_items_as_sponsor`,
`linked_events_as_sponsor`
]
`linked_events_as_sponsor`,
],
},
{
baseId,
tableName: `People`,
tableView: `All People`,
queryName: `People`, // optionally default is false - makes all records in this table a separate node type, based on your tableView, or if not present, tableName, e.g. a table called "Fruit" would become "allAirtableFruit". Useful when pulling many airtables with similar structures or fields that have different types. See https://github.com/jbolda/gatsby-source-airtable/pull/52.
mapping: {
mapping: {
headshot: `fileNode`,
bio: `text/markdown`,
}, // optional, e.g. "text/markdown", "fileNode"
Expand All @@ -175,7 +173,7 @@ const config: GatsbyConfig = {
`linked_featured_research`,
`linked_research_as_participant`,
`events_as_participant`,
`events_as_speaker`
`events_as_speaker`,
], // optional, for deep linking to records across tables.
separateNodeType: true, // boolean, default is false, see the documentation on naming conflicts for more information
// separateMapType: false, // boolean, default is false, see the documentation on using markdown and attachments for more information
Expand All @@ -186,7 +184,7 @@ const config: GatsbyConfig = {
tableView: `All Identities`,
queryName: `Identities`,
separateNodeType: true,
mapping: {
mapping: {
linked_person_bio: `text/markdown`,
person_bio: `text/markdown`,
},
Expand All @@ -198,19 +196,16 @@ const config: GatsbyConfig = {
`linked_research_as_internal`,
`linked_research_as_external`,
`linked_events_as_speaker`,
`linked_events_as_participant`
]
`linked_events_as_participant`,
],
},
{
baseId,
tableName: `Groups`,
tableView: `All Groups`,
queryName: `Groups`,
separateNodeType: true,
tableLinks: [
`linked_people`,
`linked_affiliations`
]
tableLinks: [`linked_people`, `linked_affiliations`],
},
{
baseId,
Expand All @@ -223,30 +218,24 @@ const config: GatsbyConfig = {
`linked_events`,
`linked_people`,
`disciplines`,
`methods`
]
`methods`,
],
},
{
baseId,
tableName: `Tags`,
tableView: `All Tags`,
queryName: `Tags`,
separateNodeType: true,
tableLinks: [
`linked_research`,
`linked_events`
]
tableLinks: [`linked_research`, `linked_events`],
},
{
baseId,
tableName: `Types`,
tableView: `All Research Types`,
queryName: `ResearchTypes`,
separateNodeType: true,
tableLinks: [
`linked_research`,
`linked_events`
]
tableLinks: [`linked_research`, `linked_events`],
},
{
baseId,
Expand All @@ -258,8 +247,8 @@ const config: GatsbyConfig = {
`linked_research`,
`linked_events`,
`methods`,
`disciplines`
]
`disciplines`,
],
},
{
baseId,
Expand All @@ -273,17 +262,17 @@ const config: GatsbyConfig = {
`linked_events_methods`,
`linked_events_disciplines`,
`linked_posts_methods`,
`linked_posts_disciplines`
]
`linked_posts_disciplines`,
],
},
]
}
],
},
},
{
resolve: `gatsby-plugin-plausible`,
options: {
domain: `mith.umd.edu`,
excludePaths: ["/mith-static/*"]
excludePaths: ["/mith-static/*"],
},
},
{
Expand Down Expand Up @@ -323,7 +312,7 @@ const config: GatsbyConfig = {
},
},
],
pedantic: false
pedantic: false,
},
},
{
Expand Down Expand Up @@ -442,4 +431,5 @@ const config: GatsbyConfig = {
],
}

export default config;
export default config

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"build-pages": "BASEPATH=/mith-static gatsby build --prefix-paths",
"develop": "gatsby develop",
"test": "playwright test",
"check": "tsc --noEmit",
"check": "tsc --noEmit && tsc -p ./gatsby-node.ts",
"clean": "gatsby clean",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\""
},
Expand Down

0 comments on commit cbdb0d6

Please sign in to comment.