Files
cypress/scripts/binary/util/upload.coffee
Gleb Bahmutov 4672b569f1 Upload tar and zip (#536)
* run linter an all

* add NPM package CI job

* more steps for NPM package

* start upload NPM package

* more work on NPM package upload

* testing upload

* move purge cache to utils

* add unique binary build and upload from CI

* pass saved urls to test-binary job

* allow CYPRESS_BINARY_VERSION to be an url right away

* put uploaded urls into /tmp folder

* use explicit json filenames

* paths instead of path

* testing cypress npm and binary

* use NPM folder beta to store temp binary and package

* refactor utils

* set env vars and trigger other test projects

* only test NPM and binary on develop branch

* enable all jobs again
2017-10-01 17:01:19 -04:00

97 lines
2.8 KiB
CoffeeScript

path = require("path")
awspublish = require('gulp-awspublish')
human = require("human-interval")
la = require("lazy-ass")
check = require("check-more-types")
cp = require("child_process")
fs = require("fs")
os = require("os")
{configFromEnvOrJsonFile, filenameToShellVariable} = require('@cypress/env-or-json-file')
getS3Credentials = () ->
key = path.join('scripts', 'binary', 'support', '.aws-credentials.json')
config = configFromEnvOrJsonFile(key)
if !config
console.error('⛔️ Cannot find AWS credentials')
console.error('Using @cypress/env-or-json-file module')
console.error('and filename', key)
console.error('which is environment variable', filenameToShellVariable(key))
throw new Error('AWS config not found')
la(check.unemptyString(config.bucket), 'missing AWS config bucket')
la(check.unemptyString(config.folder), 'missing AWS config folder')
config
getPublisher = (getAwsObj = getS3Credentials) ->
aws = getAwsObj()
# console.log("aws.bucket", aws.bucket)
awspublish.create {
httpOptions: {
timeout: human("10 minutes")
}
params: {
Bucket: aws.bucket
}
accessKeyId: aws.key
secretAccessKey: aws.secret
}
hasCloudflareEnvironmentVars = () ->
check.unemptyString(process.env.CF_TOKEN) &&
check.unemptyString(process.env.CF_EMAIL) &&
check.unemptyString(process.env.CF_DOMAIN)
# depends on the credentials file or environment variables
makeCloudflarePurgeCommand = (url) ->
configFile = path.resolve(__dirname, "support", ".cfcli.yml")
if fs.existsSync(configFile)
console.log("using CF credentials file")
return "cfcli purgefile -c #{configFile} #{url}"
else if hasCloudflareEnvironmentVars()
console.log("using CF environment variables")
token = process.env.CF_TOKEN
email = process.env.CF_EMAIL
domain = process.env.CF_DOMAIN
return "cfcli purgefile -e #{email} -k #{token} -d #{domain} #{url}"
else
throw new Error("Cannot form Cloudflare purge command without credentials")
purgeCache = (url) ->
la(check.url(url), "missing url to purge", url)
new Promise (resolve, reject) =>
console.log("purging url", url)
purgeCommand = makeCloudflarePurgeCommand(url)
cp.exec purgeCommand, (err, stdout, stderr) ->
if err
console.error("Could not purge #{url}")
console.error(err.message)
return reject(err)
console.log("#purgeCache: #{url}")
resolve()
getUploadNameByOs = (osName = os.platform()) ->
uploadNames = {
darwin: "osx64"
linux: "linux64"
win32: "win64"
}
name = uploadNames[osName]
if not name
throw new Error("Cannot find upload name for OS #{osName}")
name
saveUrl = (filename) -> (url) ->
s = JSON.stringify({url})
fs.writeFileSync(filename, s)
module.exports = {
getS3Credentials,
getPublisher,
purgeCache,
getUploadNameByOs,
saveUrl
}