Skip to content

Commit

Permalink
fix(command-dev-trace): pin traffic mesh agent version (#1456)
Browse files Browse the repository at this point in the history
  • Loading branch information
erezrokah authored Oct 21, 2020
1 parent 9daa4c8 commit a1df2a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/lib/exec-fetcher.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path')
const execa = require('execa')
const { fetchLatest, updateAvailable } = require('gh-release-fetch')
const { fetchVersion, fetchLatest, updateAvailable, newerVersion } = require('gh-release-fetch')
const isExe = require('isexe')

const { NETLIFYDEVWARN } = require('../utils/logo')
Expand All @@ -25,13 +25,16 @@ const getOptions = () => {
}
}

const isVersionOutdated = async ({ packageName, currentVersion }) => {
const isVersionOutdated = async ({ packageName, currentVersion, latestVersion }) => {
if (latestVersion) {
return newerVersion(latestVersion, currentVersion)
}
const options = getOptions()
const outdated = await updateAvailable(getRepository({ packageName }), currentVersion, options)
return outdated
}

const shouldFetchLatestVersion = async ({ binPath, packageName, execName, execArgs, pattern, log }) => {
const shouldFetchLatestVersion = async ({ binPath, packageName, execName, execArgs, pattern, latestVersion, log }) => {
const execPath = path.join(binPath, getExecName({ execName }))

const exists = await isExe(execPath, { ignoreErrors: true })
Expand All @@ -51,9 +54,11 @@ const shouldFetchLatestVersion = async ({ binPath, packageName, execName, execAr
}

try {
const [, currentVersion] = match
const outdated = await isVersionOutdated({
packageName,
currentVersion: match[1],
currentVersion,
latestVersion,
})
return outdated
} catch (error) {
Expand All @@ -65,7 +70,7 @@ const shouldFetchLatestVersion = async ({ binPath, packageName, execName, execAr
}
}

const fetchLatestVersion = async ({ packageName, execName, destination, extension }) => {
const fetchLatestVersion = async ({ packageName, execName, destination, extension, latestVersion }) => {
const win = isWindows()
const platform = win ? 'windows' : process.platform
const release = {
Expand All @@ -76,7 +81,7 @@ const fetchLatestVersion = async ({ packageName, execName, destination, extensio
}

const options = getOptions()
await fetchLatest(release, options)
await (latestVersion ? fetchVersion({ ...release, version: latestVersion }, options) : fetchLatest(release, options))
}

module.exports = { getExecName, shouldFetchLatestVersion, fetchLatestVersion }
5 changes: 5 additions & 0 deletions src/utils/traffic-mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const { shouldFetchLatestVersion, fetchLatestVersion } = require('../lib/exec-fe
const PACKAGE_NAME = 'traffic-mesh-agent'
const EXEC_NAME = 'traffic-mesh'

const LATEST_VERSION = 'v0.22.1'

const getBinPath = () => getPathInHome([PACKAGE_NAME, 'bin'])

const installTrafficMesh = async ({ log }) => {
Expand All @@ -18,6 +20,8 @@ const installTrafficMesh = async ({ log }) => {
execArgs: ['--version'],
pattern: '\\sv(.+)',
execName: EXEC_NAME,
latestVersion: LATEST_VERSION,
log,
})
if (!shouldFetch) {
return
Expand All @@ -30,6 +34,7 @@ const installTrafficMesh = async ({ log }) => {
execName: EXEC_NAME,
destination: binPath,
extension: 'zip',
latestVersion: LATEST_VERSION,
})
}

Expand Down

0 comments on commit a1df2a3

Please sign in to comment.