Skip to content

Commit

Permalink
Added --force-next-version command line param.
Browse files Browse the repository at this point in the history
  • Loading branch information
boocmp committed Dec 4, 2024
1 parent 6842fe2 commit 227c690
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 43 deletions.
9 changes: 7 additions & 2 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ const createTableIfNotExists = (endpoint, region) => {
})
}

const getNextVersion = (endpoint, region, id, contentHash) => {
const getNextVersion = (endpoint, region, id, contentHash, forceNextVersion) => {
const dynamodb = createDynamoDBInstance(endpoint, region)
const params = {
ExpressionAttributeValues: {
Expand All @@ -546,7 +546,10 @@ const getNextVersion = (endpoint, region, id, contentHash) => {
}
return dynamodb.send(new QueryCommand(params)).then((data) => {
if (data.Items.length === 1 && data.Items[0].Version.S !== '') {
if (data.Items[0].ContentHash !== undefined && data.Items[0].ContentHash.S !== undefined && data.Items[0].ContentHash.S === contentHash) {
if (!forceNextVersion &&
data.Items[0].ContentHash !== undefined &&
data.Items[0].ContentHash.S !== undefined &&
data.Items[0].ContentHash.S === contentHash) {
// return no next version if the content hash matches the last cached value
return undefined
} else {
Expand Down Expand Up @@ -602,6 +605,8 @@ const addCommonScriptOptions = (command) => {
'Second private key for generating publisher proof. Useful when rotating keys.')
.option('-vc, --verified-contents-key <file>',
'Private key for generating verified_contents.json.')
.option('-f, --force-next-version',
'Force to create the new version of the component even if content is not changed.')

// If setup locally, use --endpoint http://localhost:8000
.option('-e, --endpoint <endpoint>', 'DynamoDB endpoint to connect to', '')
Expand Down
7 changes: 4 additions & 3 deletions scripts/ntp-sponsored-images/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ function getManifestPath (regionPlatform) {
}

const generateCRXFile = (binary, endpoint, region, keyDir, platformRegion,
componentData, publisherProofKey, publisherProofKeyAlt) => {
componentData, publisherProofKey, publisherProofKeyAlt, forceNextVersion) => {
const rootBuildDir = path.join(path.resolve(), 'build', 'ntp-sponsored-images')
const stagingDir = path.join(rootBuildDir, 'staging', platformRegion)
const crxOutputDir = path.join(rootBuildDir, 'output')
mkdirp.sync(stagingDir)
mkdirp.sync(crxOutputDir)
util.getNextVersion(endpoint, region, componentData.id).then((version) => {
util.getNextVersion(endpoint, region, componentData.id, forceNextVersion).then((version) => {
const crxFile = path.join(crxOutputDir, `ntp-sponsored-images-${platformRegion}.crx`)
// Desktop private key file names do not have the -desktop suffix, but android has -android
const privateKeyFile = path.join(keyDir, `ntp-sponsored-images-${platformRegion.replace('-desktop', '')}.pem`)
Expand Down Expand Up @@ -88,6 +88,7 @@ util.createTableIfNotExists(commander.endpoint, commander.region).then(() => {
generateManifestFile(platformRegion, componentData)
generateCRXFile(commander.binary, commander.endpoint, commander.region,
keyDir, platformRegion, componentData,
commander.publisherProofKey, commander.publisherProofKeyAlt)
commander.publisherProofKey, commander.publisherProofKeyAlt,
commander.forceNextVersion)
}
})
6 changes: 4 additions & 2 deletions scripts/packageAdBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const processComponent = (
publisherProofKeyAlt,
localRun,
verifiedContentsKey,
forceNextVersion,
componentSubdir) => {
const originalManifest = getOriginalManifest(componentSubdir)

Expand Down Expand Up @@ -94,7 +95,7 @@ const processComponent = (
}

if (!localRun) {
util.getNextVersion(endpoint, region, id, contentHash).then((version) => {
util.getNextVersion(endpoint, region, id, contentHash, forceNextVersion).then((version) => {
if (version !== undefined) {
postNextVersionWork(componentSubdir, keyDir, publisherProofKey,
publisherProofKeyAlt, binary, localRun, version, contentHash, verifiedContentsKey)
Expand Down Expand Up @@ -127,7 +128,8 @@ const processJob = async (commander, keyDir) => {
commander.publisherProofKey,
commander.publisherProofKeyAlt,
commander.localRun,
commander.verifiedContentsKey))
commander.verifiedContentsKey,
commander.forceNextVersion))
}

util.installErrorHandlers()
Expand Down
7 changes: 4 additions & 3 deletions scripts/packageBraveAdsResourcesComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,14 @@ const getOriginalManifest = (locale) => {
}

const generateCRXFile = (binary, endpoint, region, keyDir, publisherProofKey,
publisherProofKeyAlt, componentData) => {
publisherProofKeyAlt, forceNextVersion, componentData) => {
const locale = componentData.locale
const rootBuildDir = path.join(path.resolve(), 'build', 'user-model-installer')
const stagingDir = path.join(rootBuildDir, 'staging', locale)
const crxOutputDir = path.join(rootBuildDir, 'output')
mkdirp.sync(stagingDir)
mkdirp.sync(crxOutputDir)
util.getNextVersion(endpoint, region, componentData.id).then((version) => {
util.getNextVersion(endpoint, region, componentData.id, forceNextVersion).then((version) => {
const crxFile = path.join(crxOutputDir, `user-model-installer-${locale}.crx`)
const privateKeyFile = path.join(keyDir, `user-model-installer-${locale}.pem`)
stageFiles(locale, version, stagingDir)
Expand Down Expand Up @@ -304,5 +304,6 @@ util.createTableIfNotExists(commander.endpoint, commander.region).then(() => {
getComponentDataList().forEach(
generateCRXFile.bind(null, commander.binary, commander.endpoint,
commander.region, keyDir,
commander.publisherProofKey, commander.publisherProofKeyAlt))
commander.publisherProofKey, commander.publisherProofKeyAlt,
commander.forceNextVersion))
})
6 changes: 3 additions & 3 deletions scripts/packageBravePlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ const postNextVersionWork = (key, publisherProofKey, publisherProofKeyAlt, binar
console.log(`Generated ${crxFile} with version number ${version}`)
}

const processDATFile = (binary, endpoint, region, key, publisherProofKey, publisherProofKeyAlt, localRun) => {
const processDATFile = (binary, endpoint, region, key, publisherProofKey, publisherProofKeyAlt, localRun, forceNextVersion) => {
const originalManifest = getOriginalManifest()
const parsedManifest = util.parseManifest(originalManifest)
const id = util.getIDFromBase64PublicKey(parsedManifest.key)

if (!localRun) {
util.getNextVersion(endpoint, region, id).then((version) => {
util.getNextVersion(endpoint, region, id, forceNextVersion).then((version) => {
postNextVersionWork(key, publisherProofKey, publisherProofKeyAlt,
binary, localRun, version)
})
Expand All @@ -57,7 +57,7 @@ const processDATFile = (binary, endpoint, region, key, publisherProofKey, publis

const processJob = (commander, keyParam) => {
processDATFile(commander.binary, commander.endpoint, commander.region,
keyParam, commander.publisherProofKey, commander.publisherProofKeyAlt, commander.localRun)
keyParam, commander.publisherProofKey, commander.publisherProofKeyAlt, commander.localRun, commander.forceNextVersion)
}

util.installErrorHandlers()
Expand Down
7 changes: 4 additions & 3 deletions scripts/packageIpfsDaemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ const getOriginalManifest = (platform) => {
}

const packageIpfsDaemon = (binary, endpoint, region, os, arch, key,
publisherProofKey, publisherProofKeyAlt) => {
publisherProofKey, publisherProofKeyAlt, forceNextVersion) => {
const platform = `${os}-${arch}`
const originalManifest = getOriginalManifest(platform)
const parsedManifest = util.parseManifest(originalManifest)
const id = util.getIDFromBase64PublicKey(parsedManifest.key)

util.getNextVersion(endpoint, region, id).then((version) => {
util.getNextVersion(endpoint, region, id, forceNextVersion).then((version) => {
const stagingDir = path.join('build', 'ipfs-daemon-updater', platform)
const ipfsDaemon = getIpfsDaemonPath(os, arch)
const crxOutputDir = path.join('build', 'ipfs-daemon-updater')
Expand Down Expand Up @@ -72,7 +72,8 @@ util.createTableIfNotExists(commander.endpoint, commander.region).then(() => {
for (const os of ['darwin', 'linux', 'win32']) {
for (const arch of ['amd64', 'arm64']) {
packageIpfsDaemon(commander.binary, commander.endpoint, commander.region,
os, arch, keyParam, commander.publisherProofKey, commander.publisherProofKeyAlt)
os, arch, keyParam, commander.publisherProofKey, commander.publisherProofKeyAlt,
commander.forceNextVersion)
}
}
})
6 changes: 3 additions & 3 deletions scripts/packageLeoLocalModels.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ const postNextVersionWork = (key, publisherProofKey, publisherProofKeyAlt, binar
console.log(`Generated ${crxFile} with version number ${version}`)
}

const processDATFile = (binary, endpoint, region, key, publisherProofKey, publisherProofKeyAlt, localRun) => {
const processDATFile = (binary, endpoint, region, key, publisherProofKey, publisherProofKeyAlt, localRun, forceNextVersion) => {
const originalManifest = getOriginalManifest()
const parsedManifest = util.parseManifest(originalManifest)
const id = util.getIDFromBase64PublicKey(parsedManifest.key)

if (!localRun) {
util.getNextVersion(endpoint, region, id).then((version) => {
util.getNextVersion(endpoint, region, id, forceNextVersion).then((version) => {
postNextVersionWork(key, publisherProofKey, publisherProofKeyAlt,
binary, localRun, version)
})
Expand All @@ -54,7 +54,7 @@ const processDATFile = (binary, endpoint, region, key, publisherProofKey, publis

const processJob = (commander, keyParam) => {
processDATFile(commander.binary, commander.endpoint, commander.region,
keyParam, commander.publisherProofKey, commander.publisherProofKeyAlt, commander.localRun)
keyParam, commander.publisherProofKey, commander.publisherProofKeyAlt, commander.localRun, commander.forceNextVersion)
}

util.installErrorHandlers()
Expand Down
6 changes: 3 additions & 3 deletions scripts/packageLocalDataFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ const postNextVersionWork = (key, publisherProofKey, publisherProofKeyAlt, binar
console.log(`Generated ${crxFile} with version number ${version}`)
}

const processDATFile = (binary, endpoint, region, key, publisherProofKey, publisherProofKeyAlt, localRun) => {
const processDATFile = (binary, endpoint, region, key, publisherProofKey, publisherProofKeyAlt, localRun, forceNextVersion) => {
const originalManifest = getOriginalManifest()
const parsedManifest = util.parseManifest(originalManifest)
const id = util.getIDFromBase64PublicKey(parsedManifest.key)

if (!localRun) {
util.getNextVersion(endpoint, region, id).then((version) => {
util.getNextVersion(endpoint, region, id, forceNextVersion).then((version) => {
postNextVersionWork(key, publisherProofKey, publisherProofKeyAlt,
binary, localRun, version)
})
Expand All @@ -79,7 +79,7 @@ const processDATFile = (binary, endpoint, region, key, publisherProofKey, publis

const processJob = (commander, keyParam) => {
processDATFile(commander.binary, commander.endpoint, commander.region,
keyParam, commander.publisherProofKey, commander.publisherProofKeyAlt, commander.localRun)
keyParam, commander.publisherProofKey, commander.publisherProofKeyAlt, commander.localRun, commander.forceNextVersion)
}

util.installErrorHandlers()
Expand Down
7 changes: 4 additions & 3 deletions scripts/packageNTPBackgroundImagesComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ const generateManifestFile = (publicKey) => {
}

const generateCRXFile = (binary, endpoint, region, componentID, privateKeyFile,
publisherProofKey, publisherProofKeyAlt) => {
publisherProofKey, publisherProofKeyAlt, forceNextVersion) => {
const rootBuildDir = path.join(path.resolve(), 'build', 'ntp-background-images')
const stagingDir = path.join(rootBuildDir, 'staging')
const crxOutputDir = path.join(rootBuildDir, 'output')
mkdirp.sync(stagingDir)
mkdirp.sync(crxOutputDir)
util.getNextVersion(endpoint, region, componentID).then((version) => {
util.getNextVersion(endpoint, region, componentID, forceNextVersion).then((version) => {
const crxFile = path.join(crxOutputDir, 'ntp-background-images.crx')
stageFiles(version, stagingDir)
util.generateCRXFile(binary, crxFile, privateKeyFile, publisherProofKey,
Expand All @@ -64,5 +64,6 @@ util.createTableIfNotExists(commander.endpoint, commander.region).then(() => {
const [publicKey, componentID] = ntpUtil.generatePublicKeyAndID(privateKeyFile)
generateManifestFile(publicKey)
generateCRXFile(commander.binary, commander.endpoint, commander.region,
componentID, privateKeyFile, commander.publisherProofKey, commander.publisherProofKeyAlt)
componentID, privateKeyFile, commander.publisherProofKey, commander.publisherProofKeyAlt,
commander.forceNextVersion)
})
7 changes: 4 additions & 3 deletions scripts/packageNTPSuperReferrerComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ const getOriginalManifest = (superReferrerName) => {
}

const generateCRXFile = (binary, endpoint, region, superReferrerName,
componentID, privateKeyFile, publisherProofKey, publisherProofKeyAlt) => {
componentID, privateKeyFile, publisherProofKey, publisherProofKeyAlt, forceNextVersion) => {
const rootBuildDir = path.join(path.resolve(), 'build', 'ntp-super-referrer')
const stagingDir = path.join(rootBuildDir, 'staging', superReferrerName)
const crxOutputDir = path.join(rootBuildDir, 'output')
mkdirp.sync(stagingDir)
mkdirp.sync(crxOutputDir)
util.getNextVersion(endpoint, region, componentID).then((version) => {
util.getNextVersion(endpoint, region, componentID, forceNextVersion).then((version) => {
const crxFile = path.join(crxOutputDir, `ntp-super-referrer-${superReferrerName}.crx`)
stageFiles(superReferrerName, version, stagingDir)
util.generateCRXFile(binary, crxFile, privateKeyFile, publisherProofKey,
Expand Down Expand Up @@ -69,5 +69,6 @@ util.createTableIfNotExists(commander.endpoint, commander.region).then(() => {
generateManifestFile(commander.superReferrerName, publicKey)
generateCRXFile(commander.binary, commander.endpoint, commander.region,
commander.superReferrerName, componentID, privateKeyFile,
commander.publisherProofKey, commander.publisherProofKeyAlt)
commander.publisherProofKey, commander.publisherProofKeyAlt,
commander.forceNextVersion)
})
7 changes: 4 additions & 3 deletions scripts/packageNTPSuperReferrerMappingTableComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ const getOriginalManifest = () => {
}

const generateCRXFile = (binary, endpoint, region, componentID, privateKeyFile,
publisherProofKey, publisherProofKeyAlt) => {
publisherProofKey, publisherProofKeyAlt, forceNextVersion) => {
const rootBuildDir = path.join(path.resolve(), 'build', 'ntp-super-referrer', 'mapping-table')
const stagingDir = path.join(rootBuildDir, 'staging')
const crxOutputDir = path.join(rootBuildDir, 'output')
mkdirp.sync(stagingDir)
mkdirp.sync(crxOutputDir)
util.getNextVersion(endpoint, region, componentID).then((version) => {
util.getNextVersion(endpoint, region, componentID, forceNextVersion).then((version) => {
const crxFile = path.join(crxOutputDir, 'ntp-super-referrer-mapping-table.crx')
stageFiles(version, stagingDir)
util.generateCRXFile(binary, crxFile, privateKeyFile, publisherProofKey,
Expand All @@ -67,5 +67,6 @@ util.createTableIfNotExists(commander.endpoint, commander.region).then(() => {
const [publicKey, componentID] = ntpUtil.generatePublicKeyAndID(privateKeyFile)
generateManifestFile(publicKey)
generateCRXFile(commander.binary, commander.endpoint, commander.region,
componentID, privateKeyFile, commander.publisherProofKey, commander.publisherProofKeyAlt)
componentID, privateKeyFile, commander.publisherProofKey, commander.publisherProofKeyAlt,
commander.forceNextVersion)
})
7 changes: 4 additions & 3 deletions scripts/packagePlaylist.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ const stageFiles = util.stageDir.bind(
getOriginalManifest())

const generateCRXFile = (binary, endpoint, region, componentID, privateKeyFile,
publisherProofKey, publisherProofKeyAlt) => {
publisherProofKey, publisherProofKeyAlt, forceNextVersion) => {
const rootBuildDir = path.join(path.resolve(), 'build', 'playlist')
const stagingDir = path.join(rootBuildDir, 'staging')
const crxOutputDir = path.join(rootBuildDir, 'output')
mkdirp.sync(stagingDir)
mkdirp.sync(crxOutputDir)
util.getNextVersion(endpoint, region, componentID).then((version) => {
util.getNextVersion(endpoint, region, componentID, forceNextVersion).then((version) => {
const crxFile = path.join(crxOutputDir, 'playlist.crx')
stageFiles(version, stagingDir)
util.generateCRXFile(binary, crxFile, privateKeyFile, publisherProofKey,
Expand All @@ -51,5 +51,6 @@ if (fs.existsSync(commander.keyFile)) {
util.createTableIfNotExists(commander.endpoint, commander.region).then(() => {
const [, componentID] = ntpUtil.generatePublicKeyAndID(privateKeyFile)
generateCRXFile(commander.binary, commander.endpoint, commander.region,
componentID, privateKeyFile, commander.publisherProofKey, commander.publisherProofKeyAlt)
componentID, privateKeyFile, commander.publisherProofKey, commander.publisherProofKeyAlt,
commander.forceNextVersion)
})
7 changes: 4 additions & 3 deletions scripts/packageTorClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ const getOriginalManifest = (platform) => {
}

const packageTorClient = (binary, endpoint, region, platform, key,
publisherProofKey, publisherProofKeyAlt) => {
publisherProofKey, publisherProofKeyAlt, forceNextVersion) => {
const originalManifest = getOriginalManifest(platform)
const parsedManifest = util.parseManifest(originalManifest)
const id = util.getIDFromBase64PublicKey(parsedManifest.key)

util.getNextVersion(endpoint, region, id).then((version) => {
util.getNextVersion(endpoint, region, id, forceNextVersion).then((version) => {
const stagingDir = path.join('build', 'tor-client-updater', platform)
const torClient = downloadTorClient(platform)
const crxOutputDir = path.join('build', 'tor-client-updater')
Expand Down Expand Up @@ -124,6 +124,7 @@ if (fs.existsSync(commander.keyFile)) {
util.createTableIfNotExists(commander.endpoint, commander.region).then(() => {
for (const platform of ['darwin', 'linux', 'linux-arm64', 'win32']) {
packageTorClient(commander.binary, commander.endpoint, commander.region,
platform, keyParam, commander.publisherProofKey, commander.publisherProofKeyAlt)
platform, keyParam, commander.publisherProofKey, commander.publisherProofKeyAlt,
commander.forceNextVersion)
}
})
7 changes: 4 additions & 3 deletions scripts/packageTorPluggableTransports.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ const getOriginalManifest = (platform) => {
return path.join('manifests', TOR_PLUGGABLE_TRANSPORTS_UPDATER, `${TOR_PLUGGABLE_TRANSPORTS_UPDATER}-${platform}-manifest.json`)
}

const packageTorPluggableTransports = (binary, endpoint, region, platform, key, publisherProofKey, publisherProofKeyAlt) => {
const packageTorPluggableTransports = (binary, endpoint, region, platform, key, publisherProofKey, publisherProofKeyAlt, forceNextVersion) => {
const originalManifest = getOriginalManifest(platform)
const parsedManifest = util.parseManifest(originalManifest)
const id = util.getIDFromBase64PublicKey(parsedManifest.key)

util.getNextVersion(endpoint, region, id).then((version) => {
util.getNextVersion(endpoint, region, id, forceNextVersion).then((version) => {
const snowflake = downloadTorPluggableTransport(platform, 'snowflake')
const obfs4 = downloadTorPluggableTransport(platform, 'obfs4')

Expand Down Expand Up @@ -94,6 +94,7 @@ if (fs.existsSync(commander.keyFile)) {
util.createTableIfNotExists(commander.endpoint, commander.region).then(() => {
for (const platform of ['darwin', 'linux', 'win32']) {
packageTorPluggableTransports(commander.binary, commander.endpoint, commander.region,
platform, keyParam, commander.publisherProofKey, commander.publisherProofKeyAlt)
platform, keyParam, commander.publisherProofKey, commander.publisherProofKeyAlt,
commander.forceNextVersion)
}
})
Loading

0 comments on commit 227c690

Please sign in to comment.