Skip to content

Commit

Permalink
(fix): pull latest release version from new endpoint (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann authored Jan 25, 2024
1 parent 61bb323 commit 57a1aca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os from 'node:os'

export const MOZ_CENTRAL_CARGO_TOML = 'https://hg.mozilla.org/mozilla-central/raw-file/tip/testing/geckodriver/Cargo.toml'
export const GECKODRIVER_RELEASES = 'https://api.github.com/repos/mozilla/geckodriver/releases/latest'
export const BASE_CDN_URL = process.env.GECKODRIVER_CDNURL || process.env.npm_config_geckodriver_cdnurl || 'https://github.com/mozilla/geckodriver/releases/download'
// e.g. https://github.com/mozilla/geckodriver/releases/download/v0.33.0/geckodriver-v0.33.0-macos-aarch64.tar.gz
export const GECKODRIVER_DOWNLOAD_PATH = `${BASE_CDN_URL}/v%s/geckodriver-v%s-%s%s%s`
Expand Down
13 changes: 6 additions & 7 deletions src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { HttpsProxyAgent } from 'https-proxy-agent'
import { HttpProxyAgent } from 'http-proxy-agent'
import unzipper, { type Entry } from 'unzipper'

import { BINARY_FILE, MOZ_CENTRAL_CARGO_TOML } from './constants.js'
import { BINARY_FILE, GECKODRIVER_RELEASES } from './constants.js'
import { hasAccess, getDownloadUrl, retryFetch } from './utils.js'

const log = logger('geckodriver')
Expand All @@ -40,13 +40,12 @@ export async function download (
* get latest version of Geckodriver
*/
if (!geckodriverVersion) {
const res = await retryFetch(MOZ_CENTRAL_CARGO_TOML, fetchOpts)
const toml = await res.text()
const version = toml.split('\n').find((l) => l.startsWith('version = '))
if (!version) {
throw new Error(`Couldn't find version property in Cargo.toml file: ${toml}`)
const res = await retryFetch(GECKODRIVER_RELEASES, fetchOpts)
const releases = await res.json() as { name: string }
geckodriverVersion = releases.name
if (!geckodriverVersion) {
throw new Error(`Couldn't find version name in releases: ${JSON.stringify(releases)}`)
}
geckodriverVersion = version.split(' = ').pop().slice(1, -1)
log.info(`Detected Geckodriver v${geckodriverVersion} to be latest`)
}

Expand Down

0 comments on commit 57a1aca

Please sign in to comment.