From ec9fa46c5a2cc154e45122e72d075a853eebaf40 Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Wed, 15 Mar 2023 14:00:19 +0800 Subject: [PATCH 1/7] Display the version of runner in the runner list --- models/actions/runner.go | 1 + models/migrations/migrations.go | 2 ++ models/migrations/v1_20/v246.go | 12 ++++++++++++ options/locale/locale_en-US.ini | 1 + routers/api/actions/runner/interceptor.go | 9 ++++++--- templates/shared/actions/runner_list.tmpl | 2 ++ 6 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 models/migrations/v1_20/v246.go diff --git a/models/actions/runner.go b/models/actions/runner.go index 4efe105b0884..cce8b4f4431d 100644 --- a/models/actions/runner.go +++ b/models/actions/runner.go @@ -25,6 +25,7 @@ type ActionRunner struct { ID int64 UUID string `xorm:"CHAR(36) UNIQUE"` Name string `xorm:"VARCHAR(255)"` + Version string `xorm:"VARCHAR(64)"` OwnerID int64 `xorm:"index"` // org level runner, 0 means system Owner *user_model.User `xorm:"-"` RepoID int64 `xorm:"index"` // repo level runner, if orgid also is zero, then it's a global diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 4cbcd95d20df..1fef8e715a28 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -469,6 +469,8 @@ var migrations = []Migration{ NewMigration("Add NeedApproval to actions tables", v1_20.AddNeedApprovalToActionRun), // v245 -> v246 NewMigration("Rename Webhook org_id to owner_id", v1_20.RenameWebhookOrgToOwner), + // v246 -> v247 + NewMigration("Add version column to action_runner table", v1_20.AddVersionToActionRunner), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v1_20/v246.go b/models/migrations/v1_20/v246.go new file mode 100644 index 000000000000..df201a3c011d --- /dev/null +++ b/models/migrations/v1_20/v246.go @@ -0,0 +1,12 @@ +package v1_20 + +import "xorm.io/xorm" + +func AddVersionToActionRunner(x *xorm.Engine) error { + + type ActionRunner struct { + Version string `xorm:"VARCHAR(64)"` // the version of act_runner + } + + return x.Sync(new(ActionRunner)) +} diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index afcf9ade04da..40f57bf1f6a8 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3354,6 +3354,7 @@ runners.status.unspecified = Unknown runners.status.idle = Idle runners.status.active = Active runners.status.offline = Offline +runners.version = Version runs.all_workflows = All Workflows runs.open_tab = %d Open diff --git a/routers/api/actions/runner/interceptor.go b/routers/api/actions/runner/interceptor.go index 8c0bd86ecb6c..c480ebce8cca 100644 --- a/routers/api/actions/runner/interceptor.go +++ b/routers/api/actions/runner/interceptor.go @@ -21,8 +21,9 @@ import ( ) const ( - uuidHeaderKey = "x-runner-uuid" - tokenHeaderKey = "x-runner-token" + uuidHeaderKey = "x-runner-uuid" + tokenHeaderKey = "x-runner-token" + versionHeaderKey = "x-runner-version" ) var withRunner = connect.WithInterceptors(connect.UnaryInterceptorFunc(func(unaryFunc connect.UnaryFunc) connect.UnaryFunc { @@ -33,6 +34,7 @@ var withRunner = connect.WithInterceptors(connect.UnaryInterceptorFunc(func(unar } uuid := request.Header().Get(uuidHeaderKey) token := request.Header().Get(tokenHeaderKey) + version := request.Header().Get(versionHeaderKey) runner, err := actions_model.GetRunnerByUUID(ctx, uuid) if err != nil { if errors.Is(err, util.ErrNotExist) { @@ -44,7 +46,8 @@ var withRunner = connect.WithInterceptors(connect.UnaryInterceptorFunc(func(unar return nil, status.Error(codes.Unauthenticated, "unregistered runner") } - cols := []string{"last_online"} + cols := []string{"version", "last_online"} + runner.Version = version runner.LastOnline = timeutil.TimeStampNow() if methodName == "UpdateTask" || methodName == "UpdateLog" { runner.LastActive = timeutil.TimeStampNow() diff --git a/templates/shared/actions/runner_list.tmpl b/templates/shared/actions/runner_list.tmpl index 30c52c01b457..dd2e43f816a9 100644 --- a/templates/shared/actions/runner_list.tmpl +++ b/templates/shared/actions/runner_list.tmpl @@ -49,6 +49,7 @@ {{.locale.Tr "actions.runners.status"}} {{.locale.Tr "actions.runners.id"}} {{.locale.Tr "actions.runners.name"}} + {{.locale.Tr "actions.runners.version"}} {{.locale.Tr "actions.runners.owner_type"}} {{.locale.Tr "actions.runners.labels"}} {{.locale.Tr "actions.runners.last_online"}} @@ -64,6 +65,7 @@ {{.ID}}

{{.Name}}

+ {{.Version}} {{.OwnType}} {{range .AllLabels}}{{.}}{{end}} From a8dba9a94af4fe925a29eccb5f24051adc73dca7 Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Wed, 15 Mar 2023 14:13:39 +0800 Subject: [PATCH 2/7] add copyright and fix lint --- models/migrations/v1_20/v246.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/models/migrations/v1_20/v246.go b/models/migrations/v1_20/v246.go index df201a3c011d..40555210e7e0 100644 --- a/models/migrations/v1_20/v246.go +++ b/models/migrations/v1_20/v246.go @@ -1,9 +1,11 @@ -package v1_20 +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_20 //nolint import "xorm.io/xorm" func AddVersionToActionRunner(x *xorm.Engine) error { - type ActionRunner struct { Version string `xorm:"VARCHAR(64)"` // the version of act_runner } From 30c6668097fb8b3628953ec403a62a0d44cd013f Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Wed, 15 Mar 2023 14:53:24 +0800 Subject: [PATCH 3/7] set version "Unknown" if blank --- routers/api/actions/runner/interceptor.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/routers/api/actions/runner/interceptor.go b/routers/api/actions/runner/interceptor.go index c480ebce8cca..b95b621c4877 100644 --- a/routers/api/actions/runner/interceptor.go +++ b/routers/api/actions/runner/interceptor.go @@ -24,6 +24,8 @@ const ( uuidHeaderKey = "x-runner-uuid" tokenHeaderKey = "x-runner-token" versionHeaderKey = "x-runner-version" + + versionUnknown = "Unknown" ) var withRunner = connect.WithInterceptors(connect.UnaryInterceptorFunc(func(unaryFunc connect.UnaryFunc) connect.UnaryFunc { @@ -35,6 +37,9 @@ var withRunner = connect.WithInterceptors(connect.UnaryInterceptorFunc(func(unar uuid := request.Header().Get(uuidHeaderKey) token := request.Header().Get(tokenHeaderKey) version := request.Header().Get(versionHeaderKey) + if util.IsEmptyString(version) { + version = versionUnknown + } runner, err := actions_model.GetRunnerByUUID(ctx, uuid) if err != nil { if errors.Is(err, util.ErrNotExist) { From 7ddc6ec0f6e64475c62ad5106c451cf7b4161ccf Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Thu, 16 Mar 2023 21:36:39 +0800 Subject: [PATCH 4/7] truncate the version if too long, update version only changed --- routers/api/actions/runner/interceptor.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/routers/api/actions/runner/interceptor.go b/routers/api/actions/runner/interceptor.go index b95b621c4877..bcee7e98316b 100644 --- a/routers/api/actions/runner/interceptor.go +++ b/routers/api/actions/runner/interceptor.go @@ -39,6 +39,8 @@ var withRunner = connect.WithInterceptors(connect.UnaryInterceptorFunc(func(unar version := request.Header().Get(versionHeaderKey) if util.IsEmptyString(version) { version = versionUnknown + } else if len(version) > 63 { + version, _ = util.SplitStringAtByteN(version, 63) } runner, err := actions_model.GetRunnerByUUID(ctx, uuid) if err != nil { @@ -51,8 +53,11 @@ var withRunner = connect.WithInterceptors(connect.UnaryInterceptorFunc(func(unar return nil, status.Error(codes.Unauthenticated, "unregistered runner") } - cols := []string{"version", "last_online"} - runner.Version = version + cols := []string{"last_online"} + if runner.Version != version { + runner.Version = version + cols = append(cols, "verison") + } runner.LastOnline = timeutil.TimeStampNow() if methodName == "UpdateTask" || methodName == "UpdateLog" { runner.LastActive = timeutil.TimeStampNow() From e9157bae8adead904966f7e046a3f39b34435d07 Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Thu, 16 Mar 2023 22:13:53 +0800 Subject: [PATCH 5/7] change migration version --- models/migrations/migrations.go | 2 +- models/migrations/v1_20/{v246.go => v247.go} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename models/migrations/v1_20/{v246.go => v247.go} (100%) diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 1fef8e715a28..845c4d944fe8 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -469,7 +469,7 @@ var migrations = []Migration{ NewMigration("Add NeedApproval to actions tables", v1_20.AddNeedApprovalToActionRun), // v245 -> v246 NewMigration("Rename Webhook org_id to owner_id", v1_20.RenameWebhookOrgToOwner), - // v246 -> v247 + // v247 -> v248 NewMigration("Add version column to action_runner table", v1_20.AddVersionToActionRunner), } diff --git a/models/migrations/v1_20/v246.go b/models/migrations/v1_20/v247.go similarity index 100% rename from models/migrations/v1_20/v246.go rename to models/migrations/v1_20/v247.go From 4f6ad2f5784913b4bd4afec8d9f60e94fce3a877 Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Fri, 17 Mar 2023 10:09:04 +0800 Subject: [PATCH 6/7] fix misspelling --- routers/api/actions/runner/interceptor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/actions/runner/interceptor.go b/routers/api/actions/runner/interceptor.go index bcee7e98316b..58e6ae134a47 100644 --- a/routers/api/actions/runner/interceptor.go +++ b/routers/api/actions/runner/interceptor.go @@ -56,7 +56,7 @@ var withRunner = connect.WithInterceptors(connect.UnaryInterceptorFunc(func(unar cols := []string{"last_online"} if runner.Version != version { runner.Version = version - cols = append(cols, "verison") + cols = append(cols, "version") } runner.LastOnline = timeutil.TimeStampNow() if methodName == "UpdateTask" || methodName == "UpdateLog" { From b0ab1eb96b6bd6fab4829c52f7ba931c91672d50 Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Fri, 17 Mar 2023 11:22:18 +0800 Subject: [PATCH 7/7] fix --- routers/api/actions/runner/interceptor.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routers/api/actions/runner/interceptor.go b/routers/api/actions/runner/interceptor.go index 58e6ae134a47..d97b78f8513b 100644 --- a/routers/api/actions/runner/interceptor.go +++ b/routers/api/actions/runner/interceptor.go @@ -39,9 +39,9 @@ var withRunner = connect.WithInterceptors(connect.UnaryInterceptorFunc(func(unar version := request.Header().Get(versionHeaderKey) if util.IsEmptyString(version) { version = versionUnknown - } else if len(version) > 63 { - version, _ = util.SplitStringAtByteN(version, 63) } + version, _ = util.SplitStringAtByteN(version, 64) + runner, err := actions_model.GetRunnerByUUID(ctx, uuid) if err != nil { if errors.Is(err, util.ErrNotExist) {