-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop nodegit, use lambda-git instead (#6)
`nodegit` caused all sorts of issues, and it takes too long to compile whether locally or on CI. Even worse, due to [a bug in `serverless-webpack`](serverless-heaven/serverless-webpack#309) we have to compile it twice, which takes over 15 minutes on Travis. This PR drops `nodegit` and replaces it with a regular `git` binary [compiled specifically for AWS Lambda](https://github.com/pimterry/lambda-git). This may or may not work!
- Loading branch information
Showing
6 changed files
with
138 additions
and
185 deletions.
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
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 |
---|---|---|
|
@@ -3,22 +3,25 @@ | |
// This is how `@types/*` packages can be used in TypeScript. | ||
// | ||
// Not to be confused with https://www.npmjs.com/package/aws-lambda | ||
import { Handler } from 'aws-lambda'; // tslint:disable-line:no-implicit-dependencies | ||
import { collectReports } from './helpers/collectReports'; | ||
import { format as formatDate } from 'date-fns'; | ||
import bluebird from 'bluebird'; | ||
import NodeGit from 'nodegit'; | ||
import { join } from 'path'; | ||
import Octokit from '@octokit/rest'; | ||
import { renderReport } from './helpers/renderReport'; | ||
import bluebird from 'bluebird'; | ||
import executeCommand from '@hollowverse/common/helpers/executeCommand'; | ||
import executeCommands from '@hollowverse/common/helpers/executeCommands'; | ||
import initGit from 'lambda-git'; | ||
import prettier from 'prettier'; | ||
import shelljs from 'shelljs'; | ||
import tmp from 'tmp'; | ||
import { WebPageTestReporter } from './reporters/WebPageTestReporter'; | ||
import { Handler } from 'aws-lambda'; // tslint:disable-line:no-implicit-dependencies | ||
import { SecurityHeadersReporter } from './reporters/SecurityHeadersReporter'; | ||
import { WebPageTestReporter } from './reporters/WebPageTestReporter'; | ||
import { collectReports } from './helpers/collectReports'; | ||
import { config } from './config'; | ||
import { format as formatDate } from 'date-fns'; | ||
import { join } from 'path'; | ||
import { keyBy, mapValues } from 'lodash'; | ||
import { writeFile } from './helpers/writeFile'; | ||
import { renderReport } from './helpers/renderReport'; | ||
import { stripIndents } from 'common-tags'; | ||
import prettier from 'prettier'; | ||
import { writeFile } from './helpers/writeFile'; | ||
|
||
// tslint:disable no-console | ||
// tslint:disable-next-line:max-func-body-length | ||
|
@@ -61,81 +64,46 @@ export const runReporters: Handler = async (_event, _context) => { | |
|
||
markdownReport = prettier.format(markdownReport, { parser: 'markdown' }); | ||
|
||
const repoTempDir = tmp.dirSync().name; | ||
|
||
const credentials = (_url: string, userName: string) => { | ||
return NodeGit.Cred.sshKeyNew( | ||
userName, | ||
config.sshKeyPublicKeyPath, | ||
config.sshPrivateKeyPath, | ||
'', | ||
); | ||
}; | ||
|
||
const repoPath = tmp.dirSync().name; | ||
const branchName = `report-${dateStr}`; | ||
const repo = await NodeGit.Clone.clone( | ||
'[email protected]:hollowverse/perf-reports.git', | ||
repoTempDir, | ||
{ | ||
fetchOpts: { | ||
callbacks: { | ||
credentials, | ||
}, | ||
}, | ||
}, | ||
); | ||
|
||
const repoPath = repo.workdir(); | ||
|
||
console.log('Repo cloned to', repoPath); | ||
|
||
const filesToAdd = { | ||
'mostRecent.md': markdownReport, | ||
'mostRecent.json': JSON.stringify(rawReports, undefined, 2), | ||
}; | ||
|
||
await bluebird.map( | ||
Object.entries(filesToAdd), | ||
async ([fileName, contents]) => { | ||
await writeFile(join(repoPath, fileName), contents); | ||
await executeCommands([ | ||
async () => { | ||
if (process.env.AWS) { | ||
await initGit(); | ||
await executeCommands([ | ||
'git config --global user.name hollowbot', | ||
'git config --global user.email [email protected]', | ||
]); | ||
} | ||
}, | ||
); | ||
|
||
console.info('Report files written'); | ||
|
||
const hollowbotSignature = NodeGit.Signature.now( | ||
'hollowbot', | ||
'[email protected]', | ||
); | ||
|
||
await repo.createBranch( | ||
branchName, | ||
await repo.getReferenceCommit('HEAD'), | ||
false, | ||
hollowbotSignature, | ||
'', | ||
); | ||
|
||
await repo.checkoutBranch(branchName); | ||
|
||
await repo.createCommitOnHead( | ||
Object.keys(filesToAdd), | ||
hollowbotSignature, | ||
hollowbotSignature, | ||
`Update report file with results from ${dateStr}`, | ||
); | ||
|
||
const remote = await repo.getRemote('origin'); | ||
const ref = await repo.getReference(branchName); | ||
|
||
await NodeGit.Branch.setUpstream(ref, branchName); | ||
() => { | ||
shelljs.env.GIT_SSH_COMMAND = `ssh -i ${config.sshPrivateKeyPath}`; | ||
}, | ||
`git clone [email protected]:hollowverse/perf-reports.git ${repoPath}`, | ||
() => { | ||
shelljs.cd(repoPath); | ||
}, | ||
`git checkout -b ${branchName}`, | ||
async () => { | ||
await bluebird.map( | ||
Object.entries(filesToAdd), | ||
async ([fileName, contents]) => { | ||
await writeFile(join(repoPath, fileName), contents); | ||
}, | ||
); | ||
}, | ||
`git add ${Object.keys(filesToAdd).join(' ')}`, | ||
`git commit 'Update report file with results from ${dateStr}'`, | ||
`git push origin -u ${branchName} --force`, | ||
]); | ||
|
||
if (process.env.PUSH === 'true') { | ||
await remote.push([`+${ref.toString()}`], { | ||
callbacks: { | ||
credentials, | ||
}, | ||
}); | ||
await executeCommand(`git push origin -u ${branchName} --force`); | ||
|
||
const octokit = new Octokit(); | ||
|
||
|
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,9 +1,8 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"allowJs": false, | ||
"allowJs": true, | ||
"checkJs": false, | ||
"maxNodeModuleJsDepth": 0, | ||
"skipLibCheck": true | ||
} | ||
} |
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
Oops, something went wrong.