Skip to content

Commit 3f679e7

Browse files
committed
Merge branch 'main' into 3321-templates-ui-a
2 parents 78a2e2f + cf5d48b commit 3f679e7

File tree

7 files changed

+162
-4
lines changed

7 files changed

+162
-4
lines changed

.github/workflows/packages.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Submit Packages
2+
on:
3+
release:
4+
types: [published]
5+
6+
env:
7+
CODER_VERSION: "${{ github.event.release.tag_name }}"
8+
9+
jobs:
10+
winget:
11+
runs-on: windows-latest
12+
steps:
13+
- name: Install wingetcreate
14+
run: |
15+
Invoke-WebRequest https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe
16+
17+
# the package version is the same as the release tag without the leading
18+
# "v", and with a trailing ".0" (e.g. "v1.2.3" -> "1.2.3.0")
19+
- name: Calculate package version
20+
id: version
21+
run: |
22+
$version = $env:CODER_VERSION -replace "^v", ""
23+
$version += ".0"
24+
echo "::set-output name=version::$version"
25+
26+
- name: Submit updated manifest to winget-pkgs
27+
run: |
28+
$release_assets = gh release view --repo coder/coder "$env:CODER_VERSION" --json assets | `
29+
ConvertFrom-Json
30+
31+
$installer_url = $release_assets.assets | `
32+
Where-Object name -Match ".*_windows_amd64_installer.exe$" | `
33+
Select -ExpandProperty url
34+
35+
echo "Installer URL: $installer_url"
36+
37+
# version should be extracted from the installer
38+
wingetcreate update Coder.Coder `
39+
--submit `
40+
--version "${{ steps.version.outputs.version }}" `
41+
--urls "$installer_url" `
42+
--token "${{ secrets.CDRCI_GITHUB_TOKEN }}"
43+
44+
- name: Comment on PR
45+
run: |
46+
# find the PR that wingetcreate just made
47+
$pr_list = gh pr list --repo microsoft/winget-pkgs --search "author:cdrci Coder.Coder version ${{ steps.version.outputs.version }}" --limit 1 --json number | `
48+
ConvertFrom-Json`
49+
$pr_number = $pr_list[0].number
50+
51+
gh pr comment --repo microsoft/winget-pkgs "$pr_number" --body "🤖 cc: @deansheather"

cli/cliui/table_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type tableTest3 struct {
5252
func Test_DisplayTable(t *testing.T) {
5353
t.Parallel()
5454

55-
someTime := time.Date(2022, 8, 2, 15, 49, 10, 0, time.Local)
55+
someTime := time.Date(2022, 8, 2, 15, 49, 10, 0, time.UTC)
5656
in := []tableTest1{
5757
{
5858
Name: "foo",

cli/templateedit_test.go

Lines changed: 100 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
func TestTemplateEdit(t *testing.T) {
1818
t.Parallel()
1919

20-
t.Run("Modified", func(t *testing.T) {
20+
t.Run("FirstEmptyThenModified", func(t *testing.T) {
2121
t.Parallel()
2222
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
2323
user := coderdtest.CreateFirstUser(t, client)
@@ -58,7 +58,7 @@ func TestTemplateEdit(t *testing.T) {
5858
assert.Equal(t, icon, updated.Icon)
5959
assert.Equal(t, defaultTTL.Milliseconds(), updated.DefaultTTLMillis)
6060
})
61-
t.Run("NotModified", func(t *testing.T) {
61+
t.Run("FirstEmptyThenNotModified", func(t *testing.T) {
6262
t.Parallel()
6363
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
6464
user := coderdtest.CreateFirstUser(t, client)
@@ -124,4 +124,102 @@ func TestTemplateEdit(t *testing.T) {
124124
assert.Equal(t, template.Name, updated.Name)
125125
assert.Equal(t, "", template.DisplayName)
126126
})
127+
t.Run("WithPropertiesThenModified", func(t *testing.T) {
128+
t.Parallel()
129+
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
130+
user := coderdtest.CreateFirstUser(t, client)
131+
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
132+
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
133+
134+
initialDisplayName := "This is a template"
135+
initialDescription := "This is description"
136+
initialIcon := "/img/icon.png"
137+
138+
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID, func(ctr *codersdk.CreateTemplateRequest) {
139+
ctr.DisplayName = initialDisplayName
140+
ctr.Description = initialDescription
141+
ctr.Icon = initialIcon
142+
})
143+
144+
// Test created template
145+
created, err := client.Template(context.Background(), template.ID)
146+
require.NoError(t, err)
147+
assert.Equal(t, initialDisplayName, created.DisplayName)
148+
assert.Equal(t, initialDescription, created.Description)
149+
assert.Equal(t, initialIcon, created.Icon)
150+
151+
// Test the cli command.
152+
displayName := "New Display Name 789"
153+
icon := "/icons/new-icon.png"
154+
cmdArgs := []string{
155+
"templates",
156+
"edit",
157+
template.Name,
158+
"--display-name", displayName,
159+
"--icon", icon,
160+
}
161+
cmd, root := clitest.New(t, cmdArgs...)
162+
clitest.SetupConfig(t, client, root)
163+
164+
ctx, _ := testutil.Context(t)
165+
err = cmd.ExecuteContext(ctx)
166+
167+
require.NoError(t, err)
168+
169+
// Assert that the template metadata changed.
170+
updated, err := client.Template(context.Background(), template.ID)
171+
require.NoError(t, err)
172+
assert.Equal(t, template.Name, updated.Name) // doesn't change
173+
assert.Equal(t, initialDescription, updated.Description) // doesn't change
174+
assert.Equal(t, displayName, updated.DisplayName)
175+
assert.Equal(t, icon, updated.Icon)
176+
})
177+
t.Run("WithPropertiesThenEmptyEdit", func(t *testing.T) {
178+
t.Parallel()
179+
client := coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true})
180+
user := coderdtest.CreateFirstUser(t, client)
181+
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
182+
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
183+
184+
initialDisplayName := "This is a template"
185+
initialDescription := "This is description"
186+
initialIcon := "/img/icon.png"
187+
188+
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID, func(ctr *codersdk.CreateTemplateRequest) {
189+
ctr.DisplayName = initialDisplayName
190+
ctr.Description = initialDescription
191+
ctr.Icon = initialIcon
192+
})
193+
194+
// Test created template
195+
created, err := client.Template(context.Background(), template.ID)
196+
require.NoError(t, err)
197+
assert.Equal(t, initialDisplayName, created.DisplayName)
198+
assert.Equal(t, initialDescription, created.Description)
199+
assert.Equal(t, initialIcon, created.Icon)
200+
201+
// Test the cli command.
202+
cmdArgs := []string{
203+
"templates",
204+
"edit",
205+
template.Name,
206+
}
207+
cmd, root := clitest.New(t, cmdArgs...)
208+
clitest.SetupConfig(t, client, root)
209+
210+
ctx, _ := testutil.Context(t)
211+
err = cmd.ExecuteContext(ctx)
212+
213+
require.NoError(t, err)
214+
215+
// Assert that the template metadata changed.
216+
updated, err := client.Template(context.Background(), template.ID)
217+
require.NoError(t, err)
218+
// Properties don't change
219+
assert.Equal(t, template.Name, updated.Name)
220+
assert.Equal(t, template.Description, updated.Description)
221+
assert.Equal(t, template.DisplayName, updated.DisplayName)
222+
// Icon is removed, as the API considers it as "delete" request
223+
assert.Equal(t, "", updated.Icon)
224+
})
127225
}

coderd/database/databasefake/databasefake.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,6 +2091,8 @@ func (q *fakeQuerier) InsertTemplate(_ context.Context, arg database.InsertTempl
20912091
CreatedBy: arg.CreatedBy,
20922092
UserACL: arg.UserACL,
20932093
GroupACL: arg.GroupACL,
2094+
DisplayName: arg.DisplayName,
2095+
Icon: arg.Icon,
20942096
}
20952097
q.templates = append(q.templates, template)
20962098
return template, nil

coderd/templates.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ func (api *API) postTemplateByOrganization(rw http.ResponseWriter, r *http.Reque
239239
GroupACL: database.TemplateACL{
240240
organization.ID.String(): []rbac.Action{rbac.ActionRead},
241241
},
242+
DisplayName: createTemplate.DisplayName,
243+
Icon: createTemplate.Icon,
242244
})
243245
if err != nil {
244246
return xerrors.Errorf("insert template: %s", err)

scripts/build_windows_installer.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ fi
6767
# Remove the "v" prefix and ensure the version is in the format X.X.X.X for
6868
# makensis.
6969
nsis_version="${version//-*/}"
70-
nsis_version+=".$(date -u +%Y%m%d%H%M)"
70+
# Each component of a version must be a 16 bit integer, so we can't store any
71+
# useful information like build date or commit SHA in the 4th component.
72+
nsis_version+=".0"
7173

7274
# Check dependencies
7375
dependencies makensis

scripts/win-installer/installer.nsi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# adapted to Coder's needs:
33
# https://www.conjur.org/blog/building-a-windows-installer-from-a-linux-ci-pipeline/
44

5+
# Since we only build an AMD64 installer for now, ensure that the generated
6+
# installer matches so wingetcreate can sniff the architecture properly.
7+
CPU amd64
58
Unicode true
69

710
!define APP_NAME "Coder"

0 commit comments

Comments
 (0)