From 5ca8f8040c3a3698da3faa8a9ca25ec104f276bd Mon Sep 17 00:00:00 2001 From: kirkwat Date: Wed, 24 Jan 2024 02:54:08 -0600 Subject: [PATCH] ci: update scripts --- .github/scripts/src/get-jobs.ts | 16 ++++++++-------- .github/scripts/src/queries.ts | 11 +++-------- .github/scripts/src/types/job.schema.ts | 11 ++--------- .github/workflows/get-jobs.yml | 2 ++ 4 files changed, 15 insertions(+), 25 deletions(-) diff --git a/.github/scripts/src/get-jobs.ts b/.github/scripts/src/get-jobs.ts index edb16ad..b9da416 100644 --- a/.github/scripts/src/get-jobs.ts +++ b/.github/scripts/src/get-jobs.ts @@ -3,7 +3,7 @@ import * as path from "path"; import * as core from "@actions/core"; import dotenv from "dotenv"; import { fetchJobs } from "./queries"; -import { JobInfo } from "./types/job.schema"; +import { Job } from "./types/job.schema"; import { Table } from "./types/table"; dotenv.config(); @@ -36,7 +36,7 @@ const TABLES: Table[] = [ ]; function generateMarkdownTable( - jobs: JobInfo[], + jobs: Job[], faangSalary?: boolean, interval: string = "yr" ) { @@ -69,7 +69,7 @@ function generateMarkdownTable( `${job.age}d`, ]; - if (faangSalary && "salary" in job) { + if (faangSalary && job.salary) { const salary = job.salary >= 1000 ? `${(job.salary / 1000).toFixed(0)}k` @@ -77,6 +77,9 @@ function generateMarkdownTable( const salaryCell = `$${salary}/${interval}`; row.splice(3, 0, salaryCell); + } else if (faangSalary && !job.salary) { + const salaryCell = ""; + row.splice(3, 0, salaryCell); } table += `| ${row.join(" | ")} |\n`; @@ -107,7 +110,7 @@ function updateReadme(table: string, faangTable: string, filePath: string) { fs.writeFileSync(readmePath, readmeContent); } -function sortJobs(a: JobInfo, b: JobInfo) { +function sortJobs(a: Job, b: Job) { if (a.status === "active" && b.status !== "active") { return -1; } @@ -121,10 +124,7 @@ async function main() { try { for (const table of TABLES) { const jobs = await fetchJobs(table.query); - const faangJobs = await fetchJobs( - `${table.query}_faang`, - table.faangSalary - ); + const faangJobs = await fetchJobs(`${table.query}_faang`); jobs.sort(sortJobs); faangJobs.sort(sortJobs); diff --git a/.github/scripts/src/queries.ts b/.github/scripts/src/queries.ts index 8e54302..c963278 100644 --- a/.github/scripts/src/queries.ts +++ b/.github/scripts/src/queries.ts @@ -1,6 +1,6 @@ import dotenv from "dotenv"; import { createClient } from "@supabase/supabase-js"; -import { FaangJobListSchema, JobListSchema } from "./types/job.schema"; +import { JobListSchema } from "./types/job.schema"; import { RpcName, RpcNameFaang } from "./types/rpc-name"; dotenv.config(); @@ -10,10 +10,7 @@ const supabaseKey = process.env.SUPABASE_KEY; const supabase = supabaseUrl && supabaseKey ? createClient(supabaseUrl, supabaseKey) : null; -export async function fetchJobs( - rpcName: RpcName | RpcNameFaang, - faangSalary?: boolean -) { +export async function fetchJobs(rpcName: RpcName | RpcNameFaang) { if (!supabase) { throw new Error("Supabase client is not initialized."); } @@ -25,9 +22,7 @@ export async function fetchJobs( } try { - return faangSalary - ? FaangJobListSchema.parse(data) - : JobListSchema.parse(data); + return JobListSchema.parse(data); } catch (validationError) { throw new Error(`Data validation error: [${rpcName}] ${validationError}`); } diff --git a/.github/scripts/src/types/job.schema.ts b/.github/scripts/src/types/job.schema.ts index cb7e799..b58de9b 100644 --- a/.github/scripts/src/types/job.schema.ts +++ b/.github/scripts/src/types/job.schema.ts @@ -8,16 +8,9 @@ const JobSchema = z.object({ job_url: z.string(), age: z.number(), status: z.enum(["active", "inactive"]), + salary: z.number().nullable().optional(), }); export const JobListSchema = z.array(JobSchema); -const FaangJobSchema = JobSchema.extend({ - salary: z.number(), -}); - -export const FaangJobListSchema = z.array(FaangJobSchema); - -export type JobInfo = - | z.infer - | z.infer; +export type Job = z.infer; diff --git a/.github/workflows/get-jobs.yml b/.github/workflows/get-jobs.yml index 18aaa75..93ade39 100644 --- a/.github/workflows/get-jobs.yml +++ b/.github/workflows/get-jobs.yml @@ -1,6 +1,8 @@ name: Get Jobs and Update Tables on: + push: + branches: [main] schedule: - cron: '0 12 * * *'