Skip to content

Commit

Permalink
Change the extract dir to be constant
Browse files Browse the repository at this point in the history
  • Loading branch information
cardil committed Nov 3, 2022
1 parent 73eaf4c commit 2bae62a
Show file tree
Hide file tree
Showing 96 changed files with 172 additions and 182 deletions.
4 changes: 2 additions & 2 deletions pkg/inflator/cli/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func TestApp(t *testing.T) {
tmpdir := t.TempDir()
t.Setenv(extract.ArtifactsEnvVar, tmpdir)
t.Setenv(extract.HackScriptsDirEnvVar, tmpdir)
c := cli.App{}.Command()
var (
outb bytes.Buffer
Expand All @@ -24,6 +24,6 @@ func TestApp(t *testing.T) {
err := c.Execute()

require.NoError(t, err)
assert.Equal(t, outb.String(), tmpdir+"/hack-scripts/e2e-tests.sh\n")
assert.Equal(t, outb.String(), tmpdir+"/e2e-tests.sh\n")
assert.Equal(t, errb.String(), "")
}
14 changes: 13 additions & 1 deletion pkg/inflator/cli/flags.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package cli

import (
"os"
"strings"

"github.com/spf13/cobra"
)

Expand All @@ -10,6 +13,15 @@ type flags struct {

func (f *flags) withFlags(c *cobra.Command) *cobra.Command {
fl := c.PersistentFlags()
fl.BoolVarP(&f.verbose, "verbose", "v", false, "Print verbose output on Stderr")
fl.BoolVarP(&f.verbose, "verbose", "v", isCiServer(), "Print verbose output on Stderr")
return c
}

func isCiServer() bool {
if strings.HasPrefix(strings.ToLower(os.Getenv("KNATIVE_HACK_SCRIPT_MANUAL_VERBOSE")), "t") {
return false
}
return os.Getenv("CI") != "" ||
os.Getenv("BUILD_ID") != "" ||
os.Getenv("PROW_JOB_ID") != ""
}
16 changes: 6 additions & 10 deletions pkg/inflator/extract/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
)

const (
// ArtifactsEnvVar is the name of the environment variable that points
// to ARTIFACTS directory.
ArtifactsEnvVar = "ARTIFACTS"
// HackScriptsDirEnvVar is the name of the environment variable that points
// to directory where knative-hack scripts will be extracted.
HackScriptsDirEnvVar = "KNATIVE_HACK_SCRIPTS_DIR"
// PermOwnerWrite is the permission bits for owner write.
PermOwnerWrite = 0o200
// PermAllExecutable is the permission bits for executable.
Expand Down Expand Up @@ -42,14 +42,10 @@ type Operation struct {
// provide the file path to it.
func (o Operation) Extract(prtr Printer) error {
l := logger{o.Verbose, prtr}
artifactsDir := os.Getenv(ArtifactsEnvVar)
if artifactsDir == "" {
var err error
if artifactsDir, err = os.MkdirTemp("", "knative.*"); err != nil {
return wrapErr(err, ErrBug)
}
hackRootDir := os.Getenv(HackScriptsDirEnvVar)
if hackRootDir == "" {
hackRootDir = path.Join(os.TempDir(), "knative", "hack", "scripts")
}
hackRootDir := path.Join(artifactsDir, "hack-scripts")
l.debugf("Extracting hack scripts to directory: %s", hackRootDir)
if err := copyDir(l, hack.Scripts, hackRootDir, "."); err != nil {
return err
Expand Down
12 changes: 6 additions & 6 deletions pkg/inflator/extract/extract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,35 @@ import (

func TestExtract(t *testing.T) {
tmpdir := t.TempDir()
t.Setenv(extract.ArtifactsEnvVar, tmpdir)
t.Setenv(extract.HackScriptsDirEnvVar, tmpdir)
op := extract.Operation{
ScriptName: "library.sh",
Verbose: true,
}
prtr := &testPrinter{}
err := op.Extract(prtr)
require.NoError(t, err)
assert.Equal(t, prtr.out.String(), tmpdir+"/hack-scripts/library.sh\n")
assert.Equal(t, prtr.out.String(), tmpdir+"/library.sh\n")
assert.Equal(t,
`[hack] Extracting hack scripts to directory: /tmp/x/hack-scripts
`[hack] Extracting hack scripts to directory: /tmp/x
[hack] codegen-library.sh 1 KiB +
[hack] e2e-tests.sh 6 KiB ++
[hack] infra-library.sh 5 KiB +
[hack] library.sh 33 KiB +++++++
[hack] microbenchmarks.sh 2 KiB +
[hack] performance-tests.sh 6 KiB ++
[hack] presubmit-tests.sh 12 KiB +++
[hack] release.sh 26 KiB ++++++
[hack] release.sh 27 KiB ++++++
[hack] shellcheck-presubmit.sh 1 KiB +
`, strings.ReplaceAll(prtr.err.String(), tmpdir, "/tmp/x"))

// second time should be a no-op
prtr = &testPrinter{}
err = op.Extract(prtr)
require.NoError(t, err)
assert.Equal(t, prtr.out.String(), tmpdir+"/hack-scripts/library.sh\n")
assert.Equal(t, prtr.out.String(), tmpdir+"/library.sh\n")
assert.Equal(t,
`[hack] Extracting hack scripts to directory: /tmp/x/hack-scripts
`[hack] Extracting hack scripts to directory: /tmp/x
[hack] codegen-library.sh up-to-date
[hack] e2e-tests.sh up-to-date
[hack] infra-library.sh up-to-date
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions schema/vendor/github.com/json-iterator/go/any.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions schema/vendor/github.com/json-iterator/go/reflect_array.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions schema/vendor/github.com/json-iterator/go/reflect_dynamic.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions schema/vendor/github.com/json-iterator/go/reflect_map.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions schema/vendor/github.com/json-iterator/go/reflect_slice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions schema/vendor/github.com/modern-go/concurrent/go_above_19.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions schema/vendor/github.com/modern-go/concurrent/go_below_19.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions schema/vendor/github.com/modern-go/concurrent/log.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions schema/vendor/github.com/modern-go/reflect2/go_above_17.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions schema/vendor/github.com/modern-go/reflect2/go_above_19.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions schema/vendor/github.com/modern-go/reflect2/go_below_17.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions schema/vendor/github.com/modern-go/reflect2/go_below_19.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2bae62a

Please sign in to comment.