mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(cli/templatepush): only implicitly read from stdin if the directory flag is unset (#19681)
In trying to address confusion with the `-` (for stdin) directory flag last year, I had `template push` read from stdin if stdin was not a TTY. However, I made the mistake of checking if the directory flag was set or not by comparing it to the default value. This meant in something like GitHub Actions, where you don't have a TTY for stdin, it was impossible to read from the current working directory. The fix is just to check if the flag was explicitly set, using pflags. If users encounter this bug, and this fix is unavailable in their version of Coder, they can workaround it by setting `-d "$(pwd)"`
This commit is contained in:
@@ -339,6 +339,7 @@ func TestTemplatePush(t *testing.T) {
|
||||
inv, root := clitest.New(t, "templates", "push",
|
||||
"--test.provisioner", string(database.ProvisionerTypeEcho),
|
||||
"--test.workdir", source,
|
||||
"--force-tty",
|
||||
)
|
||||
clitest.SetupConfig(t, templateAdmin, root)
|
||||
pty := ptytest.New(t).Attach(inv)
|
||||
@@ -1075,6 +1076,45 @@ func TestTemplatePush(t *testing.T) {
|
||||
require.Equal(t, templateName, template.Name)
|
||||
require.NotEqual(t, uuid.Nil, template.ActiveVersionID)
|
||||
})
|
||||
|
||||
t.Run("NoStdinWithCurrentDirectory", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
|
||||
owner := coderdtest.CreateFirstUser(t, client)
|
||||
templateAdmin, _ := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID, rbac.RoleTemplateAdmin())
|
||||
version := coderdtest.CreateTemplateVersion(t, client, owner.OrganizationID, nil)
|
||||
_ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
|
||||
|
||||
template := coderdtest.CreateTemplate(t, client, owner.OrganizationID, version.ID)
|
||||
|
||||
source := clitest.CreateTemplateVersionSource(t, &echo.Responses{
|
||||
Parse: echo.ParseComplete,
|
||||
ProvisionApply: echo.ApplyComplete,
|
||||
})
|
||||
|
||||
inv, root := clitest.New(t, "templates", "push", template.Name,
|
||||
"--directory", ".",
|
||||
"--test.provisioner", string(database.ProvisionerTypeEcho),
|
||||
"--test.workdir", source,
|
||||
"--name", "example",
|
||||
"--yes")
|
||||
clitest.SetupConfig(t, templateAdmin, root)
|
||||
|
||||
inv.Stdin = strings.NewReader("invalid tar content that would cause failure")
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
|
||||
defer cancel()
|
||||
|
||||
err := inv.WithContext(ctx).Run()
|
||||
require.NoError(t, err, "Should succeed without reading from stdin")
|
||||
|
||||
templateVersions, err := client.TemplateVersionsByTemplate(ctx, codersdk.TemplateVersionsByTemplateRequest{
|
||||
TemplateID: template.ID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Len(t, templateVersions, 2)
|
||||
require.Equal(t, "example", templateVersions[1].Name)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user