Skip to content

Commit

Permalink
Merge pull request #428 from oaknational/rc-20241206-1
Browse files Browse the repository at this point in the history
build: release candidate
  • Loading branch information
mikeritson-oak authored Dec 11, 2024
2 parents b5060c7 + 34774b5 commit 56f6d23
Show file tree
Hide file tree
Showing 131 changed files with 3,177 additions and 1,986 deletions.
13 changes: 0 additions & 13 deletions .eslintrc.cjs

This file was deleted.

2 changes: 1 addition & 1 deletion .github/actions/ref_from_sha/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ outputs:
description: "The number of the PR if one is found"
runs:
using: "node20"
main: "index.js"
main: "index.cjs"
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
const core = require("@actions/core");
const github = require("@actions/github");

const prFromSha = require("./pr_from_sha");
const branchFromSha = require("./branch_from_sha");
const prFromSha = require("./pr_from_sha.cjs");
const branchFromSha = require("./branch_from_sha.cjs");

async function run() {
try {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const github = require("@actions/github");

const prFromSha = require("../pr_from_sha");
const branchFromSha = require("../branch_from_sha");
const prFromSha = require("../pr_from_sha.cjs");
const branchFromSha = require("../branch_from_sha.cjs");

const githubToken = process.env.GITHUB_TOKEN;

Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,15 @@ jobs:
inject-env-vars: true

- name: Run tests
run: pnpm turbo test --cache-dir=".turbo" -- --maxWorkers=33%
run: pnpm turbo test --cache-dir=".turbo" -- --maxWorkers=33% --coverage

# Run only on production branch
- name: Report coverage to SonarCloud
if: ${{ github.event.pull_request.merged == true && github.base_ref == 'production' }}
uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dsonar.javascript.lcov.reportPaths=packages/**/coverage/lcov.info,apps/nextjs/coverage/lcov.info
24 changes: 0 additions & 24 deletions apps/nextjs/.eslintrc.cjs

This file was deleted.

18 changes: 12 additions & 6 deletions apps/nextjs/jest.config.js → apps/nextjs/jest.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const { pathsToModuleNameMapper } = require("ts-jest");
const { compilerOptions } = require("./tsconfig.test.json");
import { readFile } from "fs/promises";
import { pathsToModuleNameMapper } from "ts-jest";

const tsconfig = JSON.parse(
await readFile(new URL("./tsconfig.test.json", import.meta.url)),
);

/** @type {import('ts-jest').JestConfigWithTsJest} */
const config = {
Expand All @@ -9,14 +13,15 @@ const config = {
{
tsconfig: "tsconfig.test.json",
useESM: true,
isolatedModules: true,
},
],
"^.+\\.svg$": "<rootDir>/jest.svgTransform.js",
"^.+\\.svg$": "<rootDir>/jest.svgTransform.mjs",
"^.+\\.(css|scss|png|jpg|jpeg|gif|webp|avif)$": "jest-transform-stub",
},
preset: "ts-jest/presets/default-esm",
moduleNameMapper: {
...pathsToModuleNameMapper(compilerOptions.paths, {
...pathsToModuleNameMapper(tsconfig.compilerOptions.paths, {
prefix: "<rootDir>/src/",
}),
"^(\\.{1,2}/.*)\\.js$": "$1",
Expand All @@ -29,11 +34,12 @@ const config = {
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
rootDir: ".",
resetMocks: true,
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
setupFilesAfterEnv: ["<rootDir>/jest.setup.cjs"],
collectCoverageFrom: ["src/**/*.{ts,tsx,js,jsx}"],
collectCoverage:
process.env.CI === "true" || process.env.COLLECT_TEST_COVERAGE === "true",
coverageReporters: ["lcov", "text"],
coverageDirectory: "coverage",
};

module.exports = config;
export default config;
File renamed without changes.
1 change: 1 addition & 0 deletions apps/nextjs/jest.static.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
declare module "*.svg" {
const content: any;
export default content;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
process() {
console.log("Called jest svg transform");
return { code: "module.exports = {};" };
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
3 changes: 2 additions & 1 deletion apps/nextjs/next.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// This file should be in Common JS format to be compatible with Next.js
const {
getAppVersion,
getReleaseStage,
RELEASE_STAGE_PRODUCTION,
RELEASE_STAGE_TESTING,
} = require("./scripts/build_config_helpers.js");
} = require("./scripts/build_config_helpers.cjs");
const path = require("path");

const { PHASE_PRODUCTION_BUILD, PHASE_TEST } = require("next/constants");
Expand Down
38 changes: 22 additions & 16 deletions apps/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
{
"name": "@oakai/nextjs",
"version": "0.1.0",
"version": "1.0.0",
"private": true,
"scripts": {
"build": "next build",
"build:dev": "pnpm with-env next build",
"check": "tsc --noEmit",
"clean": "rm -rf .next .turbo node_modules",
"dev": "FORCE_COLOR=1 SENTRY_SUPPRESS_TURBOPACK_WARNING=1 pnpm with-env node scripts/increase-listeners.js next dev --port 2525 --turbo | pino-pretty -C",
"dev:sentry": "FORCE_COLOR=1 pnpm with-env node scripts/increase-listeners.js next dev --port 2525 | pino-pretty -C",
"dev": "FORCE_COLOR=1 SENTRY_SUPPRESS_TURBOPACK_WARNING=1 pnpm with-env next dev --port 2525 --turbo | pino-pretty -C",
"dev:sentry": "FORCE_COLOR=1 pnpm with-env next dev --port 2525 | pino-pretty -C",
"dev-trace-deprecation": "NODE_OPTIONS=\"--trace-deprecation\" next dev --port 2525 | pino-pretty -C",
"lint": "next lint",
"lint": "eslint .",
"lint-fix": "next lint --fix",
"lint-debug": "eslint --debug .",
"start": "next start",
"type-check": "tsc --noEmit",
"test": "pnpm with-env jest --colors --config jest.config.js",
"test:seq": "pnpm with-env jest --colors --config jest.config.js --verbose --runInBand --no-cache",
"test": "pnpm with-env jest --colors --config jest.config.mjs",
"test:seq": "pnpm with-env jest --colors --config jest.config.mjs --verbose --runInBand --no-cache",
"test-e2e": "pnpm with-env playwright test",
"test-e2e-ui": "pnpm with-env playwright test --ui",
"test-e2e-ui-serve": "pnpm build && pnpm start --port 4848 --turbo",
"test-e2e-ui-built": "PORT=4848 pnpm with-env playwright test --ui",
"test-coverage": "COLLECT_TEST_COVERAGE=true pnpm with-env jest --colors --config jest.config.js --coverage",
"test-coverage": "COLLECT_TEST_COVERAGE=true pnpm with-env jest --colors --config jest.config.mjs --coverage",
"with-env": "dotenv -e ../../.env --",
"aila": "tsx scripts/aila-cli.ts",
"storybook": "dotenv -e ../../.env -- storybook dev -p 6006 --no-open",
Expand All @@ -43,14 +44,15 @@
"@oakai/api": "*",
"@oakai/core": "*",
"@oakai/db": "*",
"@oakai/eslint-config": "*",
"@oakai/exports": "*",
"@oakai/logger": "*",
"@oakai/prettier-config": "*",
"@oaknational/oak-components": "^1.50.0",
"@oaknational/oak-consent-client": "^2.1.0",
"@portabletext/react": "^3.1.0",
"@prisma/client": "5.16.1",
"@prisma/extension-accelerate": "^1.0.0",
"@prisma/client": "^5.16.1",
"@prisma/extension-accelerate": "^1.2.1",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-tooltip": "^1.0.7",
Expand Down Expand Up @@ -141,26 +143,23 @@
"@storybook/test": "^8.4.1",
"@tailwindcss/typography": "^0.5.10",
"@types/file-saver": "^2.0.6",
"@types/jest": "^29.5.12",
"@types/node": "^18.17.0",
"@types/jest": "^29.5.14",
"@types/node": "^20.9.0",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@types/styled-components": "^5.1.34",
"autoprefixer": "^10.4.16",
"avo": "^3.2.11",
"concurrently": "^8.2.2",
"dotenv-cli": "^6.0.0",
"eslint": "^8.56.0",
"eslint-config-next": "15.0.1",
"eslint-plugin-storybook": "^0.8.0",
"graphql": "^16.9.0",
"jest": "^29.7.0",
"msw": "^2.6.5",
"msw-storybook-addon": "^2.0.4",
"postcss": "^8.4.32",
"tailwindcss": "^3.3.7",
"ts-jest": "^29.1.4",
"typescript": "5.3.3",
"ts-jest": "^29.2.5",
"typescript": "5.7.2",
"web-streams-polyfill": "^4.0.0"
},
"engines": {
Expand All @@ -171,5 +170,12 @@
"workerDirectory": [
".storybook/public"
]
},
"eslintConfig": {
"extends": "@oakai/eslint-config",
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { existsSync, readFileSync } = require("fs");
* @returns {(string|null)} The SHA if found, or "no_git_state" if mid-merge, or `null` if it cannot be determined.
*/
function getLocalGitRef() {
if (existsSync("../../.git")) {
if (existsSync("../../.git/HEAD")) {
const rev = readFileSync("../../.git/HEAD")
.toString()
.trim()
Expand Down
18 changes: 0 additions & 18 deletions apps/nextjs/scripts/increase-listeners.js

This file was deleted.

1 change: 1 addition & 0 deletions apps/nextjs/scripts/preload-chat-routes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const preBuildRoutes = async (
console.log("All routes pre-built successfully");
console.timeEnd(timerId);
} catch (error) {
console.error(error);
if (retryCount < maxRetries) {
console.log(
`Retrying pre-build (attempt ${retryCount + 1} of ${maxRetries})...`,
Expand Down
1 change: 1 addition & 0 deletions apps/nextjs/src/ai-apps/lesson-planner/state/actions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-duplicate-enum-values */
import type { RateLimitInfo } from "@oakai/api/src/types";
import type { KeyStageName, SubjectName } from "@oakai/core";
import type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createOpenAIClient } from "@oakai/core/src/llm/openai";
import { aiLogger } from "@oakai/logger";
import fs from "fs/promises";
import type OpenAI from "openai";
import type { ChatCompletionCreateParamsNonStreaming } from "openai/resources";
import type { ChatCompletionCreateParamsNonStreaming } from "openai/resources/index.mjs";

const log = aiLogger("fixtures");

Expand Down
33 changes: 25 additions & 8 deletions apps/nextjs/src/app/api/cron-jobs/expired-exports/route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { drive_v3 } from "@googleapis/drive";
import { prisma } from "@oakai/db";
import { googleDrive } from "@oakai/exports/src/gSuite/drive/client";
import { aiLogger } from "@oakai/logger";
Expand Down Expand Up @@ -126,19 +127,35 @@ export async function GET(request: NextRequest) {
return new Response("Unauthorized", { status: 401 });
}

const files = await fetchExpiredExports({ folderId, daysAgo: 14 });
let files: drive_v3.Schema$File[] | null;
let hasMoreFiles = true;

if (!files || files.length === 0) {
return new Response("No expired files found", { status: 404 });
}
while (hasMoreFiles) {
files = await fetchExpiredExports({ folderId, daysAgo: 14 });

if (!files || files.length === 0) {
log.info("No expired files found.");
hasMoreFiles = false;
break;
}

const validFileIds = files.map((file) => file.id).filter(isTruthy);
const validFileIds = files.map((file) => file.id).filter(isTruthy);

if (validFileIds.length === 0) {
log.info("No valid file IDs to process.");
hasMoreFiles = false;
break;
}

await updateExpiredAtAndDelete(validFileIds);
await updateExpiredAtAndDelete(validFileIds);
}

return new Response("All expired files processed successfully.", {
status: 200,
});
} catch (error) {
Sentry.captureException(error);
log.error("An error occurred during the cron job execution:", error);
return new Response("Internal Server Error", { status: 500 });
}

return new Response(JSON.stringify({ success: true }), { status: 200 });
}
Loading

0 comments on commit 56f6d23

Please sign in to comment.