Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
cache: 'yarn'

- name: Install deps
run: yarn install --immutable
run: yarn install # --immutable

- name: run linter
run: yarn lint
Expand Down
2 changes: 1 addition & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
nodeLinker: node-modules

npmRegistryServer: 'https://registry.npmjs.org/'
npmRegistryServer: "https://registry.npmjs.org/"
1 change: 0 additions & 1 deletion functions/.yarnrc.yml

This file was deleted.

10 changes: 5 additions & 5 deletions functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"test:ui": "run -T vitest --ui"
},
"engines": {
"node": "22"
"node": ">=22"
},
"main": "lib/index.js",
"dependencies": {
Expand All @@ -29,7 +29,7 @@
"lodash": "^4.17.21",
"node-fetch": "^2.7.0",
"semver": "^7.6.3",
"unity-changeset": "^3.0.1"
"unity-changeset": "3.0.1"
},
"devDependencies": {
"@octokit/types": "^13.5.0",
Expand All @@ -47,8 +47,8 @@
},
"private": true,
"volta": {
"node": "22.20.0",
"yarn": "4.10.3"
"node": "24.12.0",
"yarn": "4.12.0"
},
"packageManager": "yarn@4.10.3"
"packageManager": "yarn@4.12.0"
}
2 changes: 1 addition & 1 deletion functions/src/api/reportBuildFailure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const internalToken = defineSecret('INTERNAL_TOKEN');
export const reportBuildFailure = onRequest(
{ secrets: [discordToken, internalToken] },
async (req: Request, res: Response) => {
await Discord.init(discordToken.value());
await Discord.initSafely(discordToken.value());

try {
if (!Token.isValid(req.header('authorization'), internalToken.value())) {
Expand Down
4 changes: 1 addition & 3 deletions functions/src/api/reportNewBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const internalToken = defineSecret('INTERNAL_TOKEN');
export const reportNewBuild = onRequest(
{ secrets: [discordToken, internalToken] },
async (req: Request, res: Response) => {
await Discord.init(discordToken.value());
await Discord.initSafely(discordToken.value());

try {
if (!Token.isValid(req.header('authorization'), internalToken.value())) {
Expand Down Expand Up @@ -60,8 +60,6 @@ export const reportNewBuild = onRequest(
}

res.status(500).send('Something went wrong');

Discord.disconnect();
}
},
);
Expand Down
2 changes: 1 addition & 1 deletion functions/src/api/reportPublication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const internalToken = defineSecret('INTERNAL_TOKEN');
export const reportPublication = onRequest(
{ secrets: [discordToken, internalToken] },
async (req: Request, res: Response) => {
await Discord.init(discordToken.value());
await Discord.initSafely(discordToken.value());

try {
if (!Token.isValid(req.header('authorization'), internalToken.value())) {
Expand Down
2 changes: 1 addition & 1 deletion functions/src/api/retryBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const githubClientSecret = defineSecret('GITHUB_CLIENT_SECRET');
export const retryBuild = onRequest(
{ secrets: [discordToken, githubClientSecret, githubPrivateKey] },
async (request: Request, response: Response) => {
await Discord.init(discordToken.value());
await Discord.initSafely(discordToken.value());

try {
response.set('Content-Type', 'application/json');
Expand Down
2 changes: 1 addition & 1 deletion functions/src/api/testFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const testFunction = onRequest(
let code = 200;

try {
await Discord.init(discordToken.value());
await Discord.initSafely(discordToken.value());

const versions = await scrapeVersions(
githubPrivateKeyConfigSecret.value(),
Expand Down
2 changes: 1 addition & 1 deletion functions/src/cron/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const trigger = onSchedule(
secrets: [discordToken, githubPrivateKeyConfigSecret, githubClientSecretConfigSecret],
},
async () => {
await Discord.init(discordToken.value());
await Discord.initSafely(discordToken.value());

try {
await routineTasks(
Expand Down
2 changes: 1 addition & 1 deletion functions/src/model-triggers/editorVersionInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const onCreate = onDocumentCreated(
secrets: [discordToken],
},
async (snapshot: FirestoreEvent<QueryDocumentSnapshot | undefined>) => {
await Discord.init(discordToken.value());
await Discord.initSafely(discordToken.value());

const editorVersionInfo = snapshot.data?.data() as EditorVersionInfo;
const repoVersionInfo = await RepoVersionInfo.getLatest();
Expand Down
2 changes: 1 addition & 1 deletion functions/src/model-triggers/repoVersionInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const onCreate = onDocumentCreated(
secrets: [discordToken],
},
async (snapshot: FirestoreEvent<QueryDocumentSnapshot | undefined>) => {
await Discord.init(discordToken.value());
await Discord.initSafely(discordToken.value());

const repoVersionInfo = snapshot.data?.data() as RepoVersionInfo;
const currentRepoVersion = repoVersionInfo.version;
Expand Down
28 changes: 20 additions & 8 deletions functions/src/service/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import { settings } from '../config/settings';
let instance: ErisClient | null = null;
let instanceCount = 0;
export class Discord {
public static async initSafely(token: string) {
try {
await this.init(token);
} catch (err) {
logger.error('Failed to initialize Discord client safely:', err);
}
}

public static async init(token: string) {
if (instance) {
instanceCount += 1;
Expand Down Expand Up @@ -109,17 +117,21 @@ export class Discord {
}

public static disconnect() {
if (!instance) return;
instanceCount -= 1;
try {
if (!instance) return;
instanceCount -= 1;

if (instanceCount > 0) return;
if (instanceCount > 0) return;

instance.disconnect({ reconnect: false });
instance = null;
instance.disconnect({ reconnect: false });
instance = null;

if (instanceCount < 0) {
logger.error('Discord instance count is negative! This should not happen');
instanceCount = 0;
if (instanceCount < 0) {
logger.error('Discord instance count is negative! This should not happen');
instanceCount = 0;
}
} catch (err) {
logger.error('An error occurred while trying to disconnect from discord.', err);
}
}

Expand Down
8 changes: 0 additions & 8 deletions functions/test/unityChangesetBump.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ describe('unity-changeset bump validation', () => {
expect(SearchMode.SUPPORTED).toBeDefined();
});

it('should have expected version of unity-changeset package', async () => {
// Import package.json to check the version
const packageJson = (await import('./../package.json', { assert: { type: 'json' } })).default;

// Verify unity-changeset is in dependencies with expected version
expect(packageJson.dependencies['unity-changeset']).toMatch(/\^3\.0\.1/);
});

it('should properly import and use unity-changeset functions', async () => {
// Dynamic import to verify the module can be properly loaded after the bump
const unityChangeset = await import('unity-changeset');
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@
"@vitest/ui": "^3.2.4",
"husky": "^9.1.7",
"lint-staged": "^15.4.3",
"oxlint": "^1.22.0",
"oxlint": "^1.32.0",
"shellcheck": "^4.1.0",
"typescript": "^5.9.3",
"vitest": "^3.2.4"
},
"volta": {
"node": "22.20.0",
"yarn": "4.10.3"
"node": "24.12.0",
"yarn": "4.12.0"
},
"packageManager": "yarn@4.10.3"
"packageManager": "yarn@4.12.0"
}
Loading