diff --git a/modules/structs/actions_capabilities.go b/modules/structs/actions_capabilities.go index bcc489378a..d6b8661490 100644 --- a/modules/structs/actions_capabilities.go +++ b/modules/structs/actions_capabilities.go @@ -3,6 +3,14 @@ package structs +// DiskInfo holds disk space information for a runner +type DiskInfo struct { + Total uint64 `json:"total_bytes"` + Free uint64 `json:"free_bytes"` + Used uint64 `json:"used_bytes"` + UsedPercent float64 `json:"used_percent"` +} + // RunnerCapability represents the detailed capabilities of a runner type RunnerCapability struct { OS string `json:"os"` @@ -14,6 +22,7 @@ type RunnerCapability struct { Tools map[string][]string `json:"tools,omitempty"` Features *CapabilityFeatures `json:"features,omitempty"` Limitations []string `json:"limitations,omitempty"` + Disk *DiskInfo `json:"disk,omitempty"` } // CapabilityFeatures represents feature support flags diff --git a/modules/templates/helper.go b/modules/templates/helper.go index 4203b057b5..8978003c8f 100644 --- a/modules/templates/helper.go +++ b/modules/templates/helper.go @@ -50,6 +50,8 @@ func NewFuncMap() template.FuncMap { "SliceUtils": NewSliceUtils, "newSlice": func() []any { return []any{} }, "Append": func(s []any, v any) []any { return append(s, v) }, + "Int64ToFloat64": func(i uint64) float64 { return float64(i) }, + "DivideFloat64": func(a, b float64) float64 { if b == 0 { return 0 }; return a / b }, "JsonUtils": NewJsonUtils, "DateUtils": NewDateUtils, diff --git a/options/locale/locale_en-US.json b/options/locale/locale_en-US.json index bacae2b052..2f843ed882 100644 --- a/options/locale/locale_en-US.json +++ b/options/locale/locale_en-US.json @@ -3708,6 +3708,11 @@ "actions.runners.capabilities.tools": "Tools", "actions.runners.capabilities.limitations": "Limitations", "actions.runners.capabilities.available": "Available", + "actions.runners.capabilities.disk": "Disk Space", + "actions.runners.capabilities.disk_free": "free", + "actions.runners.capabilities.disk_total": "total", + "actions.runners.capabilities.disk_warning": "Low disk space", + "actions.runners.capabilities.disk_critical": "Critical: disk almost full", "actions.runs.all_workflows": "All Workflows", "actions.runs.commit": "Commit", "actions.runs.scheduled": "Scheduled", diff --git a/templates/shared/actions/runner_edit.tmpl b/templates/shared/actions/runner_edit.tmpl index 2c396f53a2..13d2749f10 100644 --- a/templates/shared/actions/runner_edit.tmpl +++ b/templates/shared/actions/runner_edit.tmpl @@ -66,6 +66,30 @@ {{end}} + {{if .RunnerCapabilities.Disk}} +
+ {{ctx.Locale.Tr "actions.runners.capabilities.disk"}}: +
+ {{$diskUsed := .RunnerCapabilities.Disk.UsedPercent}} + {{$diskFreeGB := DivideFloat64 (Int64ToFloat64 .RunnerCapabilities.Disk.Free) 1073741824.0}} + {{$diskTotalGB := DivideFloat64 (Int64ToFloat64 .RunnerCapabilities.Disk.Total) 1073741824.0}} + {{$diskUsedInt := printf "%.0f" $diskUsed}} +
+
+
{{printf "%.1f" $diskUsed}}%
+
+
+
+ {{printf "%.1f" $diskFreeGB}} GB {{ctx.Locale.Tr "actions.runners.capabilities.disk_free"}} / {{printf "%.1f" $diskTotalGB}} GB {{ctx.Locale.Tr "actions.runners.capabilities.disk_total"}} + {{if ge $diskUsed 95.0}} + {{svg "octicon-alert" 14}} {{ctx.Locale.Tr "actions.runners.capabilities.disk_critical"}} + {{else if ge $diskUsed 85.0}} + {{svg "octicon-alert" 14}} {{ctx.Locale.Tr "actions.runners.capabilities.disk_warning"}} + {{end}} +
+
+
+ {{end}} {{if .RunnerCapabilities.Limitations}}
{{ctx.Locale.Tr "actions.runners.capabilities.limitations"}}: