mirror of
https://github.com/cypress-io/cypress.git
synced 2026-04-23 23:49:43 -05:00
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
This commit is contained in:
@@ -11,105 +11,40 @@ Promise = require("bluebird")
|
||||
meta = require("./meta")
|
||||
la = require("lazy-ass")
|
||||
check = require("check-more-types")
|
||||
{configFromEnvOrJsonFile, filenameToShellVariable} = require('@cypress/env-or-json-file')
|
||||
uploadUtils = require("./util/upload")
|
||||
|
||||
fs = Promise.promisifyAll(fs)
|
||||
|
||||
uploadNames = {
|
||||
darwin: "osx64"
|
||||
linux: "linux64"
|
||||
win32: "win64"
|
||||
}
|
||||
|
||||
## TODO: refactor this
|
||||
# system expects desktop application to be inside a file
|
||||
# with this name
|
||||
zipName = "cypress.zip"
|
||||
|
||||
getUploadNameByOs = (os) ->
|
||||
name = uploadNames[os]
|
||||
if not name
|
||||
throw new Error("Cannot find upload name for OS #{os}")
|
||||
name
|
||||
|
||||
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')
|
||||
config
|
||||
|
||||
module.exports = {
|
||||
getPublisher: ->
|
||||
aws = @getAwsObj()
|
||||
|
||||
awspublish.create {
|
||||
httpOptions: {
|
||||
timeout: human("10 minutes")
|
||||
}
|
||||
params: {
|
||||
Bucket: aws.bucket
|
||||
}
|
||||
accessKeyId: aws.key
|
||||
secretAccessKey: aws.secret
|
||||
}
|
||||
uploadUtils.getPublisher(@getAwsObj)
|
||||
|
||||
getAwsObj: ->
|
||||
getS3Credentials()
|
||||
uploadUtils.getS3Credentials()
|
||||
|
||||
# store uploaded application in subfolders by platform and version
|
||||
# something like desktop/0.20.1/osx64/
|
||||
getUploadDirName: ({version, platform}) ->
|
||||
aws = @getAwsObj()
|
||||
osName = getUploadNameByOs(platform)
|
||||
osName = uploadUtils.getUploadNameByOs(platform)
|
||||
dirName = [aws.folder, version, osName, null].join("/")
|
||||
console.log("target directory %s", dirName)
|
||||
dirName
|
||||
|
||||
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: ({version, platform}) ->
|
||||
la(check.unemptyString(platform), "missing platform", platform)
|
||||
la(check.unemptyString(zipName), "missing zip filename")
|
||||
la(check.extension("zip", zipName),
|
||||
"zip filename should end with .zip", zipName)
|
||||
|
||||
new Promise (resolve, reject) =>
|
||||
osName = getUploadNameByOs(platform)
|
||||
|
||||
url = [konfig("cdn_url"), "desktop", version, osName, zipName].join("/")
|
||||
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()
|
||||
osName = uploadUtils.getUploadNameByOs(platform)
|
||||
url = [konfig("cdn_url"), "desktop", version, osName, zipName].join("/")
|
||||
uploadUtils.purgeCache(url)
|
||||
|
||||
createRemoteManifest: (folder, version) ->
|
||||
getUrl = (uploadOsName) ->
|
||||
|
||||
Reference in New Issue
Block a user