Skip to content

Commit 166d98c

Browse files
Merge pull request #1465 from github/robertbrignull/upload_database_stream
Use a stream when uploading database contents
2 parents cf1437a + a9337bc commit 166d98c

File tree

3 files changed

+53
-40
lines changed

3 files changed

+53
-40
lines changed

lib/database-upload.js

Lines changed: 25 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/database-upload.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/database-upload.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,34 @@ export async function uploadDatabases(
3636
const codeql = await getCodeQL(config.codeQLCmd);
3737

3838
for (const language of config.languages) {
39-
// Upload the database bundle.
40-
// Although we are uploading arbitrary file contents to the API, it's worth
41-
// noting that it's the API's job to validate that the contents is acceptable.
42-
// This API method is available to anyone with write access to the repo.
43-
const payload = fs.readFileSync(
44-
await bundleDb(config, language, codeql, language)
45-
);
4639
try {
47-
await client.request(
48-
`POST https://uploads.github.com/repos/:owner/:repo/code-scanning/codeql/databases/:language?name=:name`,
49-
{
50-
owner: repositoryNwo.owner,
51-
repo: repositoryNwo.repo,
52-
language,
53-
name: `${language}-database`,
54-
data: payload,
55-
headers: {
56-
authorization: `token ${apiDetails.auth}`,
57-
"Content-Type": "application/zip",
58-
},
59-
}
60-
);
61-
logger.debug(`Successfully uploaded database for ${language}`);
40+
// Upload the database bundle.
41+
// Although we are uploading arbitrary file contents to the API, it's worth
42+
// noting that it's the API's job to validate that the contents is acceptable.
43+
// This API method is available to anyone with write access to the repo.
44+
const bundledDb = await bundleDb(config, language, codeql, language);
45+
const bundledDbSize = fs.statSync(bundledDb).size;
46+
const bundledDbReadStream = fs.createReadStream(bundledDb);
47+
try {
48+
await client.request(
49+
`POST https://uploads.github.com/repos/:owner/:repo/code-scanning/codeql/databases/:language?name=:name`,
50+
{
51+
owner: repositoryNwo.owner,
52+
repo: repositoryNwo.repo,
53+
language,
54+
name: `${language}-database`,
55+
data: bundledDbReadStream,
56+
headers: {
57+
authorization: `token ${apiDetails.auth}`,
58+
"Content-Type": "application/zip",
59+
"Content-Length": bundledDbSize,
60+
},
61+
}
62+
);
63+
logger.debug(`Successfully uploaded database for ${language}`);
64+
} finally {
65+
bundledDbReadStream.close();
66+
}
6267
} catch (e) {
6368
console.log(e);
6469
// Log a warning but don't fail the workflow

0 commit comments

Comments
 (0)