From cbdb0d607ab1dcd659f032aa17b6bea41e55506e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trevor=20Mu=C3=B1oz?= Date: Tue, 30 Jul 2024 10:08:43 -0400 Subject: [PATCH] Add GitHub Action for typeschecking in CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .github/workflows/run-typescript.yml | 36 ++++++++++++ .github/workflows/staging.yml | 5 +- gatsby-config.ts | 84 ++++++++++++---------------- package.json | 2 +- 4 files changed, 78 insertions(+), 49 deletions(-) create mode 100644 .github/workflows/run-typescript.yml diff --git a/.github/workflows/run-typescript.yml b/.github/workflows/run-typescript.yml new file mode 100644 index 0000000000..0633acd089 --- /dev/null +++ b/.github/workflows/run-typescript.yml @@ -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 diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index 3e7ff332f0..59f6d5fdfa 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -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 diff --git a/gatsby-config.ts b/gatsby-config.ts index d39f8ddf22..9762c4904f 100644 --- a/gatsby-config.ts +++ b/gatsby-config.ts @@ -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", @@ -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`, @@ -101,8 +102,8 @@ const config: GatsbyConfig = { `linked_sponsors`, `linked_posts`, `linked_events`, - `related_research` - ] + `related_research`, + ], }, { baseId, @@ -110,10 +111,10 @@ const config: GatsbyConfig = { tableView: `All Events`, queryName: `Events`, separateNodeType: true, - mapping: { + mapping: { excerpt: `text/markdown`, description: `text/markdown`, - image: `fileNode` + image: `fileNode`, }, tableLinks: [ `linked_research_item`, @@ -129,8 +130,8 @@ const config: GatsbyConfig = { `methods`, `disciplines`, `tags`, - `event_types` - ] + `event_types`, + ], }, { baseId, @@ -138,10 +139,7 @@ const config: GatsbyConfig = { tableView: `All Links`, queryName: `Links`, separateNodeType: true, - tableLinks: [ - `linked_research_items`, - `linked_events` - ] + tableLinks: [`linked_research_items`, `linked_events`], }, { baseId, @@ -149,22 +147,22 @@ const config: GatsbyConfig = { 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" @@ -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 @@ -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`, }, @@ -198,8 +196,8 @@ const config: GatsbyConfig = { `linked_research_as_internal`, `linked_research_as_external`, `linked_events_as_speaker`, - `linked_events_as_participant` - ] + `linked_events_as_participant`, + ], }, { baseId, @@ -207,10 +205,7 @@ const config: GatsbyConfig = { tableView: `All Groups`, queryName: `Groups`, separateNodeType: true, - tableLinks: [ - `linked_people`, - `linked_affiliations` - ] + tableLinks: [`linked_people`, `linked_affiliations`], }, { baseId, @@ -223,8 +218,8 @@ const config: GatsbyConfig = { `linked_events`, `linked_people`, `disciplines`, - `methods` - ] + `methods`, + ], }, { baseId, @@ -232,10 +227,7 @@ const config: GatsbyConfig = { tableView: `All Tags`, queryName: `Tags`, separateNodeType: true, - tableLinks: [ - `linked_research`, - `linked_events` - ] + tableLinks: [`linked_research`, `linked_events`], }, { baseId, @@ -243,10 +235,7 @@ const config: GatsbyConfig = { tableView: `All Research Types`, queryName: `ResearchTypes`, separateNodeType: true, - tableLinks: [ - `linked_research`, - `linked_events` - ] + tableLinks: [`linked_research`, `linked_events`], }, { baseId, @@ -258,8 +247,8 @@ const config: GatsbyConfig = { `linked_research`, `linked_events`, `methods`, - `disciplines` - ] + `disciplines`, + ], }, { baseId, @@ -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/*"], }, }, { @@ -323,7 +312,7 @@ const config: GatsbyConfig = { }, }, ], - pedantic: false + pedantic: false, }, }, { @@ -442,4 +431,5 @@ const config: GatsbyConfig = { ], } -export default config; \ No newline at end of file +export default config + diff --git a/package.json b/package.json index d422127789..11a4d99b2e 100644 --- a/package.json +++ b/package.json @@ -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}\"" },