Fetch CLI verisons from Homebrew where applicable. (#3290)

If the CLI seems to have been installed using Homebrew, do not consult
the service for the latest version. Instead, consult the Homebrew JSON
API.

Fixes #3230.
This commit is contained in:
Pat Gavlin 2019-10-01 13:34:42 -07:00 committed by GitHub
parent 5ad307d457
commit ecd028104c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 0 deletions

View file

@ -8,23 +8,34 @@ CHANGELOG
using defaults calculated by the provider.
[#3245](https://github.com/pulumi/pulumi/pull/3245)
- Fetch version information from the Homebrew JSON API for CLIs installed using `brew`.
[#3290](https://github.com/pulumi/pulumi/pull/3290)
## 1.2.0 (2019-09-26)
- Support emitting high-level execution trace data to a file and add a debug-only command to view trace data.
[#3238](https://github.com/pulumi/pulumi/pull/3238)
- Fix parsing of GitLab urls with subgroups.
[#3239](https://github.com/pulumi/pulumi/pull/3239)
- `pulumi refresh` can now be scoped to refresh a subset of resources by adding a `--target urn` or
`-t urn` argument. Multiple resources can be specified using `-t urn1 -t urn2`.
- `pulumi destroy` can now be scoped to delete a single resource (and its dependents) by adding a
`--target urn` or `-t urn` argument. Multiple resources can be specified using `-t urn1 -t urn2`.
- `pulumi update` can now be scoped to update a single resource by adding a `--target urn` or `-t urn`
argument. Multiple resources can be specified using `-t urn1 -t urn2`.
- Avoid re-encrypting secret values on each checkpoint write. These changes should improve update times for stacks
that contain secret values.
[#3183](https://github.com/pulumi/pulumi/pull/3183)
- Add Codefresh CI detection.
- Add `-c` (config array) flag to the `preview` command.
- Adds the ability to provide transformations to modify the properties and resource options that
will be used for any child resource of a component or stack.
[#3174](https://github.com/pulumi/pulumi/pull/3174)
@ -33,17 +44,23 @@ CHANGELOG
- Fix a bug that caused the Python runtime to ignore unhandled exceptions and erroneously report that a Pulumi program executed successfully.
[#3170](https://github.com/pulumi/pulumi/pull/3170)
- Read operations are no longer considered changes for the purposes of `--expect-no-changes`.
[#3197](https://github.com/pulumi/pulumi/pull/3197)
- Increase the MaxCallRecvMsgSize for interacting with the gRPC server.
[#3201](https://github.com/pulumi/pulumi/pull/3201)
- Do not ask for a passphrase in non-interactive sessions (fix [#2758](https://github.com/pulumi/pulumi/issues/2758)).
[#3204](https://github.com/pulumi/pulumi/pull/3204)
- Support combining the filestate backend (local or remote storage) with the cloud-backed secrets providers (KMS, etc.).
[#3198](https://github.com/pulumi/pulumi/pull/3198)
- Moved `@pulumi/pulumi` to target `es2016` instead of `es6`. As `@pulumi/pulumi` programs run
inside Nodejs, this should not change anything externally as Nodejs already provides es2016
support. Internally, this makes more APIs available for `@pulumi/pulumi` to use in its implementation.
- Fix the --stack option of the `pulumi new` command.
([#3131](https://github.com/pulumi/pulumi/pull/3131) fixes [#2880](https://github.com/pulumi/pulumi/issues/2880))

View file

@ -19,6 +19,8 @@ import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/url"
"os"
"os/exec"
"os/user"
@ -41,6 +43,7 @@ import (
"github.com/pulumi/pulumi/pkg/diag/colors"
"github.com/pulumi/pulumi/pkg/util/cmdutil"
"github.com/pulumi/pulumi/pkg/util/contract"
"github.com/pulumi/pulumi/pkg/util/httputil"
"github.com/pulumi/pulumi/pkg/util/logging"
"github.com/pulumi/pulumi/pkg/version"
"github.com/pulumi/pulumi/pkg/workspace"
@ -232,6 +235,15 @@ func getCLIVersionInfo() (semver.Version, semver.Version, error) {
return semver.Version{}, semver.Version{}, err
}
brewLatest, isBrew, err := getLatestBrewFormulaVersion()
if err != nil {
return semver.Version{}, semver.Version{}, err
}
if isBrew {
// When consulting Homebrew for version info, we just use the latest version as the oldest allowed.
latest, oldest = brewLatest, brewLatest
}
err = cacheVersionInfo(latest, oldest)
if err != nil {
logging.V(3).Infof("failed to cache version info: %s", err)
@ -401,6 +413,49 @@ func isBrewInstall(exe string) (bool, error) {
return exePath == brewPrefixExePath, nil
}
func getLatestBrewFormulaVersion() (semver.Version, bool, error) {
exe, err := os.Executable()
if err != nil {
return semver.Version{}, false, err
}
isBrew, err := isBrewInstall(exe)
if err != nil {
return semver.Version{}, false, err
}
if !isBrew {
return semver.Version{}, false, nil
}
url, err := url.Parse("https://formulae.brew.sh/api/formula/pulumi.json")
contract.AssertNoError(err)
resp, err := httputil.DoWithRetry(&http.Request{
Method: http.MethodGet,
URL: url,
}, http.DefaultClient)
if err != nil {
return semver.Version{}, false, err
}
defer contract.IgnoreClose(resp.Body)
type versions struct {
Stable string `json:"stable"`
}
var formula struct {
Versions versions `json:"versions"`
}
if err := json.NewDecoder(resp.Body).Decode(&formula); err != nil {
return semver.Version{}, false, err
}
stable, err := semver.ParseTolerant(formula.Versions.Stable)
if err != nil {
return semver.Version{}, false, err
}
return stable, true, nil
}
func isDevVersion(s semver.Version) bool {
if len(s.Pre) == 0 {
return false