Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions .github/scripts/auto-approval/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { RestEndpointMethodTypes } from "@octokit/rest";

import { Octokit, RequestError } from "octokit";
import { Octokit } from "octokit";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";

Expand Down Expand Up @@ -52,12 +52,7 @@ async function main() {
pull_number: prId,
});
} catch (e) {
let s: string;
if (e instanceof RequestError) {
s = JSON.stringify(e.response?.data);
} else {
s = String(e);
}
const s = JSON.stringify(e);
throw new Error(`GitHub API Error\n\n${s}`);
}

Expand All @@ -76,12 +71,7 @@ async function main() {
event: "APPROVE",
});
} catch (e) {
let s: string;
if (e instanceof RequestError) {
s = JSON.stringify(e.response?.data);
} else {
s = String(e);
}
const s = JSON.stringify(e);
throw new Error(`GitHub API Error\n\n${s}`);
}
}
Expand Down
56 changes: 2 additions & 54 deletions .github/scripts/copy-prod-db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,60 +81,8 @@ async function main() {
--port="$DATABASE_PORT" \
--username="$DATABASE_USER" \
--dbname="$STAGING_DATABASE_NAME" \
--command="
DELETE FROM \"ApiKey\";
DELETE FROM \"Auth\";
DELETE FROM \"Club\";
DELETE FROM \"Session\";

-- Scramble non-admin user data
UPDATE \"User\"
SET
\"nickname\" = CASE
WHEN \"nickname\" IS NOT NULL THEN 'user_' || encode(gen_random_bytes(8), 'hex')
ELSE NULL
END,
\"verifyKey\" = encode(gen_random_bytes(16), 'hex'),
\"schoolEmail\" = CASE
WHEN \"schoolEmail\" IS NOT NULL THEN 'test_' || encode(gen_random_bytes(4), 'hex') || '@example.com'
ELSE NULL
END,
\"profileUrl\" = 'https://via.placeholder.com/150'
WHERE \"admin\" IS NOT TRUE;

-- Scramble admin user data
UPDATE \"User\"
SET
\"leetcodeUsername\" = NULL
WHERE \"admin\" IS TRUE;

-- Update DiscordClubMetadata for 'Patina Network'
UPDATE \"DiscordClubMetadata\" m
SET
\"guildId\" = '1389762654452580373',
\"leaderboardChannelId\" = '1417161536014778388'
FROM \"DiscordClub\" c
WHERE c.\"id\" = m.\"discordClubId\"
AND c.\"name\" = 'Patina Network';

-- Update DiscordClubMetadata for 'MHC++'
UPDATE \"DiscordClubMetadata\" m
SET
\"guildId\" = '1389762654452580373',
\"leaderboardChannelId\" = '1417161536014778388'
FROM \"DiscordClub\" c
WHERE c.\"id\" = m.\"discordClubId\"
AND c.\"name\" = 'MHC++';

-- Update DiscordClubMetadata for 'GWC - Hunter College'
UPDATE \"DiscordClubMetadata\" m
SET
\"guildId\" = '1389762654452580373',
\"leaderboardChannelId\" = '1417161536014778388'
FROM \"DiscordClub\" c
WHERE c.\"id\" = m.\"discordClubId\"
AND c.\"name\" = 'GWC - Hunter College';
"`;
--set ON_ERROR_STOP=on \
--file ./infra/clean-stg-db.SQL`;

await updateCommitStatus({
sha,
Expand Down
8 changes: 1 addition & 7 deletions .github/scripts/utils/send-message/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Octokit } from "@octokit/rest";
import { RequestError } from "octokit";

const githubToken = (() => {
const v = process.env.GH_TOKEN;
Expand Down Expand Up @@ -36,12 +35,7 @@ export async function sendMessage(
body: message,
});
} catch (e) {
let s: string;
if (e instanceof RequestError) {
s = JSON.stringify(e.response?.data);
} else {
s = String(e);
}
const s = JSON.stringify(e);
throw new Error(`GitHub API Error\n\n${s}`);
}
} catch (e) {
Expand Down
8 changes: 1 addition & 7 deletions .github/scripts/utils/update-commit-status/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Octokit } from "@octokit/rest";
import { RequestError } from "octokit";

const githubToken = (() => {
const v = process.env.GH_TOKEN;
Expand Down Expand Up @@ -44,12 +43,7 @@ export async function updateCommitStatus(options: Options) {
description: description,
});
} catch (e) {
let s: string;
if (e instanceof RequestError) {
s = JSON.stringify(e.response?.data);
} else {
s = String(e);
}
const s = JSON.stringify(e);
throw new Error(`GitHub API Error\n\n${s}`);
}
} catch (e) {
Expand Down
16 changes: 3 additions & 13 deletions .github/scripts/utils/update-pr-description.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Octokit, RequestError } from "octokit";
import { Octokit } from "octokit";

const githubToken = (() => {
const v = process.env.GH_TOKEN;
Expand Down Expand Up @@ -37,12 +37,7 @@ export async function updatePrDescriptionWithTicket(
});
body = pr.data.body;
} catch (e) {
let s: string;
if (e instanceof RequestError) {
s = JSON.stringify(e.response?.data);
} else {
s = String(e);
}
const s = JSON.stringify(e);
throw new Error(`GitHub API Error\n\n${s}`);
}

Expand Down Expand Up @@ -70,12 +65,7 @@ export async function updatePrDescriptionWithTicket(
body: newBody,
});
} catch (e) {
let s: string;
if (e instanceof RequestError) {
s = JSON.stringify(e.response?.data);
} else {
s = String(e);
}
const s = JSON.stringify(e);
throw new Error(`GitHub API Error\n\n${s}`);
}
} catch (e) {
Expand Down
6 changes: 4 additions & 2 deletions infra/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# `infra/`

> [!NOTE]
> Our staging to production migration script has been moved [here](https://github.com/tahminator/codebloom/tree/main/.github/scripts/copy-prod-db/index.ts#L28).
Comment thread
Arshadul-Monir marked this conversation as resolved.
> Our staging to production migration script is located [here](https://github.com/tahminator/codebloom/tree/main/.github/scripts/copy-prod-db/index.ts#L28).

[`clean-stg-db.SQL`](./clean-stg-db.SQL) is a SQL script used to clean and scramble staging data after copying the production database.

This directory contains the Dockerfile used to build the main Codebloom image, which is then uploaded to [hub.docker.com/r/tahminator/codebloom](https://hub.docker.com/r/tahminator/codebloom).

The image is then deployed to the [DigitalOcean App Platform](https://www.digitalocean.com/products/app-platform) see [`.do/`](../.do/) to view the DigitalOcean app spec and more detailed documentation regarding DigitalOcean and deployments.

There is a Bun Shell script which helps us manage the workflow for deployments across production and staging, which can be found at [`.github/scripts/redeploy/index.ts`](../.github/scripts/redeploy/index.ts).
There is a Bun Shell script which helps us manage the workflow for deployments across production and staging, which can be found at [`.github/scripts/redeploy/index.ts`](../.github/scripts/redeploy/index.ts).
59 changes: 59 additions & 0 deletions infra/clean-stg-db.SQL
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
BEGIN;
Comment thread
Arshadul-Monir marked this conversation as resolved.

CREATE EXTENSION IF NOT EXISTS pgcrypto;

-- Cleaning unnecesary data...
DELETE FROM "ApiKey";
DELETE FROM "Auth";
DELETE FROM "Club";
DELETE FROM "Session";

-- Scramble non-admin user data
UPDATE "User"
SET
"nickname" = CASE
WHEN "nickname" IS NOT NULL THEN 'user_' || encode(gen_random_bytes(8), 'hex')
ELSE NULL
END,
"verifyKey" = encode(gen_random_bytes(16), 'hex'),
"schoolEmail" = CASE
WHEN "schoolEmail" IS NOT NULL THEN 'test_' || encode(gen_random_bytes(4), 'hex') || '@example.com'
ELSE NULL
END,
"profileUrl" = 'https://via.placeholder.com/150'
WHERE "admin" IS NOT TRUE;

-- Scramble admin user data
UPDATE "User"
SET
"leetcodeUsername" = NULL
WHERE "admin" IS TRUE;

-- Update DiscordClubMetadata for 'Patina Network'
UPDATE "DiscordClubMetadata" m
SET
"guildId" = '1389762654452580373',
"leaderboardChannelId" = '1417161536014778388'
FROM "DiscordClub" c
WHERE c."id" = m."discordClubId"
AND c."name" = 'Patina Network';

-- Update DiscordClubMetadata for 'MHC++'
UPDATE "DiscordClubMetadata" m
SET
"guildId" = '1389762654452580373',
"leaderboardChannelId" = '1417161536014778388'
FROM "DiscordClub" c
WHERE c."id" = m."discordClubId"
AND c."name" = 'MHC++';

-- Update DiscordClubMetadata for 'GWC - Hunter College'
UPDATE "DiscordClubMetadata" m
SET
"guildId" = '1389762654452580373',
"leaderboardChannelId" = '1417161536014778388'
FROM "DiscordClub" c
WHERE c."id" = m."discordClubId"
AND c."name" = 'GWC - Hunter College';

COMMIT;