-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
V2 Migration #47
Merged
Merged
V2 Migration #47
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
679f933
Fix issues discovered during deployment
AndrewKahr 3c56b9d
Fix compile issues
AndrewKahr 4915b72
Fix predeploy
AndrewKahr d12b2ac
Add test function deployment
AndrewKahr 67e3480
Fix linting
AndrewKahr db20947
Fix linting
AndrewKahr e6a260e
Pin versions, add module to package type
AndrewKahr 843bd8a
Fix linting
AndrewKahr 3cfea6d
Revert to commonjs
AndrewKahr 8c1ce71
Revert module resolution
AndrewKahr 3f1171c
Fix missing token field
AndrewKahr 97c06d3
Remove token
AndrewKahr f18e100
Fix lint
AndrewKahr cd6a9c9
Revert node fetch version
AndrewKahr 0a6821a
Cleanup test function
AndrewKahr 7aba8d0
Use force delete
AndrewKahr 6d93f00
Finish migration to v2 functions. Converts to new secrets management.…
AndrewKahr 59f9247
Fix formatting
AndrewKahr 1e9e46a
Remove require
AndrewKahr abdc8e9
Read file contents
AndrewKahr cedc50a
Downgrade node-fetch
AndrewKahr 318af17
Downgrade octokit
AndrewKahr 2280e5e
Verbose secret paths
AndrewKahr 3478c03
Improve service account credential read
AndrewKahr f605d87
Force service account credential
AndrewKahr 5d4219e
Revert secret names
AndrewKahr 42782bd
Add fallback path to service account credentials
AndrewKahr a43b241
Fixes from code review. Docs on database backup/restore
AndrewKahr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,92 @@ | ||
name: 🚀 | ||
|
||
on: | ||
pull_request: { } | ||
push: { branches: [ main ] } | ||
pull_request: {} | ||
push: { branches: [main] } | ||
|
||
jobs: | ||
test: | ||
name: 🧪 Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 16 | ||
node-version: 20 | ||
cache: 'yarn' | ||
- name: install dependencies | ||
run: yarn && yarn --cwd ./functions | ||
- name: run linter | ||
run: yarn lint && yarn --cwd ./functions lint | ||
- name: run tests | ||
run: yarn test && yarn --cwd ./functions test | ||
# - name: Upload test results | ||
# uses: actions/upload-artifact@v1 | ||
# with: | ||
# name: Test results | ||
# path: "**/artifacs" | ||
# - name: Upload test results | ||
# uses: actions/upload-artifact@v1 | ||
# with: | ||
# name: Test results | ||
# path: "**/artifacs" | ||
|
||
build: | ||
name: 🛠 Build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 16 | ||
node-version: 20 | ||
cache: 'yarn' | ||
- name: install dependencies | ||
run: yarn && yarn --cwd ./functions | ||
- name: build | ||
run: yarn --cwd ./functions build | ||
|
||
testDeploy: | ||
name: Test Deploy | ||
needs: [test, build] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: 'yarn' | ||
- name: install dependencies | ||
run: yarn && yarn --cwd ./functions | ||
- name: Deploy test to Firebase | ||
uses: w9jds/firebase-action@v13.10.2 | ||
with: | ||
args: deploy --only functions:testFunction | ||
env: | ||
GCP_SA_KEY: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_UNITY_CI_VERSIONS }}' | ||
- name: Cleanup Firebase Test | ||
uses: w9jds/firebase-action@v13.10.2 | ||
with: | ||
args: functions:delete testFunction --force | ||
env: | ||
GCP_SA_KEY: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_UNITY_CI_VERSIONS }}' | ||
|
||
deploy: | ||
name: ✨ Deploy | ||
needs: [ test, build ] | ||
needs: [test, build, testDeploy] | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-node@v3 | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 16 | ||
yarn: 'yarn' | ||
node-version: 20 | ||
cache: 'yarn' | ||
- name: install dependencies | ||
run: yarn && yarn --cwd ./functions | ||
- name: Deploy to Firebase | ||
uses: w9jds/firebase-action@v11.24.1 | ||
uses: w9jds/firebase-action@v13.10.2 | ||
with: | ||
args: deploy | ||
env: | ||
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }} | ||
GCP_SA_KEY: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_UNITY_CI_VERSIONS }}' | ||
- name: Cleanup Firebase Test | ||
uses: w9jds/firebase-action@v13.10.2 | ||
with: | ||
args: functions:delete testFunction --force | ||
env: | ||
GCP_SA_KEY: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_UNITY_CI_VERSIONS }}' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to use |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,4 +68,5 @@ node_modules/ | |
# IDE | ||
.idea | ||
.vs | ||
.vscode | ||
.vscode | ||
functions/.yarn/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nodeLinker: node-modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { onRequest, Request } from 'firebase-functions/v2/https'; | ||
import { logger } from 'firebase-functions/v2'; | ||
import { Response } from 'express-serve-static-core'; | ||
import { RepoVersionInfo } from '../model/repoVersionInfo'; | ||
|
||
export const repoVersions = onRequest(async (request: Request, response: Response) => { | ||
try { | ||
const versions = await RepoVersionInfo.getAllIds(); | ||
|
||
response.send(versions); | ||
} catch (err) { | ||
logger.error(err); | ||
response.send('Oops.'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,56 @@ | ||
import { firebase, functions } from '../service/firebase'; | ||
import { Request } from 'firebase-functions/v2/https'; | ||
import { onRequest, Request } from 'firebase-functions/v2/https'; | ||
import { logger } from 'firebase-functions/v2'; | ||
import { Response } from 'express-serve-static-core'; | ||
import { Token } from '../config/token'; | ||
import { BuildFailure, CiBuilds } from '../model/ciBuilds'; | ||
import { CiJobs } from '../model/ciJobs'; | ||
import { Discord } from '../service/discord'; | ||
import { defineSecret } from 'firebase-functions/params'; | ||
|
||
export const reportBuildFailure = functions.https.onRequest(async (req: Request, res: Response) => { | ||
try { | ||
if (!Token.isValid(req.header('authorization'))) { | ||
firebase.logger.warn('unauthorised request', req.headers); | ||
res.status(403).send('Unauthorized'); | ||
return; | ||
} | ||
const discordToken = defineSecret('DISCORD_TOKEN'); | ||
const internalToken = defineSecret('INTERNAL_TOKEN'); | ||
|
||
export const reportBuildFailure = onRequest( | ||
{ secrets: [discordToken, internalToken] }, | ||
async (req: Request, res: Response) => { | ||
const discordClient = new Discord(); | ||
await discordClient.init(discordToken.value()); | ||
|
||
try { | ||
if (!Token.isValid(req.header('authorization'), internalToken.value())) { | ||
logger.warn('unauthorised request', req.headers); | ||
res.status(403).send('Unauthorized'); | ||
return; | ||
} | ||
|
||
const { body } = req; | ||
firebase.logger.debug('Build failure report incoming.', body); | ||
const { body } = req; | ||
logger.debug('Build failure report incoming.', body); | ||
|
||
const { jobId, buildId, reason } = body; | ||
const failure: BuildFailure = { reason }; | ||
const { jobId, buildId, reason } = body; | ||
const failure: BuildFailure = { reason }; | ||
|
||
await CiJobs.markFailureForJob(jobId); | ||
await CiBuilds.markBuildAsFailed(buildId, failure); | ||
await CiJobs.markFailureForJob(jobId); | ||
await CiBuilds.markBuildAsFailed(buildId, failure); | ||
|
||
firebase.logger.info('Build failure reported.', body); | ||
res.status(200).send('OK'); | ||
} catch (err: any) { | ||
const message = ` | ||
logger.info('Build failure reported.', body); | ||
res.status(200).send('OK'); | ||
} catch (err: any) { | ||
const message = ` | ||
Something went wrong while reporting a build failure | ||
${err.message} | ||
`; | ||
firebase.logger.error(message, err); | ||
await Discord.sendAlert(message); | ||
logger.error(message, err); | ||
|
||
await discordClient.sendAlert(message); | ||
|
||
if (req.body?.jobId?.toString().startsWith('dryRun')) { | ||
await CiBuilds.removeDryRunBuild(req.body.buildId); | ||
await CiJobs.removeDryRunJob(req.body.jobId); | ||
} | ||
|
||
if (req.body?.jobId?.toString().startsWith('dryRun')) { | ||
await CiBuilds.removeDryRunBuild(req.body.buildId); | ||
await CiJobs.removeDryRunJob(req.body.jobId); | ||
res.status(500).send('Something went wrong'); | ||
} | ||
|
||
res.status(500).send('Something went wrong'); | ||
} | ||
}); | ||
await discordClient.disconnect(); | ||
}, | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would want to keep it as this is a great way to ensure the project will deploy properly for the actual functions since it requires roughly the same permissions as the main functions and has been setup to require all the secrets that the other functions might use as a deploy test