mirror of
https://gitea.com/gitea/tea.git
synced 2026-02-21 22:03:32 +01:00
Implements comprehensive workflow execution tracking for Gitea Actions using tea CLI ## Features ### tea actions runs list - List workflow runs with filtering (status, branch, event, actor, time) - Time filters: relative (24h, 7d) and absolute dates - Status symbols: ✓ success, ✘ failure, ⭮ pending, ⊘ skipped/cancelled, ⚠ blocked - Multiple output formats: table, json, yaml, csv, tsv ### tea actions runs view - View run details with metadata (ID, status, workflow, branch, event, trigger info) - Shows jobs table with status, runner, duration - Optional --jobs flag to toggle jobs display ### tea actions runs delete - Delete/cancel workflow runs with confirmation prompt - Supports --confirm/-y to skip prompt ### tea actions runs logs - View job logs for all jobs or specific job (--job <id>) - **New: --follow/-f flag for real-time log following** (like tail -f) - Polls API every 2 seconds, only shows new content - Auto-detects completion and exits ### tea actions workflows list - List workflow files (.yml and .yaml) in repository - Searches in .gitea/workflows and .github/workflows - Shows active (✓) or inactive (✗) status based on recent runs - Displays workflow name, path, and file size ## Commands `tea actions runs list --status success --since 24h` `tea actions runs view 123` `tea actions runs delete 123 --confirm` `tea actions runs logs 123 --job 456 --follow` `tea actions workflows list` ## Tests - 19 unit tests across all commands - Full test suite passing - Manual testing successful --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.com> Reviewed-on: https://gitea.com/gitea/tea/pulls/880 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: yousfi saad <yousfi.saad@gmail.com> Co-committed-by: yousfi saad <yousfi.saad@gmail.com>
145 lines
3.4 KiB
Go
145 lines
3.4 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package runs
|
|
|
|
import (
|
|
stdctx "context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"code.gitea.io/tea/cmd/flags"
|
|
"code.gitea.io/tea/modules/context"
|
|
"code.gitea.io/tea/modules/print"
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
// CmdRunsList represents a sub command to list workflow runs
|
|
var CmdRunsList = cli.Command{
|
|
Name: "list",
|
|
Aliases: []string{"ls"},
|
|
Usage: "List workflow runs",
|
|
Description: "List workflow runs for repository actions with optional filtering",
|
|
Action: RunRunsList,
|
|
Flags: append([]cli.Flag{
|
|
&flags.PaginationPageFlag,
|
|
&flags.PaginationLimitFlag,
|
|
&cli.StringFlag{
|
|
Name: "status",
|
|
Usage: "Filter by status (success, failure, pending, queued, in_progress, skipped, canceled)",
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "branch",
|
|
Usage: "Filter by branch name",
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "event",
|
|
Usage: "Filter by event type (push, pull_request, etc.)",
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "actor",
|
|
Usage: "Filter by actor username (who triggered the run)",
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "since",
|
|
Usage: "Show runs started after this time (e.g., '24h', '2024-01-01')",
|
|
},
|
|
&cli.StringFlag{
|
|
Name: "until",
|
|
Usage: "Show runs started before this time (e.g., '2024-01-01')",
|
|
},
|
|
}, flags.AllDefaultFlags...),
|
|
}
|
|
|
|
// parseTimeFlag parses time flags like "24h" or "2024-01-01"
|
|
func parseTimeFlag(value string) (time.Time, error) {
|
|
if value == "" {
|
|
return time.Time{}, nil
|
|
}
|
|
|
|
// Try parsing as duration (e.g., "24h", "168h")
|
|
if duration, err := time.ParseDuration(value); err == nil {
|
|
return time.Now().Add(-duration), nil
|
|
}
|
|
|
|
// Try parsing as date
|
|
formats := []string{
|
|
"2006-01-02",
|
|
"2006-01-02 15:04",
|
|
"2006-01-02T15:04:05",
|
|
time.RFC3339,
|
|
}
|
|
|
|
for _, format := range formats {
|
|
if t, err := time.Parse(format, value); err == nil {
|
|
return t, nil
|
|
}
|
|
}
|
|
|
|
return time.Time{}, fmt.Errorf("unable to parse time: %s", value)
|
|
}
|
|
|
|
// RunRunsList lists workflow runs
|
|
func RunRunsList(ctx stdctx.Context, cmd *cli.Command) error {
|
|
c := context.InitCommand(cmd)
|
|
client := c.Login.Client()
|
|
|
|
// Parse time filters
|
|
since, err := parseTimeFlag(cmd.String("since"))
|
|
if err != nil {
|
|
return fmt.Errorf("invalid --since value: %w", err)
|
|
}
|
|
|
|
until, err := parseTimeFlag(cmd.String("until"))
|
|
if err != nil {
|
|
return fmt.Errorf("invalid --until value: %w", err)
|
|
}
|
|
|
|
// Build list options
|
|
listOpts := flags.GetListOptions()
|
|
|
|
runs, _, err := client.ListRepoActionRuns(c.Owner, c.Repo, gitea.ListRepoActionRunsOptions{
|
|
ListOptions: listOpts,
|
|
Status: cmd.String("status"),
|
|
Branch: cmd.String("branch"),
|
|
Event: cmd.String("event"),
|
|
Actor: cmd.String("actor"),
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if runs == nil {
|
|
print.ActionRunsList(nil, c.Output)
|
|
return nil
|
|
}
|
|
|
|
// Filter by time if specified
|
|
filteredRuns := filterRunsByTime(runs.WorkflowRuns, since, until)
|
|
|
|
print.ActionRunsList(filteredRuns, c.Output)
|
|
return nil
|
|
}
|
|
|
|
// filterRunsByTime filters runs based on time range
|
|
func filterRunsByTime(runs []*gitea.ActionWorkflowRun, since, until time.Time) []*gitea.ActionWorkflowRun {
|
|
if since.IsZero() && until.IsZero() {
|
|
return runs
|
|
}
|
|
|
|
var filtered []*gitea.ActionWorkflowRun
|
|
for _, run := range runs {
|
|
if !since.IsZero() && run.StartedAt.Before(since) {
|
|
continue
|
|
}
|
|
if !until.IsZero() && run.StartedAt.After(until) {
|
|
continue
|
|
}
|
|
filtered = append(filtered, run)
|
|
}
|
|
|
|
return filtered
|
|
}
|