forked from desktop/desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
91 additions
and
6 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
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,77 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict' | ||
|
||
let branchName = '' | ||
if (process.platform === 'darwin') { | ||
branchName = process.env.TRAVIS_BRANCH | ||
} else if (process.platform === 'win32') { | ||
branchName = process.env.APPVEYOR_REPO_BRANCH | ||
} | ||
|
||
if (!/release.*/.test(branchName)) { | ||
process.exit(0) | ||
} | ||
|
||
const fs = require('fs') | ||
const cp = require('child_process') | ||
const AWS = require('aws-sdk') | ||
const distInfo = require('./dist-info') | ||
|
||
console.log('Packaging…') | ||
cp.execSync('npm run package') | ||
|
||
const sha = cp.execSync('git rev-parse HEAD').toString().substr(0, 6) | ||
|
||
console.log('Uploading…') | ||
|
||
if (process.platform === 'darwin') { | ||
const name = `${distInfo.getProductName()}.zip` | ||
upload(name, distInfo.getOSXZipPath()) | ||
.then(url => { | ||
console.log(`Uploaded ${name} to ${url}`) | ||
}) | ||
.catch(e => { | ||
console.error(`Uploading ${name} failed: ${e}`) | ||
process.exit(1) | ||
}) | ||
} else if (process.platform === 'win32') { | ||
const name = `${distInfo.getProductName()}.msi` | ||
upload(name, distInfo.getWindowsInstallerPath()) | ||
.then(url => { | ||
console.log(`Uploaded ${name} to ${url}`) | ||
}) | ||
.catch(e => { | ||
console.error(`Uploading ${name} failed: ${e}`) | ||
process.exit(1) | ||
}) | ||
} else { | ||
console.error(`I dunno how to publish a release for ${process.platform} :(`) | ||
process.exit(1) | ||
} | ||
|
||
function upload (assetName, assetPath) { | ||
const s3Info = {accessKeyId: process.env.S3_KEY, secretAccessKey: process.env.S3_SECRET} | ||
const s3 = new AWS.S3(s3Info) | ||
|
||
const bucket = process.env.S3_BUCKET | ||
const key = `releases/${distInfo.getVersion()}-${sha}/${assetName}` | ||
const url = `https://s3.amazonaws.com/${bucket}/${key}` | ||
|
||
const uploadParams = { | ||
Bucket: bucket, | ||
ACL: 'public-read', | ||
Key: key, | ||
Body: fs.createReadStream(assetPath) | ||
} | ||
|
||
return new Promise((resolve, reject) => { | ||
s3.upload(uploadParams, (error, data) => { | ||
if (error) { | ||
reject(error) | ||
} else { | ||
resolve(url) | ||
} | ||
}) | ||
}) | ||
} |