Skip to content

Commit

Permalink
ci: update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkwat committed Jan 24, 2024
1 parent 4d6e16f commit 5ca8f80
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 25 deletions.
16 changes: 8 additions & 8 deletions .github/scripts/src/get-jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -36,7 +36,7 @@ const TABLES: Table[] = [
];

function generateMarkdownTable(
jobs: JobInfo[],
jobs: Job[],
faangSalary?: boolean,
interval: string = "yr"
) {
Expand Down Expand Up @@ -69,14 +69,17 @@ 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`
: job.salary.toString();

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`;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
11 changes: 3 additions & 8 deletions .github/scripts/src/queries.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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.");
}
Expand All @@ -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}`);
}
Expand Down
11 changes: 2 additions & 9 deletions .github/scripts/src/types/job.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof JobSchema>
| z.infer<typeof FaangJobSchema>;
export type Job = z.infer<typeof JobSchema>;
2 changes: 2 additions & 0 deletions .github/workflows/get-jobs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Get Jobs and Update Tables

on:
push:
branches: [main]
schedule:
- cron: '0 12 * * *'

Expand Down

0 comments on commit 5ca8f80

Please sign in to comment.