Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Add multi-channel support to updateBrowser.js. Pull common code int…
Browse files Browse the repository at this point in the history
…o `common.js`

Fixes brave/browser-laptop#11795

Auditors: @aekeus
  • Loading branch information
bsclifton committed Nov 20, 2017
1 parent dde3e2b commit 74ee8ea
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 36 deletions.
19 changes: 10 additions & 9 deletions bin/updateBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ var _ = require('underscore')
var util = require('util')
var semver = require('semver')

var channelData = require('../src/common').channelData
var platformData = require('../src/common').platformData
const {channelData, platformData, getChannelName} = require('../src/common')
var nope = require('../src/common').nope

var args = require('yargs')
Expand Down Expand Up @@ -46,8 +45,8 @@ var preview = !args.release

const BASE_URL = process.env.BASE_URL || 'https://brave-download.global.ssl.fastly.net/multi-channel/releases'

const OSX_TEMPLATE = BASE_URL + '/CHANNEL/VERSION/osx/Brave-VERSION.zip'
const LINUX64_TEMPLATE = BASE_URL + '/CHANNEL/VERSION/linux64/Brave.tar.bz2'
const OSX_TEMPLATE = BASE_URL + '/CHANNEL/VERSION/osx/Brave{{channelName}}-VERSION.zip'
const LINUX64_TEMPLATE = BASE_URL + '/CHANNEL/VERSION/linux64/Brave{{channelName}}.tar.bz2'

This comment has been minimized.

Copy link
@aekeus

aekeus Jan 10, 2018

Member

Does Brave{{channelName}}-VERSION.zip match the name of the binary we are building now?

This comment has been minimized.

Copy link
@aekeus

aekeus Jan 10, 2018

Member

The substitution pattern {{ }} does not match the capitalization format currently in use. We should probably use one or the other.

This comment has been minimized.

Copy link
@bsclifton

bsclifton Jan 19, 2018

Author Member

Does Brave{{channelName}}-VERSION.zip match the name of the binary we are building now?

Great catch- it does 😄 Using https://github.com/brave/browser-laptop/releases/tag/v0.21.4developer as an example, it has Brave-Developer-0.21.4.zip. Below, the code will (optionally) prepend - to the channel name. This only happens if channel is NOT release channel

Comparing to release, which is in the format of Brave-0.19.139.zip. channel is blank and there is no additional preceding - character.

This comment has been minimized.

Copy link
@bsclifton

bsclifton Jan 19, 2018

Author Member

RE: the pattern; updated!


var winx64_entry = {
version: args.version,
Expand All @@ -60,13 +59,15 @@ var winia32_entry = _.clone(winx64_entry)

var osx_entry = _.clone(winx64_entry)
osx_entry.url = OSX_TEMPLATE
osx_entry.url = osx_entry.url.replace(/VERSION/g, args.version)
osx_entry.url = osx_entry.url.replace(/CHANNEL/g, args.channel)
.replace(/VERSION/g, args.version)
.replace(/CHANNEL/g, args.channel)
.replace('{{channelName}}', getChannelName('osx', args.channel))

var linux64_entry = _.clone(winx64_entry)
linux64_entry.url = LINUX64_TEMPLATE
linux64_entry.url = linux64_entry.url.replace(/VERSION/g, args.version)
linux64_entry.url = linux64_entry.url.replace(/CHANNEL/g, args.channel)
.replace(/VERSION/g, args.version)
.replace(/CHANNEL/g, args.channel)
.replace('{{channelName}}', getChannelName('linux', args.channel))

var winia32_json = JSON.parse(fs.readFileSync(path.join(dataPath, args.channel, 'winia32.json')))
var winx64_json = JSON.parse(fs.readFileSync(path.join(dataPath, args.channel, 'winx64.json')))
Expand Down Expand Up @@ -108,5 +109,5 @@ if (args.overwrite) {
} else {
console.log("Warning: nothing written to disk. Use --overwrite flag to write changes.")
}

console.log("Done")
26 changes: 3 additions & 23 deletions bin/uploadBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var async = require('async')

var AWS = require('aws-sdk')

var channelData = require('../src/common').channelData
const {channelData, getChannelName} = require('../src/common')

var args = require('yargs')
.usage('node bin/uploadBrowser.js --source=/full/directory/to/browser-laptop --send')
Expand Down Expand Up @@ -72,7 +72,7 @@ var OS_IDENTIFIER = 2
// Recipe tuples containing local relative paths to files, key locations on S3, and an os identifier
var recipes = [
// Linux
['dist/Brave.tar.bz2', 'multi-channel/releases/CHANNEL/VERSION/linux64', 'linux'],
['dist/Brave{{channelName}}.tar.bz2', 'multi-channel/releases/CHANNEL/VERSION/linux64', 'linux'],
['dist/brave{{channelName}}_VERSION_amd64.deb', 'multi-channel/releases/CHANNEL/VERSION/debian64', 'linux'],
['dist/brave{{channelName}}-VERSION.x86_64.rpm', 'multi-channel/releases/CHANNEL/VERSION/fedora64', 'linux'],

Expand Down Expand Up @@ -113,26 +113,6 @@ if (args.channel === 'dev') {
])
}

const capitalizeFirstLetter = (word) => {
const firstLetter = word.charAt(0).toUpperCase()
return firstLetter + word.slice(1)
}

const getChannelName = () => {
if (args.channel === 'dev') {
return ''
}
switch (args.os) {
case 'windows':
case 'winx64':
case 'winia32':
return capitalizeFirstLetter(args.channel) + '-'
case 'osx':
return '-' + capitalizeFirstLetter(args.channel)
}
return '-' + args.channel
}

// filter the recipes based on the 'os' command line argument
recipes = recipes.filter({
all: (recipe) => { return true },
Expand All @@ -147,7 +127,7 @@ recipes = recipes.filter({
recipes = recipes.map((recipe) => {
var dist = recipe[LOCAL_LOCATION].replace('VERSION', version)
dist = dist.replace('CHANNEL', args.channel)
dist = dist.replace('{{channelName}}', getChannelName())
dist = dist.replace('{{channelName}}', getChannelName(args.os, args.channel))

var multi = recipe[REMOTE_LOCATION].replace('VERSION', version)
multi = multi.replace('CHANNEL', args.channel)
Expand Down
29 changes: 25 additions & 4 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,31 @@ var makeVlog = function (argsv) {
return (v, ...vargs) => argsv >= v && console.log(...vargs)
}

const capitalizeFirstLetter = (word) => {
const firstLetter = word.charAt(0).toUpperCase()
return firstLetter + word.slice(1)
}

const getChannelName = (os, channel) => {
if (channel === 'dev') {
return ''
}
switch (os) {
case 'windows':
case 'winx64':
case 'winia32':
return capitalizeFirstLetter(channel) + '-'
case 'osx':
return '-' + capitalizeFirstLetter(channel)
}
return '-' + channel
}

module.exports = {
channelData: channelData,
platformData: platformData,
nope: nope,
makeVlog: makeVlog
channelData,
platformData,
nope,
makeVlog,
getChannelName
}

0 comments on commit 74ee8ea

Please sign in to comment.