Skip to content

Commit

Permalink
Let us then try publishing?
Browse files Browse the repository at this point in the history
  • Loading branch information
joshaber committed May 25, 2016
1 parent 5c9d90e commit bcd04b3
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 6 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ addons:
packages:
- g++-4.8

cache:
directories:
- node_modules

install:
- npm install

Expand All @@ -32,6 +36,6 @@ script:
- npm run build:prod
- npm test

cache:
directories:
- node_modules
deploy:
provider: script
script: node script/publish
7 changes: 5 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
environment:
nodejs_version: "5"

cache:
- node_modules

branches:
only:
- master
Expand All @@ -20,5 +23,5 @@ build_script:
test_script:
- npm test

cache:
- node_modules
deploy_script:
- node script/publish
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"webpack-hot-middleware": "^2.10.0"
},
"devDependencies": {
"aws-sdk": "^2.3.15",
"babel-core": "^6.7.6",
"babel-loader": "^6.2.4",
"babel-plugin-react-transform": "^2.0.2",
Expand Down
2 changes: 1 addition & 1 deletion script/package
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if (process.platform === 'darwin') {
}

function packageOSX () {
const dest = path.join(distPath, '..', `${productName}.zip`)
const dest = distInfo.getOSXZipPath()
fs.removeSync(dest)

cp.execSync(`ditto -ck --keepParent ${distPath}/${productName}.app ${dest}`)
Expand Down
77 changes: 77 additions & 0 deletions script/publish
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)
}
})
})
}

0 comments on commit bcd04b3

Please sign in to comment.