mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(cli): support non-active template version pushes (#7488)
So that we can push template updates for testing without impacting normal users of the template. --------- Co-authored-by: Ammar Bandukwala <ammar@ammar.io> Co-authored-by: Muhammad Atif Ali <matifali@live.com> Co-authored-by: Atif Ali <atif@coder.com>
This commit is contained in:
co-authored by
Ammar Bandukwala
Muhammad Atif Ali
Atif Ali
parent
1f8e817da7
commit
e2613c91a7
+14
-5
@@ -115,6 +115,7 @@ func (r *RootCmd) templatePush() *clibase.Cmd {
|
||||
alwaysPrompt bool
|
||||
provisionerTags []string
|
||||
uploadFlags templateUploadFlags
|
||||
activate bool
|
||||
)
|
||||
client := new(codersdk.Client)
|
||||
cmd := &clibase.Cmd{
|
||||
@@ -172,11 +173,13 @@ func (r *RootCmd) templatePush() *clibase.Cmd {
|
||||
return xerrors.Errorf("job failed: %s", job.Job.Status)
|
||||
}
|
||||
|
||||
err = client.UpdateActiveTemplateVersion(inv.Context(), template.ID, codersdk.UpdateActiveTemplateVersion{
|
||||
ID: job.ID,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
if activate {
|
||||
err = client.UpdateActiveTemplateVersion(inv.Context(), template.ID, codersdk.UpdateActiveTemplateVersion{
|
||||
ID: job.ID,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
_, _ = fmt.Fprintf(inv.Stdout, "Updated version at %s!\n", cliui.Styles.DateTimeStamp.Render(time.Now().Format(time.Stamp)))
|
||||
@@ -226,6 +229,12 @@ func (r *RootCmd) templatePush() *clibase.Cmd {
|
||||
Description: "Always prompt all parameters. Does not pull parameter values from active template version.",
|
||||
Value: clibase.BoolOf(&alwaysPrompt),
|
||||
},
|
||||
{
|
||||
Flag: "activate",
|
||||
Description: "Whether the new template will be marked active.",
|
||||
Default: "true",
|
||||
Value: clibase.BoolOf(&activate),
|
||||
},
|
||||
cliui.SkipPromptOption(),
|
||||
uploadFlags.option(),
|
||||
}
|
||||
|
||||
@@ -69,6 +69,48 @@ func TestTemplatePush(t *testing.T) {
|
||||
require.Equal(t, "example", templateVersions[1].Name)
|
||||
})
|
||||
|
||||
t.Run("PushInactiveTemplateVersion", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
|
||||
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
|
||||
|
||||
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
|
||||
|
||||
// Test the cli command.
|
||||
source := clitest.CreateTemplateVersionSource(t, &echo.Responses{
|
||||
Parse: echo.ParseComplete,
|
||||
ProvisionApply: echo.ProvisionComplete,
|
||||
})
|
||||
inv, root := clitest.New(t, "templates", "push", template.Name, "--activate=false", "--directory", source, "--test.provisioner", string(database.ProvisionerTypeEcho), "--name", "example")
|
||||
clitest.SetupConfig(t, client, root)
|
||||
pty := ptytest.New(t).Attach(inv)
|
||||
w := clitest.StartWithWaiter(t, inv)
|
||||
|
||||
matches := []struct {
|
||||
match string
|
||||
write string
|
||||
}{
|
||||
{match: "Upload", write: "yes"},
|
||||
}
|
||||
for _, m := range matches {
|
||||
pty.ExpectMatch(m.match)
|
||||
pty.WriteLine(m.write)
|
||||
}
|
||||
|
||||
w.RequireSuccess()
|
||||
|
||||
// Assert that the template version didn't change.
|
||||
templateVersions, err := client.TemplateVersionsByTemplate(context.Background(), codersdk.TemplateVersionsByTemplateRequest{
|
||||
TemplateID: template.ID,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, templateVersions, 2)
|
||||
assert.Equal(t, template.ActiveVersionID, templateVersions[0].ID)
|
||||
require.NotEqual(t, "example", templateVersions[0].Name)
|
||||
})
|
||||
|
||||
t.Run("UseWorkingDir", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@ Usage: coder templates push [flags] [template]
|
||||
Push a new template version from the current directory or as specified by flag
|
||||
|
||||
[1mOptions[0m
|
||||
--activate bool (default: true)
|
||||
Whether the new template will be marked active.
|
||||
|
||||
--always-prompt bool
|
||||
Always prompt all parameters. Does not pull parameter values from
|
||||
active template version.
|
||||
|
||||
@@ -12,6 +12,15 @@ coder templates push [flags] [template]
|
||||
|
||||
## Options
|
||||
|
||||
### --activate
|
||||
|
||||
| | |
|
||||
| ------- | ----------------- |
|
||||
| Type | <code>bool</code> |
|
||||
| Default | <code>true</code> |
|
||||
|
||||
Whether the new template will be marked active.
|
||||
|
||||
### --always-prompt
|
||||
|
||||
| | |
|
||||
|
||||
Reference in New Issue
Block a user