Skip to content

Commit 371520d

Browse files
authored
Display the version of runner in the runner list (#23490)
Close: #23489 ### Change 1. Add version column to action_runner table. 2. Read the runner version from the request header, and update it in DB. 3. Display version in runner list ### Screenshot ![image](https://user-images.githubusercontent.com/33891828/225220990-98bc0158-4403-4e6c-9805-31bbbc65a802.png)
1 parent af37111 commit 371520d

File tree

6 files changed

+35
-2
lines changed

6 files changed

+35
-2
lines changed

models/actions/runner.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type ActionRunner struct {
2525
ID int64
2626
UUID string `xorm:"CHAR(36) UNIQUE"`
2727
Name string `xorm:"VARCHAR(255)"`
28+
Version string `xorm:"VARCHAR(64)"`
2829
OwnerID int64 `xorm:"index"` // org level runner, 0 means system
2930
Owner *user_model.User `xorm:"-"`
3031
RepoID int64 `xorm:"index"` // repo level runner, if orgid also is zero, then it's a global

models/migrations/migrations.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,8 @@ var migrations = []Migration{
473473
NewMigration("Add missed column owner_id for project table", v1_20.AddNewColumnForProject),
474474
// v247 -> v248
475475
NewMigration("Fix incorrect project type", v1_20.FixIncorrectProjectType),
476+
// v248 -> v249
477+
NewMigration("Add version column to action_runner table", v1_20.AddVersionToActionRunner),
476478
}
477479

478480
// GetCurrentDBVersion returns the current db version

models/migrations/v1_20/v248.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package v1_20 //nolint
5+
6+
import "xorm.io/xorm"
7+
8+
func AddVersionToActionRunner(x *xorm.Engine) error {
9+
type ActionRunner struct {
10+
Version string `xorm:"VARCHAR(64)"` // the version of act_runner
11+
}
12+
13+
return x.Sync(new(ActionRunner))
14+
}

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3355,6 +3355,7 @@ runners.status.unspecified = Unknown
33553355
runners.status.idle = Idle
33563356
runners.status.active = Active
33573357
runners.status.offline = Offline
3358+
runners.version = Version
33583359
33593360
runs.all_workflows = All Workflows
33603361
runs.open_tab = %d Open

routers/api/actions/runner/interceptor.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ import (
2121
)
2222

2323
const (
24-
uuidHeaderKey = "x-runner-uuid"
25-
tokenHeaderKey = "x-runner-token"
24+
uuidHeaderKey = "x-runner-uuid"
25+
tokenHeaderKey = "x-runner-token"
26+
versionHeaderKey = "x-runner-version"
27+
28+
versionUnknown = "Unknown"
2629
)
2730

2831
var withRunner = connect.WithInterceptors(connect.UnaryInterceptorFunc(func(unaryFunc connect.UnaryFunc) connect.UnaryFunc {
@@ -33,6 +36,12 @@ var withRunner = connect.WithInterceptors(connect.UnaryInterceptorFunc(func(unar
3336
}
3437
uuid := request.Header().Get(uuidHeaderKey)
3538
token := request.Header().Get(tokenHeaderKey)
39+
version := request.Header().Get(versionHeaderKey)
40+
if util.IsEmptyString(version) {
41+
version = versionUnknown
42+
}
43+
version, _ = util.SplitStringAtByteN(version, 64)
44+
3645
runner, err := actions_model.GetRunnerByUUID(ctx, uuid)
3746
if err != nil {
3847
if errors.Is(err, util.ErrNotExist) {
@@ -45,6 +54,10 @@ var withRunner = connect.WithInterceptors(connect.UnaryInterceptorFunc(func(unar
4554
}
4655

4756
cols := []string{"last_online"}
57+
if runner.Version != version {
58+
runner.Version = version
59+
cols = append(cols, "version")
60+
}
4861
runner.LastOnline = timeutil.TimeStampNow()
4962
if methodName == "UpdateTask" || methodName == "UpdateLog" {
5063
runner.LastActive = timeutil.TimeStampNow()

templates/shared/actions/runner_list.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<th data-sortt-asc="online" data-sortt-desc="offline">{{.locale.Tr "actions.runners.status"}}</th>
5050
<th data-sortt-asc="alphabetically">{{.locale.Tr "actions.runners.id"}}</th>
5151
<th>{{.locale.Tr "actions.runners.name"}}</th>
52+
<th>{{.locale.Tr "actions.runners.version"}}</th>
5253
<th>{{.locale.Tr "actions.runners.owner_type"}}</th>
5354
<th>{{.locale.Tr "actions.runners.labels"}}</th>
5455
<th>{{.locale.Tr "actions.runners.last_online"}}</th>
@@ -64,6 +65,7 @@
6465
</td>
6566
<td>{{.ID}}</td>
6667
<td><p class="tooltip" data-content="{{.Description}}">{{.Name}}</p></td>
68+
<td>{{.Version}}</td>
6769
<td>{{.OwnType}}</td>
6870
<td class="runner-tags">
6971
{{range .AllLabels}}<span class="ui label">{{.}}</span>{{end}}

0 commit comments

Comments
 (0)