Skip to content

Commit

Permalink
Allow overriding Buf version in PATH (#72)
Browse files Browse the repository at this point in the history
This avoids requiring the version of Buf found in the PATH to match the
resolved. Fallback to installing a new explicit version in the
toolcache.

Fixes #71
  • Loading branch information
emcfarlane authored Oct 9, 2024
1 parent 275c46d commit 4a2a5f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
11 changes: 4 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45508,14 +45508,11 @@ async function installBuf(github, versionInput) {
silent: true,
});
const version = bufVersion.stdout.trim();
core.info(`Using buf (${version}) found in $PATH`);
if (!semver.satisfies(version, requiredVersion)) {
throw new Error(`The version of buf (${version}) does not satisfy the required version (${requiredVersion})`);
if (semver.satisfies(version, requiredVersion) &&
(resolvedVersion == "" || semver.eq(version, resolvedVersion))) {
core.info(`Using buf (${version}) found in $PATH`);
return [binName, version];
}
if (resolvedVersion != "" && !semver.eq(version, resolvedVersion)) {
throw new Error(`The version of buf (${version}) does not equal the resolved version (${resolvedVersion})`);
}
return [binName, version];
}
if (resolvedVersion === "") {
resolvedVersion = await latestVersion(github);
Expand Down
17 changes: 6 additions & 11 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,13 @@ export async function installBuf(
silent: true,
});
const version = bufVersion.stdout.trim();
core.info(`Using buf (${version}) found in $PATH`);
if (!semver.satisfies(version, requiredVersion)) {
throw new Error(
`The version of buf (${version}) does not satisfy the required version (${requiredVersion})`,
);
if (
semver.satisfies(version, requiredVersion) &&
(resolvedVersion == "" || semver.eq(version, resolvedVersion))
) {
core.info(`Using buf (${version}) found in $PATH`);
return [binName, version];
}
if (resolvedVersion != "" && !semver.eq(version, resolvedVersion)) {
throw new Error(
`The version of buf (${version}) does not equal the resolved version (${resolvedVersion})`,
);
}
return [binName, version];
}
if (resolvedVersion === "") {
resolvedVersion = await latestVersion(github);
Expand Down

0 comments on commit 4a2a5f7

Please sign in to comment.