Skip to content

Commit

Permalink
Changes env naming convention to be more normal (#288)
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <adrian@tetrate.io>
  • Loading branch information
codefromthecrypt committed Jul 6, 2021
1 parent 439900c commit 14347d9
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 40 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:
- name: "Run GoReleaser"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_FUNC-E_GITHUB_TOKEN: ${{ secrets.FUNC-E_CI_GITHUB_TOKEN }}
run: make release

e2e:
Expand Down Expand Up @@ -58,4 +57,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: "Run e2e tests using released `func-e` binary"
run: E2E_FUNC-E_BINARY=$PWD/func-e make e2e
run: E2E_FUNC_E_BINARY=$PWD/func-e make e2e
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ test:

# End-to-end (e2e) tests run against a compiled binary.
#
# When E2E_FUNC-E_BINARY isn't set, the func-e binary is built on-demand.
# When E2E_FUNC_E_BINARY isn't set, the func-e binary is built on-demand.
#
# Tests run one at a time, in verbose mode, so that failures are easy to diagnose.
# Note: -failfast helps as it stops at the first error. However, it is not a cacheable flag, so runs won't cache.
E2E_FUNC-E_BINARY ?= $(BIN)
E2E_FUNC_E_BINARY ?= $(BIN)
.PHONY: e2e
e2e: $(E2E_FUNC-E_BINARY)
e2e: $(E2E_FUNC_E_BINARY)
@echo "--- e2e ---"
@go test -parallel 1 -v -failfast ./e2e

Expand Down
2 changes: 1 addition & 1 deletion e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Ex run this from the project root:
make e2e
```

You can override the binary tested by setting `E2E_FUNC-E_BINARY` to an alternative location, for example a release.
You can override the binary tested by setting `E2E_FUNC_E_BINARY` to an alternative location, for example a release.

If the `func-e` version is a snapshot and "envoy-versions.json" exists, tests run against the local. This allows local
development and pull requests to verify changes not yet [published](https://archive.tetratelabs.io/envoy/envoy-versions.json)
Expand Down
4 changes: 2 additions & 2 deletions e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

//nolint:golint
const (
funcEBinaryEnvKey = "E2E_FUNC-E_BINARY"
funcEBinaryEnvKey = "E2E_FUNC_E_BINARY"
envoyVersionsURLEnvKey = "ENVOY_VERSIONS_URL"
envoyVersionsJSON = "envoy-versions.json"
runTimeout = 2 * time.Minute
Expand Down Expand Up @@ -107,7 +107,7 @@ func mockEnvoyVersionsServer() (*httptest.Server, error) {
return ts, nil
}

// readFuncEPath reads E2E_FUNC-E_BINARY or defaults to "$PWD/dist/func-e_$GOOS_$GOARCH/func-e"
// readFuncEPath reads E2E_FUNC_E_BINARY or defaults to "$PWD/dist/func-e_$GOOS_$GOARCH/func-e"
// An error is returned if the value isn't an executable file.
func readFuncEPath() (string, error) {
path := os.Getenv(funcEBinaryEnvKey)
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewApp(o *globals.GlobalOpts) *cli.App {
To list versions of Envoy you can use, execute ` + "`func-e versions -a`" + `. To
choose one, invoke ` + fmt.Sprintf("`func-e use %s`", version.LastKnownEnvoy) + `. This installs into
` + fmt.Sprintf("`$FUNC-E_HOME/versions/%s`", version.LastKnownEnvoy) + `, if not already present.
` + fmt.Sprintf("`$FUNC_E_HOME/versions/%s`", version.LastKnownEnvoy) + `, if not already present.
You may want to override ` + "`$ENVOY_VERSIONS_URL`" + ` to supply custom builds or
otherwise control the source of Envoy binaries. When overriding, validate
Expand All @@ -54,7 +54,7 @@ func NewApp(o *globals.GlobalOpts) *cli.App {
Usage: "func-e home directory (location of installed versions and run archives)",
DefaultText: globals.DefaultHomeDir,
Destination: &homeDir,
EnvVars: []string{"FUNC-E_HOME"},
EnvVars: []string{"FUNC_E_HOME"},
},
&cli.StringFlag{
Name: "envoy-versions-url",
Expand Down Expand Up @@ -117,7 +117,7 @@ func setHomeDir(o *globals.GlobalOpts, homeDir string) error {
if homeDir == "" {
u, err := user.Current()
if err != nil || u.HomeDir == "" {
return NewValidationError("unable to determine home directory. Set FUNC-E_HOME instead: %v", err)
return NewValidationError("unable to determine home directory. Set FUNC_E_HOME instead: %v", err)
}
o.HomeDir = filepath.Join(u.HomeDir, ".func-e")
} else {
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,23 @@ func TestHomeDir(t *testing.T) {
expected: filepath.Join(u.HomeDir, ".func-e"),
},
{
name: "FUNC-E_HOME env",
name: "FUNC_E_HOME env",
args: []string{"func-e"},
setup: func() func() {
return morerequire.RequireSetenv(t, "FUNC-E_HOME", "/from/FUNC-E_HOME/env")
return morerequire.RequireSetenv(t, "FUNC_E_HOME", "/from/FUNC_E_HOME/env")
},
expected: "/from/FUNC-E_HOME/env",
expected: "/from/FUNC_E_HOME/env",
},
{
name: "--home-dir arg",
args: []string{"func-e", "--home-dir", "/from/home-dir/arg"},
expected: "/from/home-dir/arg",
},
{
name: "prioritizes --home-dir arg over FUNC-E_HOME env",
name: "prioritizes --home-dir arg over FUNC_E_HOME env",
args: []string{"func-e", "--home-dir", "/from/home-dir/arg"},
setup: func() func() {
return morerequire.RequireSetenv(t, "FUNC-E_HOME", "/from/FUNC-E_HOME/env")
return morerequire.RequireSetenv(t, "FUNC_E_HOME", "/from/FUNC_E_HOME/env")
},
expected: "/from/home-dir/arg",
},
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ Envoy interprets the '[arguments...]' and runs in the current working
directory (aka $CWD) until func-e is interrupted (ex Ctrl+C, Ctrl+Break).
Envoy's process ID and console output write to "envoy.pid", stdout.log" and
"stderr.log" in the run directory (` + "`$FUNC-E_HOME/runs/$epochtime`" + `).
"stderr.log" in the run directory (` + "`$FUNC_E_HOME/runs/$epochtime`" + `).
When interrupted, shutdown hooks write files including network and process
state. On exit, these archive into ` + "`$FUNC-E_HOME/runs/$epochtime.tar.gz`",
state. On exit, these archive into ` + "`$FUNC_E_HOME/runs/$epochtime.tar.gz`",
Before: func(c *cli.Context) error {
if err := os.MkdirAll(o.HomeDir, 0750); err != nil {
return NewValidationError(err.Error())
Expand Down Expand Up @@ -133,7 +133,7 @@ func initializeRunOpts(ctx context.Context, o *globals.GlobalOpts, p version.Pla
return nil
}

// setHomeEnvoyVersion makes sure the $FUNC-E_HOME/version exists.
// setHomeEnvoyVersion makes sure the $FUNC_E_HOME/version exists.
func setHomeEnvoyVersion(ctx context.Context, o *globals.GlobalOpts) error {
v, homeVersionFile, err := envoy.GetHomeVersion(o.HomeDir)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestFuncERun_ValidatesHomeVersion(t *testing.T) {
err := c.Run([]string{"func-e", "run"})

// Verify the command failed with the expected error
require.EqualError(t, err, fmt.Sprintf(`invalid version in "$FUNC-E_HOME/version": "a.a.a" should look like "%s"`, version.LastKnownEnvoy))
require.EqualError(t, err, fmt.Sprintf(`invalid version in "$FUNC_E_HOME/version": "a.a.a" should look like "%s"`, version.LastKnownEnvoy))
}

// TestFuncERun_ValidatesWorkingVersion duplicates logic in version_test.go to ensure a non-home version validates.
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/testdata/func-e_help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ USAGE:

To list versions of Envoy you can use, execute `func-e versions -a`. To
choose one, invoke `func-e use {ENVOY_VERSION}`. This installs into
`$FUNC-E_HOME/versions/{ENVOY_VERSION}`, if not already present.
`$FUNC_E_HOME/versions/{ENVOY_VERSION}`, if not already present.

You may want to override `$ENVOY_VERSIONS_URL` to supply custom builds or
otherwise control the source of Envoy binaries. When overriding, validate
Expand All @@ -23,6 +23,6 @@ COMMANDS:
use Sets the current [version] used by the "run" command

GLOBAL OPTIONS:
--home-dir value func-e home directory (location of installed versions and run archives) (default: ${HOME}/.func-e) [$FUNC-E_HOME]
--home-dir value func-e home directory (location of installed versions and run archives) (default: ${HOME}/.func-e) [$FUNC_E_HOME]
--envoy-versions-url value URL of Envoy versions JSON (default: https://archive.tetratelabs.io/envoy/envoy-versions.json) [$ENVOY_VERSIONS_URL]
--version, -v print the version (default: false)
6 changes: 3 additions & 3 deletions internal/cmd/testdata/func-e_run_help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ DESCRIPTION:

The first version in the below is run, controllable by the "use" command:
```
$ENVOY_VERSION, $PWD/.envoy-version, $FUNC-E_HOME/version
$ENVOY_VERSION, $PWD/.envoy-version, $FUNC_E_HOME/version
```
The version to use is downloaded and installed, if necessary.

Envoy interprets the '[arguments...]' and runs in the current working
directory (aka $CWD) until func-e is interrupted (ex Ctrl+C, Ctrl+Break).

Envoy's process ID and console output write to "envoy.pid", stdout.log" and
"stderr.log" in the run directory (`$FUNC-E_HOME/runs/$epochtime`).
"stderr.log" in the run directory (`$FUNC_E_HOME/runs/$epochtime`).
When interrupted, shutdown hooks write files including network and process
state. On exit, these archive into `$FUNC-E_HOME/runs/$epochtime.tar.gz`
state. On exit, these archive into `$FUNC_E_HOME/runs/$epochtime.tar.gz`
4 changes: 2 additions & 2 deletions internal/cmd/testdata/func-e_use_help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ USAGE:

DESCRIPTION:
The '[version]' is from the "versions -a" command.
The Envoy [version] installs on-demand into $FUNC-E_HOME/versions/[version]
The Envoy [version] installs on-demand into $FUNC_E_HOME/versions/[version]
if needed.

This updates $PWD/.envoy-version or $FUNC-E_HOME/version with [version],
This updates $PWD/.envoy-version or $FUNC_E_HOME/version with [version],
depending on which is present.

Example:
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewUseCmd(o *globals.GlobalOpts) *cli.Command {
Usage: `Sets the current [version] used by the "run" command`,
ArgsUsage: "[version]",
Description: fmt.Sprintf(`The '[version]' is from the "versions -a" command.
The Envoy [version] installs on-demand into $FUNC-E_HOME/versions/[version]
The Envoy [version] installs on-demand into $FUNC_E_HOME/versions/[version]
if needed.
This updates %s or %s with [version],
Expand Down
10 changes: 5 additions & 5 deletions internal/cmd/versions_cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ func TestFuncEVersions_CurrentVersion(t *testing.T) {
`, stdout.String())
})

t.Run("set by $FUNC-E_HOME/version", func(t *testing.T) {
t.Run("set by $FUNC_E_HOME/version", func(t *testing.T) {
require.NoError(t, os.WriteFile(filepath.Join(o.HomeDir, "version"), []byte("1.1.2"), 0600))

c, stdout, _ := newApp(o)
require.NoError(t, c.Run([]string{"func-e", "versions"}))
require.Equal(t, ` 1.2.2 2021-01-31
* 1.1.2 2021-01-31 (set by $FUNC-E_HOME/version)
* 1.1.2 2021-01-31 (set by $FUNC_E_HOME/version)
1.2.1 2021-01-30
`, stdout.String())
})
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestFuncEVersions_Sorted(t *testing.T) {
require.NoError(t, err)
require.Equal(t, ` 1.2.2 2021-01-31
1.1.2 2021-01-31
* 1.2.1 2021-01-30 (set by $FUNC-E_HOME/version)
* 1.2.1 2021-01-30 (set by $FUNC_E_HOME/version)
`, stdout.String())
require.Empty(t, stderr)
}
Expand All @@ -145,7 +145,7 @@ func TestFuncEVersions_All_RemoteIsCurrent(t *testing.T) {
morerequire.RequireSetMtime(t, versionDir, "2020-12-31")
require.NoError(t, os.WriteFile(filepath.Join(o.HomeDir, "version"), []byte(version.LastKnownEnvoy), 0600))

expected := fmt.Sprintf("* %s 2020-12-31 (set by $FUNC-E_HOME/version)\n", version.LastKnownEnvoy)
expected := fmt.Sprintf("* %s 2020-12-31 (set by $FUNC_E_HOME/version)\n", version.LastKnownEnvoy)

c, stdout, stderr := newApp(o)
err := c.Run([]string{"func-e", "versions", "-a"})
Expand All @@ -165,7 +165,7 @@ func TestFuncEVersions_All_Mixed(t *testing.T) {
require.NoError(t, err)
require.Equal(t, fmt.Sprintf(` 1.2.2 2021-01-31
1.1.2 2021-01-31
* 1.2.1 2021-01-30 (set by $FUNC-E_HOME/version)
* 1.2.1 2021-01-30 (set by $FUNC_E_HOME/version)
%s 2020-12-31
`, version.LastKnownEnvoy), stdout.String())
require.Empty(t, stderr)
Expand Down
4 changes: 2 additions & 2 deletions internal/envoy/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
// CurrentVersionWorkingDirFile is used for stable "versions" and "help" output
CurrentVersionWorkingDirFile = filepath.Join("$PWD", ".envoy-version")
// CurrentVersionHomeDirFile is used for stable "versions" and "help" output
CurrentVersionHomeDirFile = filepath.Join("$FUNC-E_HOME", "version")
CurrentVersionHomeDirFile = filepath.Join("$FUNC_E_HOME", "version")
)

// GetHomeVersion returns the default version in the "homeDir" and path to to it (homeVersionFile). When "v" is empty,
Expand Down Expand Up @@ -90,7 +90,7 @@ func getCurrentVersion(homeDir string) (v version.Version, source string, err er
return "", CurrentVersionWorkingDirFile, err
}

// Priority 3: $FUNC-E_HOME/version
// Priority 3: $FUNC_E_HOME/version
source = CurrentVersionHomeDirFile
v, _, err = getHomeVersion(homeDir)
return
Expand Down
4 changes: 2 additions & 2 deletions internal/envoy/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

func TestVersionUsageList(t *testing.T) {
require.Equal(t, "$ENVOY_VERSION, $PWD/.envoy-version, $FUNC-E_HOME/version", VersionUsageList())
require.Equal(t, "$ENVOY_VERSION, $PWD/.envoy-version, $FUNC_E_HOME/version", VersionUsageList())
}

func TestGetHomeVersion_Empty(t *testing.T) {
Expand Down Expand Up @@ -172,7 +172,7 @@ func TestCurrentVersion_Validates(t *testing.T) {

t.Run("validates home version", func(t *testing.T) {
_, _, err := CurrentVersion(homeDir)
require.EqualError(t, err, fmt.Sprintf(`invalid version in "$FUNC-E_HOME/version": "a.a.a" should look like "%s"`, version.LastKnownEnvoy))
require.EqualError(t, err, fmt.Sprintf(`invalid version in "$FUNC_E_HOME/version": "a.a.a" should look like "%s"`, version.LastKnownEnvoy))
})

revertTempWd := morerequire.RequireChdirIntoTemp(t)
Expand Down
2 changes: 1 addition & 1 deletion internal/globals/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type RunOpts struct {
// Fields representing non-hidden flags have values set according to the following rules:
// 1) value that precedes flag parsing, used in tests
// 2) to a value of the command line argument, e.g. `--home-dir`
// 3) optional mapping to an environment variable, e.g. `FUNC-E_HOME` (not all flags are mapped to ENV)
// 3) optional mapping to an environment variable, e.g. `FUNC_E_HOME` (not all flags are mapped to ENV)
// 4) otherwise, to the default value, e.g. DefaultHomeDir
type GlobalOpts struct {
// RunOpts are inlined to allow tests to override parameters without changing ENV variables or flags
Expand Down
4 changes: 2 additions & 2 deletions site/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ downloads and installs the latest version of Envoy for you.

To list versions of Envoy you can use, execute `func-e versions -a`. To
choose one, invoke `func-e use 1.18.3`. This installs into
`$FUNC-E_HOME/versions/1.18.3`, if not already present.
`$FUNC_E_HOME/versions/1.18.3`, if not already present.

You may want to override `$ENVOY_VERSIONS_URL` to supply custom builds or
otherwise control the source of Envoy binaries. When overriding, validate
Expand All @@ -24,5 +24,5 @@ your JSON first: https://archive.tetratelabs.io/release-versions-schema.json

| Name | Usage | Default |
| ---- | ----- | ------- |
| FUNC-E_HOME | func-e home directory (location of installed versions and run archives) | ${HOME}/.func-e |
| FUNC_E_HOME | func-e home directory (location of installed versions and run archives) | ${HOME}/.func-e |
| ENVOY_VERSIONS_URL | URL of Envoy versions JSON | https://archive.tetratelabs.io/envoy/envoy-versions.json |

0 comments on commit 14347d9

Please sign in to comment.