ghaprofiler

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2020 License: MIT Imports: 20 Imported by: 0

README

github-actions-profile

A profiler for GitHub Actions workflow

Installation

go get github.com/utgwkk/github-actions-profiler/cmd/github-actions-profiler

Configuration

Arguments
arguments type description
access-token string An access token
cache bool Enable disk cache (Default: true)
cache-dir string Where to store cache data
concurrency int Concurrency of GitHub API client (Default: 2)
number-of-job int The number of job to analyze
format string Output format (Default: table, Supported: table, json, tsv, markdown)
job-name-regexp string Filter regular expression for a job name
owner string Repository owner name
repository string Repository name
reverse bool Reverse the result of sort
sort string A field name to sort by (Default: number, Supported: number, min, max, median, mean, p50, p90, p95, p99)
verbose bool Verbose mode
workflow-file string Workflow file name (without .github/workflows/)
Passing access token with a environment variable

You may pass access-token with GITHUB_ACTIONS_PROFILER_TOKEN environment variable.

TOML

You may set configuration with a TOML file and pass it with --config <path to config.toml>.

access-token = "YOUR_ACCESS_TOKEN"
cache = true
cache-dir = "/tmp/cache/dir"
number-of-job = 50
format = "table"
job-name-regexp = "Perl"
owner = "your-name"
repository = "your-repository"
reverse = true
sort = "max"
workflow-file = "ci.yml"

Example output

Job: Perl 5.32
+--------+----------+----------+----------+----------+----------+-----------+------------+------------+----------------------------------------------------+
| Number |   Min    |  Median  |   Mean   |   P50    |   P90    |    P95    |    P99     |    Max     |                        Name                        |
+--------+----------+----------+----------+----------+----------+-----------+------------+------------+----------------------------------------------------+
|      1 | 2.000000 | 3.000000 | 3.430769 | 3.000000 | 5.000000 |  5.000000 |   5.000000 |   5.000000 | Set up job                                         |
|      2 | 1.000000 | 1.000000 | 1.307692 | 1.000000 | 2.000000 |  3.000000 |   3.000000 |   3.000000 | Run actions/checkout@v2                            |
|      3 | 0.000000 | 1.000000 | 1.138462 | 1.000000 | 2.000000 |  2.500000 |   5.000000 |   6.000000 | Run actions/cache@v2                               |
|      4 | 1.000000 | 2.000000 | 2.000000 | 2.000000 | 2.000000 |  2.500000 |   3.000000 |   3.000000 | Set up Perl                                        |
|      5 | 0.000000 | 0.000000 | 0.000000 | 0.000000 | 0.000000 |  0.000000 |   0.000000 |   0.000000 | Remove Perl Problem Matcher                        |
|      6 | 0.000000 | 0.000000 | 7.323077 | 0.000000 | 2.500000 | 26.000000 | 176.500000 | 178.000000 | Run cpanm -L local                                 |
|        |          |          |          |          |          |           |            |            | --installdeps .                                    |
|      7 | 0.000000 | 2.000000 | 1.553846 | 2.000000 | 3.000000 |  4.000000 |   5.000000 |   6.000000 | Run cpanm -L local                                 |
|        |          |          |          |          |          |           |            |            | Test2::Plugin::GitHub::Actions::AnnotateFailedTest |
|      8 | 2.000000 | 2.000000 | 2.466667 | 2.000000 | 3.000000 |  4.000000 |   4.000000 |   4.000000 | Run prove -Ilocal/lib/perl5                        |
|        |          |          |          |          |          |           |            |            | -Ilib -lv t                                        |
|     13 | 0.000000 | 0.000000 | 0.371429 | 0.000000 | 1.000000 |  1.000000 |   1.000000 |   1.000000 | Post Run actions/cache@v2                          |
|     14 | 0.000000 | 0.000000 | 0.200000 | 0.000000 | 1.000000 |  1.000000 |   1.000000 |   1.000000 | Post Run actions/checkout@v2                       |
|     15 | 0.000000 | 0.000000 | 0.338462 | 0.000000 | 1.000000 |  1.000000 |   1.500000 |   2.000000 | Post Run actions/cache@v2                          |
|     16 | 0.000000 | 0.000000 | 0.033333 | 0.000000 | 0.000000 |  0.000000 |   0.500000 |   1.000000 | Post Run actions/checkout@v2                       |
|     17 | 0.000000 | 0.000000 | 0.033333 | 0.000000 | 0.000000 |  0.000000 |   0.500000 |   1.000000 | Complete job                                       |
+--------+----------+----------+----------+----------+----------+-----------+------------+------------+----------------------------------------------------+

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AvailableFormatsForCLI

func AvailableFormatsForCLI() string

func AvailableSortFieldsForCLI

func AvailableSortFieldsForCLI() string

func IsValidFormatName

func IsValidFormatName(formatName string) bool

func IsValidSortFieldName

func IsValidSortFieldName(fieldName string) bool

func NewReplaceRule

func NewReplaceRule(regexpStr, replace string) (*replaceRule, error)

func SortProfileBy

func SortProfileBy(profile TaskStepProfileResult, fieldName string) error

func WriteJSON

func WriteJSON(w io.Writer, profileResult ProfileInput) (err error)

func WriteTSV

func WriteTSV(w io.Writer, profileResult ProfileInput) error

func WriteTable

func WriteTable(w io.Writer, profileResult ProfileInput, markdown bool) error

func WriteWithFormat

func WriteWithFormat(w io.Writer, profileResult ProfileInput, format string) error

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClientWithConfig

func NewClientWithConfig(ctx context.Context, config *ClientConfig) *Client

func (Client) GetWorkflowJobByID

func (c Client) GetWorkflowJobByID(ctx context.Context, owner, repo string, jobID int64) (*github.WorkflowJob, *github.Response, error)

func (Client) ListWorkflowJobs

func (c Client) ListWorkflowJobs(ctx context.Context, owner, repo string, runID int64, opts *github.ListWorkflowJobsOptions) (*github.Jobs, *github.Response, error)

func (Client) ListWorkflowRunsByFileName

func (c Client) ListWorkflowRunsByFileName(ctx context.Context, owner, repo, workflowFileName string, opts *github.ListWorkflowRunsOptions) (*github.WorkflowRuns, *github.Response, error)

type ClientConfig

type ClientConfig struct {
	AccessToken    string
	Cache          bool
	CacheDirectory string
}

type ProfileConfig

type ProfileConfig struct {
	Owner            string        `toml:"owner"`
	Repository       string        `toml:"repository"`
	WorkflowFileName string        `toml:"workflow-file"`
	Cache            bool          `toml:"cache"`
	CacheDirectory   string        `toml:"cache-directory"`
	Concurrency      int           `toml:"concurrency"`
	NumberOfJob      int           `toml:"number-of-job"`
	AccessToken      string        `toml:"access-token"`
	Format           string        `toml:"format"`
	SortBy           string        `toml:"sort"`
	Reverse          bool          `toml:"reverse"`
	Verbose          bool          `toml:"verbose"`
	JobNameRegexp    string        `toml:"job-name-regexp"`
	Replace          []replaceRule `toml:"replace_rule"`
}

func DefaultProfileConfig

func DefaultProfileConfig() *ProfileConfig

func LoadConfigFromTOML

func LoadConfigFromTOML(filename string) (*ProfileConfig, error)

func OverrideCLIArgs

func OverrideCLIArgs(tomlConfig *ProfileConfig, cliArgs *ProfileConfigCLIArgs) (newConfig *ProfileConfig)

func (ProfileConfig) Dump

func (c ProfileConfig) Dump() string

func (ProfileConfig) Validate

func (config ProfileConfig) Validate() error

type ProfileConfigCLIArgs

type ProfileConfigCLIArgs struct {
	AccessToken      *string `long:"access-token" description:"Access token for GitHub"`
	Cache            *bool   `long:"cache" description:"Enable disk cache" default-mask:"true"`
	CacheDirectory   *string `long:"cache-dir" description:"Where to store cache data"`
	Concurrency      *int    `long:"concurrency" short:"j" description:"Concurrency of GitHub API client" default-mask:"2"`
	ConfigPath       *string `long:"config" description:"Path to configuration TOML file"`
	NumberOfJob      *int    `long:"number-of-job" short:"n" description:"The number of job to analyze" default-mask:"20"`
	Format           *string `` /* 132-byte string literal not displayed */
	JobNameRegexp    *string `long:"job-name-regexp" description:"Filter regular expression for a job name"`
	Owner            *string `long:"owner" description:"Repository owner name"`
	Repository       *string `long:"repository" description:"Repository name"`
	Reverse          *bool   `long:"reverse" short:"r" description:"Reverse the result of sort" default-mask:"false"`
	SortBy           *string `long:"sort" short:"s" description:"A field name to sort by" default-mask:"number"`
	Verbose          *bool   `long:"verbose" description:"Verbose mode"`
	WorkflowFileName *string `long:"workflow-file" description:"Workflow file name"`
}

ProfileConfigCLIArgs is a set of option from command-line arguments see DefaultProfileConfig() in config.go for more details

type ProfileForFormatter

type ProfileForFormatter struct {
	Name    string             `json:"name"`
	Profile []*TaskStepProfile `json:"profile"`
}

type ProfileInput

type ProfileInput []*ProfileForFormatter

type TaskStepProfile

type TaskStepProfile struct {
	Name         string  `json:"name"`
	Number       int64   `json:"number"`
	Min          float64 `json:"min"`
	Max          float64 `json:"max"`
	Median       float64 `json:"median"`
	Mean         float64 `json:"mean"`
	Percentile50 float64 `json:"50percentile"`
	Percentile90 float64 `json:"90percentile"`
	Percentile95 float64 `json:"95percentile"`
	Percentile99 float64 `json:"99percentile"`
}

type TaskStepProfileResult

type TaskStepProfileResult = []*TaskStepProfile

func ProfileTaskStep

func ProfileTaskStep(steps []*github.TaskStep) (profileResult TaskStepProfileResult, err error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL