Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Hotfixes #50

Closed
wants to merge 5 commits into from
Closed
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
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ jobs:
args: deploy --only functions:testFunction
env:
GCP_SA_KEY: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_UNITY_CI_VERSIONS }}'

- name: Call Test Function
run: curl -f -s -S -X POST https://testfunction-wbe4ukn6tq-ey.a.run.app

- name: Cleanup Firebase Test
uses: w9jds/firebase-action@v13.10.2
if: always()
with:
args: functions:delete testFunction --force
env:
Expand All @@ -86,6 +91,7 @@ jobs:
GCP_SA_KEY: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_UNITY_CI_VERSIONS }}'
- name: Cleanup Firebase Test
uses: w9jds/firebase-action@v13.10.2
if: always()
with:
args: functions:delete testFunction --force
env:
Expand Down
33 changes: 30 additions & 3 deletions functions/src/api/testFunction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { onRequest, Request } from 'firebase-functions/v2/https';
import { Response } from 'express-serve-static-core';
import { defineSecret } from 'firebase-functions/params';
import { scrapeVersions } from '../logic/ingestRepoVersions/scrapeVersions';
import { Discord } from '../service/discord';

const discordToken = defineSecret('DISCORD_TOKEN');
const githubPrivateKeyConfigSecret = defineSecret('GITHUB_PRIVATE_KEY');
Expand All @@ -9,14 +11,39 @@ const internalToken = defineSecret('INTERNAL_TOKEN');

export const testFunction = onRequest(
{
// Passing secrets so that test deployments verify that the secrets are correctly set.
// Passing all secrets so that test deployments verify that the secrets are correctly set.
secrets: [
discordToken,
githubPrivateKeyConfigSecret,
githubClientSecretConfigSecret,
internalToken,
],
},
// eslint-disable-next-line @typescript-eslint/no-empty-function
async (request: Request, response: Response) => {},
async (request: Request, response: Response) => {
// Run all non-sensitive functions to verify that the deployment is working.
const discordClient = new Discord();
let info = 'Ok';
let code = 200;

try {
await discordClient.init(discordToken.value());

const versions = await scrapeVersions(
githubPrivateKeyConfigSecret.value(),
githubClientSecretConfigSecret.value(),
);

if (versions.length === 0) {
info = 'No versions were found.';
code = 500;
}
} catch (error: any) {
info = error.message;
code = 500;
} finally {
await discordClient.disconnect();
}

response.status(code).send(info);
},
);
1 change: 1 addition & 0 deletions functions/src/config/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const settings = {
github: {
auth: {
appId: 84327,
installationId: 12321333,
clientId: 'Iv1.fa93dce6a47c9357',
},
},
Expand Down