Skip to content

Commit

Permalink
chore: Update createMarFile function to include github parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
mauro-balades committed Aug 14, 2024
1 parent 6de5d11 commit 62c50b6
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 33 deletions.
113 changes: 81 additions & 32 deletions src/commands/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import { copyFile, mkdir, readdir, unlink } from 'node:fs/promises'
import { join, resolve } from 'node:path'

import { bin_name, config } from '..'
import { DIST_DIR, ENGINE_DIR, OBJ_DIR } from '../constants'
import { DIST_DIR, ENGINE_DIR, OBJ_DIR, MAR_TMP_FILE } from '../constants'
import { log } from '../log'
import {
configDispatch,
dispatch,
dynamicConfig,
windowsPathToUnix,
} from '../utils'
import { generateBrowserUpdateFiles } from './updates/browser'
import { generateBrowserUpdateFiles, getReleaseMarURL } from './updates/browser'
import { downloadFileToLocation } from '../utils/download'
import { moveSync } from 'fs-extra'

const machPath = resolve(ENGINE_DIR, 'mach')

Expand Down Expand Up @@ -138,36 +140,83 @@ function getCurrentBrandName(): string {
}

async function createMarFile(version: string, channel: string, github?: { repo: string }) {
log.info(`Creating mar file...`)
let marBinary: string = windowsPathToUnix(
join(OBJ_DIR, 'dist/host/bin', 'mar')
)
return new Promise(async (resolve, reject) => {
log.info(`Creating mar file...`)
let marBinary: string = windowsPathToUnix(
join(OBJ_DIR, 'dist/host/bin', 'mar')
)

if (process.platform == 'win32') {
marBinary += '.exe'
}
if (process.platform == 'win32') {
marBinary += '.exe'
}

// On macos this should be
// <obj dir>/dist/${binaryName}/${brandFullName}.app and on everything else,
// the contents of the folder <obj dir>/dist/${binaryName}
const binary =
(process as any).surferPlatform == 'darwin'
? join(OBJ_DIR, 'dist', config.binaryName, `${getCurrentBrandName()}.app`)
: join(OBJ_DIR, 'dist', config.binaryName)

const marPath = windowsPathToUnix(join(DIST_DIR, 'output.mar'))
await configDispatch('./tools/update-packaging/make_full_update.sh', {
args: [
// The mar output location
windowsPathToUnix(join(DIST_DIR)),
binary,
],
cwd: ENGINE_DIR,
env: {
MOZ_PRODUCT_VERSION: version,
MAR_CHANNEL_ID: channel,
MAR: marBinary,
},
})
return marPath
// On macos this should be
// <obj dir>/dist/${binaryName}/${brandFullName}.app and on everything else,
// the contents of the folder <obj dir>/dist/${binaryName}
const binary =
(process as any).surferPlatform == 'darwin'
? join(OBJ_DIR, 'dist', config.binaryName, `${getCurrentBrandName()}.app`)
: join(OBJ_DIR, 'dist', config.binaryName)

const marPath = windowsPathToUnix(join(DIST_DIR, 'output.mar'))
await configDispatch('./tools/update-packaging/make_full_update.sh', {
args: [
// The mar output location
windowsPathToUnix(join(DIST_DIR)),
binary,
],
cwd: ENGINE_DIR,
env: {
MOZ_PRODUCT_VERSION: version,
MAR_CHANNEL_ID: channel,
MAR: marBinary,
},
});

// Download the latest MAR from the github release and run make_incremental_update.sh
const brandingKey = dynamicConfig.get('brand') as string
const brandingDetails = config.brands[brandingKey]
const releaseInfo = brandingDetails.release

console.log(releaseInfo)
const releaseUrl = getReleaseMarURL(releaseInfo);
// Try downloading the file
const oldMarFile = "output-old.mar";
await downloadFileToLocation(releaseUrl, oldMarFile).catch((error) => {
log.warning(`Failed to download the MAR file from ${releaseUrl}`)
resolve(marPath)
}).then(async () => {
log.info(`Downloaded the MAR file from ${releaseUrl}`)
// Extract both the old and new mar files into MAR_TMP_FILE/A and MAR_TMP_FILE/B
const oldMarPath = join(MAR_TMP_FILE, 'A')
const newMarPath = join(MAR_TMP_FILE, 'B')

await configDispatch(marBinary, {
args: ['-x', oldMarFile],
cwd: MAR_TMP_FILE,
});

// Run the make_incremental_update.sh script
await configDispatch('./tools/update-packaging/make_incremental_update.sh', {
args: [
// The mar output location
windowsPathToUnix(join(DIST_DIR)),
oldMarPath,
marPath,
newMarPath,
],
cwd: ENGINE_DIR,
env: {
MOZ_PRODUCT_VERSION: version,
MAR_CHANNEL_ID: channel,
MAR: marBinary,
},
}).then(() => {
resolve(marPath)
}).catch((error) => {
log.error(`Failed to create the incremental update: ${error}`)
resolve(marPath)
});
});
});
}
2 changes: 1 addition & 1 deletion src/commands/updates/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function getReleaseMarName(releaseInfo: ReleaseInfo): string | undefined {
}
}

function getReleaseMarURL(releaseInfo: ReleaseInfo) {
export function getReleaseMarURL(releaseInfo: ReleaseInfo) {
const releaseMarName = getReleaseMarName(releaseInfo)
let completeMarURL = `https://${config.updateHostname || 'localhost:8000'}/${
releaseMarName || 'output.mar'
Expand Down
1 change: 1 addition & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const CONFIGS_DIR = resolve(process.cwd(), 'configs')
export const MELON_DIR = resolve(process.cwd(), '.surfer')
export const MELON_TMP_DIR = resolve(MELON_DIR, 'engine')
export const DIST_DIR = resolve(process.cwd(), 'dist')
export const MAR_TMP_FILE = resolve(process.cwd(), 'dist-old')

mkdirSync(MELON_TMP_DIR, { recursive: true })

Expand Down

0 comments on commit 62c50b6

Please sign in to comment.