Created
February 21, 2018 22:32
-
-
Save klamping/e9efe83f95e23cb3a6eb1d4ef96b9a20 to your computer and use it in GitHub Desktop.
Sauce Labs Node.js Upload Script
This file contains hidden or 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
const path = require('path'); | |
const sync = require('synchronize'); | |
const request = require('request'); | |
const fs = require('fs'); | |
const { APP_PATH, SAUCE_USERNAME, SAUCE_ACCESS_KEY } = process.env; | |
const authToken = Buffer(`${SAUCE_USERNAME}:${SAUCE_ACCESS_KEY}`).toString( | |
'base64' | |
); | |
if (APP_PATH.length === 0) { | |
// eslint-disable-next-line no-console | |
console.error('APP_PATH must be set'); | |
process.exit(1); | |
} | |
const filename = path.basename(APP_PATH); | |
const options = { | |
headers: { | |
'Content-Type': 'application/octet-stream', | |
authorization: `Basic ${authToken}`, | |
}, | |
body: fs.createReadStream(APP_PATH), | |
}; | |
const sauceUrl = `https://saucelabs.com/rest/v1/storage/${SAUCE_USERNAME}/${ | |
filename | |
}?overwrite=true`; | |
sync(request, 'post'); | |
sync.fiber(() => { | |
const res = request.post(sauceUrl, options); | |
// eslint-disable-next-line no-console | |
console.log(`'${filename}' uploaded with response code ${res.statusCode}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment