Skip to content

gh run list should report in a predictable order #6678

Open

Description

@nedbat

Describe the feature or problem you’d like to solve

If I use gh run list twice to check up on progress, the order of the runs can change. Can the result be sorted, for example by start time, and then workflow name?

Proposed solution

Sort by start time then workflow name so that sequential runs are more understandable.

Activity

  1. nedbat commented on Dec 1, 2022

    @nedbat
    Author

    Sorry, more information: I use a git alias to format the output the way I want. The plain gh run list output order is different than my alias' order. The alias order can shift around. I'm not sure what determines the ordering:

    % gh run list --limit 6
    STATUS  TITLE                                                         WORKFLOW  BRANCH                                             EVENT  ID          ELAPSED  AGE
    *       fix: when checking source existence for remapping, zipfil...  Quality   nedbat/limit-implicit-combine-recursion-w-metacov  push   3593979659  1m23s    1m
    *       fix: when checking source existence for remapping, zipfil...  Coverage  nedbat/limit-implicit-combine-recursion-w-metacov  push   3593979655  1m23s    1m
    *       fix: when checking source existence for remapping, zipfil...  Tests     nedbat/limit-implicit-combine-recursion-w-metacov  push   3593979653  1m23s    1m
    ✓       fix: when checking source existence for remapping, zipfil...  Quality   nedbat/limit-implicit-combine-recursion-w-metacov  push   3593536538  6m32s    53m
    ✓       fix: when checking source existence for remapping, zipfil...  Tests     nedbat/limit-implicit-combine-recursion-w-metacov  push   3593536535  41m47s   53m
    ✓       fix: when checking source existence for remapping, zipfil...  Coverage  nedbat/limit-implicit-combine-recursion-w-metacov  push   3593536529  23m35s   53m
    % git runs 6
    STATUS       RESULT   WORKFLOW  STARTED         COMMIT
    in_progress           Quality   1 minute ago    fix: when checking source existe...  https://github.com/nedbat/coveragepy/actions/runs/3593979659
    queued                Tests     1 minute ago    fix: when checking source existe...  https://github.com/nedbat/coveragepy/actions/runs/3593979653
    queued                Coverage  1 minute ago    fix: when checking source existe...  https://github.com/nedbat/coveragepy/actions/runs/3593979655
    completed    success  Quality   53 minutes ago  fix: when checking source existe...  https://github.com/nedbat/coveragepy/actions/runs/3593536538
    completed    success  Coverage  53 minutes ago  fix: when checking source existe...  https://github.com/nedbat/coveragepy/actions/runs/3593536529
    completed    success  Tests     53 minutes ago  fix: when checking source existe...  https://github.com/nedbat/coveragepy/actions/runs/3593536535
    

    The (wildly over-engineered) git alias is:

        runs = "!f() { \
            gh run list \
                --limit ${1:-10} \
                --branch $(git rev-parse --abbrev-ref HEAD) \
                --json status,conclusion,url,startedAt,workflowName,displayTitle \
                --template '\
                    {{- tablerow \"STATUS\" \"RESULT\" \"WORKFLOW\" \"STARTED\" \"COMMIT\" \"\" -}} \
                    {{- range . -}} \
                    {{- $ccolor := \"green+b\" -}} \
                    {{- if eq .conclusion \"failure\"}}{{ $ccolor = \"red+b\" }}{{ end -}} \
                    {{- tablerow \
                        .status \
                        (.conclusion | color $ccolor) \
                        (.workflowName | truncate 15 | color \"white+b\") \
                        (timeago .startedAt) \
                        (.displayTitle | truncate 35 | color \"white\") \
                        (.url | color \"blue+d\") \
                        -}}\
                    {{- end }}'; \
        }; f"
    
  2. nedbat commented on Dec 1, 2022

    @nedbat
    Author

    Here are two consecutive runs of my alias:

    % git runs 6
    STATUS       RESULT   WORKFLOW  STARTED         COMMIT
    queued                Coverage  16 minutes ago  fix: when checking source existe...  https://github.com/nedbat/coveragepy/actions/runs/3593979655
    completed    success  Quality   16 minutes ago  fix: when checking source existe...  https://github.com/nedbat/coveragepy/actions/runs/3593979659
    in_progress           Tests     16 minutes ago  fix: when checking source existe...  https://github.com/nedbat/coveragepy/actions/runs/3593979653
    completed    success  Coverage  1 hour ago      fix: when checking source existe...  https://github.com/nedbat/coveragepy/actions/runs/3593536529
    completed    success  Quality   1 hour ago      fix: when checking source existe...  https://github.com/nedbat/coveragepy/actions/runs/3593536538
    completed    success  Tests     1 hour ago      fix: when checking source existe...  https://github.com/nedbat/coveragepy/actions/runs/3593536535
    
    % git runs 6
    STATUS       RESULT   WORKFLOW  STARTED         COMMIT
    completed    success  Quality   17 minutes ago  fix: when checking source existe...  https://github.com/nedbat/coveragepy/actions/runs/3593979659
    in_progress           Tests     17 minutes ago  fix: when checking source existe...  https://github.com/nedbat/coveragepy/actions/runs/3593979653
    in_progress           Coverage  17 minutes ago  fix: when checking source existe...  https://github.com/nedbat/coveragepy/actions/runs/3593979655
    completed    success  Quality   1 hour ago      fix: when checking source existe...  https://github.com/nedbat/coveragepy/actions/runs/3593536538
    completed    success  Coverage  1 hour ago      fix: when checking source existe...  https://github.com/nedbat/coveragepy/actions/runs/3593536529
    completed    success  Tests     1 hour ago      fix: when checking source existe...  https://github.com/nedbat/coveragepy/actions/runs/3593536535
    

    Notice that even the three completed runs have changed order!

  3. mislav commented on Dec 1, 2022

    @mislav
    Contributor

    Thanks for reporting! We use this API endpoint which doesn't have an explicit parameter to specify a desired order. I must admit I do not know exactly what the default order is on (I presume some kind of createdAt key). I can ask, but in general, I would not rely on the order being stable in these results. The list of latest runs, even when filtered per-branch, can be is highly volatile.

  4. added and removed on Dec 1, 2022
  5. nedbat commented on Dec 1, 2022

    @nedbat
    Author

    Thanks, is there anything I can do to sort them myself? The Golang templates can do a lot, but maybe not that much...

  6. mislav commented on Dec 1, 2022

    @mislav
    Contributor

    Right now we don't have any template helpers to perform sorting based on a custom key, sorry. Would that be a useful thing to add?

  7. mislav commented on Dec 1, 2022

    @mislav
    Contributor

    @nedbat I've checked with Hubbers who work on the platform side and our best guess so far is:

    1. Specifying --branch filter makes the query go to Elastic Search index (instead of to a database);
    2. The ES index has default sort created desc;
    3. Depending on the granularity of the created field, if two items were created within the same second (or same millisecond, which is also possible), then the stability of their order is not guaranteed.

    I understand that this doesn't help you right now, but I just wanted to note this here for posterity.

  8. nedbat commented on Dec 1, 2022

    @nedbat
    Author

    It's at least comforting my engineer's brain to have a reason, if not a solution :D

  9. added
    coreThis issue is not accepting PRs from outside contributors
    platformProblems with the GitHub platform rather than the CLI client
    and removed on Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    blockedcoreThis issue is not accepting PRs from outside contributorsenhancementa request to improve CLIgh-runrelating to the gh run commandplatformProblems with the GitHub platform rather than the CLI client

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions