Skip to content

Commit 2e545df

Browse files
committed
Proper raw uploading to Github
1 parent 7bab929 commit 2e545df

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

packages/build/src/github.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import fs from 'fs';
2+
import { StringDecoder } from 'string_decoder';
23
import path from 'path';
34
import { Octokit } from '@octokit/rest';
45
import semver from 'semver';
6+
import Platform from './platform';
57

68
/**
79
* The repo we are working on.
@@ -16,16 +18,17 @@ const REPO = Object.freeze({
1618
*
1719
* @param {string} version - The current version.
1820
* @param {string} artifact - The artifact path.
21+
* @param {string} platform - The platform.
1922
* @param {Octokit} octokit - The octokit instance.
2023
*/
21-
const releaseToGithub = async(version: string, artifact: string, octokit: Octokit): Promise<any> => {
24+
const releaseToGithub = async(version: string, artifact: string, platform: string, octokit: Octokit): Promise<any> => {
2225
const latestRelease = await getLatestRelease(octokit);
2326
if (semver.gt(version, latestRelease.tag_name.replace('v', ''))) {
2427
// Create a new release if our version is higher than latest.
2528
const newRelease = await createRelease(version, octokit);
26-
await uploadAsset(artifact, newRelease.id, octokit);
29+
await uploadAsset(artifact, platform, newRelease.upload_url, octokit);
2730
} else {
28-
await uploadAsset(artifact, latestRelease.id, octokit);
31+
await uploadAsset(artifact, platform, latestRelease.upload_url, octokit);
2932
}
3033
};
3134

@@ -67,18 +70,22 @@ const createRelease = async(version: string, octokit: Octokit): Promise<any> =>
6770
* Upload the asset to the release.
6871
*
6972
* @param {string} artifact - The artifact.
70-
* @param {number} releaseId - The release id.
73+
* @param {string} platform - The platform.
74+
* @param {string} uploadUrl - The release endpoint.
7175
* @param {Octokit} octokit - The octokit instance.
7276
*/
73-
const uploadAsset = (artifact: string, releaseId: number, octokit: Octokit): Promise<any> => {
77+
const uploadAsset = (artifact: string, platform: string, uploadUrl: string, octokit: Octokit): Promise<any> => {
7478
const params = {
75-
...REPO,
76-
release_id: releaseId,
79+
method: 'POST',
80+
url: uploadUrl,
81+
headers: {
82+
'content-type': platform === Platform.Linux ? 'application/gzip' : 'application/zip'
83+
},
7784
name: path.basename(artifact),
78-
data: artifact
85+
data: fs.readFileSync(artifact)
7986
};
80-
console.log('mongosh: uploading asset:', artifact);
81-
return octokit.repos.uploadReleaseAsset(params).catch((e) => {
87+
console.log('mongosh: uploading asset to github:', artifact);
88+
return octokit.request(params).catch((e) => {
8289
// If the asset already exists it will throw, but we just log
8390
// it since we don't want to overwrite assets.
8491
console.error(e);

packages/build/src/release.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const release = async(config: Config) => {
4949
);
5050

5151
// - Create release and upload assets to Github.
52-
await releaseToGithub(config.version, artifact, octokit);
52+
await releaseToGithub(config.version, artifact, platform, octokit);
5353

5454
// - Publish the .deb (only on linux)
5555
// - Publish the .rpm (only on linux)

0 commit comments

Comments
 (0)