Skip to content

Commit 757ea0f

Browse files
committed
Merge branch 'main' into optional-external-auth
2 parents d58c088 + d6b025d commit 757ea0f

File tree

82 files changed

+3132
-308
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+3132
-308
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ jobs:
141141
142142
# Check for any typos
143143
- name: Check for typos
144-
uses: crate-ci/typos@v1.18.0
144+
uses: crate-ci/typos@v1.18.2
145145
with:
146146
config: .github/workflows/typos.toml
147147

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ jobs:
411411
- name: Sync fork
412412
run: gh repo sync cdrci/winget-pkgs -b master
413413
env:
414-
GH_TOKEN: ${{ github.token }}
414+
GH_TOKEN: ${{ secrets.CDRCI_GITHUB_TOKEN }}
415415

416416
- name: Checkout
417417
uses: actions/checkout@v4

.github/workflows/security.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122
image_name: ${{ steps.build.outputs.image }}
123123

124124
- name: Run Trivy vulnerability scanner
125-
uses: aquasecurity/trivy-action@d43c1f16c00cfd3978dde6c07f4bbcf9eb6993ca
125+
uses: aquasecurity/trivy-action@84384bd6e777ef152729993b8145ea352e9dd3ef
126126
with:
127127
image-ref: ${{ steps.build.outputs.image }}
128128
format: sarif

cli/templateedit.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
2323
description string
2424
icon string
2525
defaultTTL time.Duration
26+
activityBump time.Duration
2627
maxTTL time.Duration
2728
autostopRequirementDaysOfWeek []string
2829
autostopRequirementWeeks int64
@@ -108,6 +109,10 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
108109
defaultTTL = time.Duration(template.DefaultTTLMillis) * time.Millisecond
109110
}
110111

112+
if !userSetOption(inv, "activity-bump") {
113+
activityBump = time.Duration(template.ActivityBumpMillis) * time.Millisecond
114+
}
115+
111116
if !userSetOption(inv, "allow-user-autostop") {
112117
allowUserAutostop = template.AllowUserAutostop
113118
}
@@ -168,12 +173,13 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
168173
}
169174

170175
req := codersdk.UpdateTemplateMeta{
171-
Name: name,
172-
DisplayName: displayName,
173-
Description: description,
174-
Icon: icon,
175-
DefaultTTLMillis: defaultTTL.Milliseconds(),
176-
MaxTTLMillis: maxTTL.Milliseconds(),
176+
Name: name,
177+
DisplayName: displayName,
178+
Description: description,
179+
Icon: icon,
180+
DefaultTTLMillis: defaultTTL.Milliseconds(),
181+
ActivityBumpMillis: activityBump.Milliseconds(),
182+
MaxTTLMillis: maxTTL.Milliseconds(),
177183
AutostopRequirement: &codersdk.TemplateAutostopRequirement{
178184
DaysOfWeek: autostopRequirementDaysOfWeek,
179185
Weeks: autostopRequirementWeeks,
@@ -233,6 +239,11 @@ func (r *RootCmd) templateEdit() *clibase.Cmd {
233239
Description: "Edit the template default time before shutdown - workspaces created from this template default to this value. Maps to \"Default autostop\" in the UI.",
234240
Value: clibase.DurationOf(&defaultTTL),
235241
},
242+
{
243+
Flag: "activity-bump",
244+
Description: "Edit the template activity bump - workspaces created from this template will have their shutdown time bumped by this value when activity is detected. Maps to \"Activity bump\" in the UI.",
245+
Value: clibase.DurationOf(&activityBump),
246+
},
236247
{
237248
Flag: "max-ttl",
238249
Description: "Edit the template maximum time before shutdown - workspaces created from this template must shutdown within the given duration after starting, regardless of user activity. This is an enterprise-only feature. Maps to \"Max lifetime\" in the UI.",

cli/templateedit_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func TestTemplateEdit(t *testing.T) {
9393
"--description", template.Description,
9494
"--icon", template.Icon,
9595
"--default-ttl", (time.Duration(template.DefaultTTLMillis) * time.Millisecond).String(),
96+
"--activity-bump", (time.Duration(template.ActivityBumpMillis) * time.Millisecond).String(),
9697
"--allow-user-cancel-workspace-jobs=" + strconv.FormatBool(template.AllowUserCancelWorkspaceJobs),
9798
}
9899
inv, root := clitest.New(t, cmdArgs...)

cli/testdata/coder_templates_edit_--help.golden

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ USAGE:
66
Edit the metadata of a template by name.
77

88
OPTIONS:
9+
--activity-bump duration
10+
Edit the template activity bump - workspaces created from this
11+
template will have their shutdown time bumped by this value when
12+
activity is detected. Maps to "Activity bump" in the UI.
13+
914
--allow-user-autostart bool (default: true)
1015
Allow users to configure autostart for workspaces on this template.
1116
This can only be disabled in enterprise.

coderd/agentapi/activitybump_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
4141
maxDeadlineOffset *time.Duration
4242
workspaceTTL time.Duration
4343
templateTTL time.Duration
44+
templateActivityBump time.Duration
4445
templateDisallowsUserAutostop bool
4546
expectedBump time.Duration
4647
// If the tests get queued, we need to be able to set the next autostart
@@ -137,6 +138,26 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
137138
expectedBump: 10*time.Hour + (time.Minute * 30),
138139
nextAutostart: func(now time.Time) time.Time { return now.Add(time.Minute * 30) },
139140
},
141+
{
142+
// Custom activity bump duration specified on the template.
143+
name: "TemplateCustomActivityBump",
144+
transition: database.WorkspaceTransitionStart,
145+
jobCompletedAt: sql.NullTime{Valid: true, Time: dbtime.Now().Add(-30 * time.Minute)},
146+
buildDeadlineOffset: ptr.Ref(-30 * time.Minute),
147+
workspaceTTL: 8 * time.Hour,
148+
templateActivityBump: 5 * time.Hour, // instead of default 1h
149+
expectedBump: 5 * time.Hour,
150+
},
151+
{
152+
// Activity bump duration is 0.
153+
name: "TemplateCustomActivityBumpZero",
154+
transition: database.WorkspaceTransitionStart,
155+
jobCompletedAt: sql.NullTime{Valid: true, Time: dbtime.Now().Add(-30 * time.Minute)},
156+
buildDeadlineOffset: ptr.Ref(-30 * time.Minute),
157+
workspaceTTL: 8 * time.Hour,
158+
templateActivityBump: -1, // negative values get changed to 0 in the test
159+
expectedBump: 0,
160+
},
140161
} {
141162
tt := tt
142163
for _, tz := range timezones {
@@ -186,11 +207,19 @@ func Test_ActivityBumpWorkspace(t *testing.T) {
186207
buildID = uuid.New()
187208
)
188209

210+
activityBump := 1 * time.Hour
211+
if tt.templateActivityBump < 0 {
212+
// less than 0 => 0
213+
activityBump = 0
214+
} else if tt.templateActivityBump != 0 {
215+
activityBump = tt.templateActivityBump
216+
}
189217
require.NoError(t, db.UpdateTemplateScheduleByID(ctx, database.UpdateTemplateScheduleByIDParams{
190218
ID: template.ID,
191219
UpdatedAt: dbtime.Now(),
192220
AllowUserAutostop: !tt.templateDisallowsUserAutostop,
193221
DefaultTTL: int64(tt.templateTTL),
222+
ActivityBump: int64(activityBump),
194223
}), "unexpected error updating template schedule")
195224

196225
var buildNumber int32 = 1

0 commit comments

Comments
 (0)