Skip to content

Commit

Permalink
Merge pull request #11 from urcomputeringpal/load-workflow
Browse files Browse the repository at this point in the history
Accept target runtime, success rate as inputs
  • Loading branch information
jnewland authored May 25, 2023
2 parents 0ba3f19 + 3a6d693 commit 094e693
Show file tree
Hide file tree
Showing 13 changed files with 7,931 additions and 1,544 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ on:
push:
branches:
- main
tags:
- v*
schedule:
- cron: "0 * * * *"

jobs:
prepare:
test:
runs-on: ubuntu-latest
steps:
- run: sleep 5
workflow-run-history:
name: workflow run history
needs: prepare
name: Workflow
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- uses: ./
id: summarizeHistory
timeout-minutes: 2
test:
needs: workflow-run-history
runs-on: ubuntu-latest
steps:
- run: echo true
- run: echo "$HISTORY_OUTPUTS"
env:
HISTORY_OUTPUTS: ${{ toJSON(steps.summarizeHistory.outputs) }}
35 changes: 21 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
# workflow-run-history

Adds a Markdown Step Summary explaining the historical performance and success rate of a workflow over the previous month.
Adds a Markdown Step Summary explaining the historical performance and success rate of a workflow over the previous week.

### Not yet implemented

- Compare performance / success rate against default branch
- Custom date rages
- Compares performance / success rate against other workflows runs on the default branch, PRs, and tags
- Allows setting performance and success rate targets
- Outputs values that indicate whether or not the workflow is meeting its targets

## Example

<h1>Workflow Run History over the last month (20 total runs)</h1>
<h1>Success rate: 75% (15 successes out of 20 runs)</h1>
<h1>15 successful runs</h1>
<table><tr><th>Percentile</th><th>Success duration in seconds</th></tr><tr><td>99th</td><td>25</td></tr><tr><td>90th</td><td>35</td></tr><tr><td>50th</td><td>41</td></tr></table>
<h1>5 failing runs</h1>
<table><tr><th>Percentile</th><th>Success duration in seconds</th></tr><tr><td>99th</td><td>29</td></tr><tr><td>90th</td><td>29</td></tr><tr><td>50th</td><td>39</td></tr></table>
<h1>Run status breakdown</h1>
<table><tr><th>Status</th><th>Percent of total</th></tr><tr><td>success</td><td>75%</td></tr><tr><td>failure</td><td>25%</td></tr></table>

https://github.com/urcomputeringpal/workflow-run-history/actions/runs/5079482931

## Usage

Expand All @@ -41,5 +32,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: urcomputeringpal/workflow-run-history@v0
id: history
timeout-minutes: 2
with:
# # Target performance
# Target an average workflow runtime of 60 seconds.
target-seconds: "60"
target-percentile: "50"

# # Target success rates
# This workflow should complete 99% of the time on the default branch.
target-default-success-rate: "99"
# This workflow should complete 90% of the time on PRs.
target-pr-success-rate: "90"
- run: |
echo "This workflow run hit its target performance: ${{ steps.history.outputs.hit-target-seconds }}"
echo "This workflow has historically hit its target performance on PRs: ${{ steps.history.outputs.hit-target-pr-success-percentile }}"
echo "This workflow has historically hit its target success rate on main: ${{ steps.history.outputs.hit-target-default-success-rate }}"
```
112 changes: 109 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,87 @@
name: Summarize Workflow History
description: Performance, success rate, etc
inputs:
github-token:
description: The GitHub token used to create an authenticated client
default: ${{ github.token }}

target-default-success-rate:
description: "Target default branch success rate"
required: false
default: "99"
target-pr-success-rate:
description: "Target PR success rate"
required: false
default: "90"
target-tag-success-rate:
description: "Target tag success rate"
required: false
default: "99"

target-seconds:
description: "Target runtime seconds. Defaults to 60."
required: false
default: "60"
target-percentile:
description: "Target percentile. Higher percentiles are faster. Defaults to 50 (average)."
required: false
default: "50"

target-default-seconds:
description: "Target latency for default branch in seconds. Defaults to `target-seconds`."
required: false
target-default-percentile:
description: "Target percentile for default branch runtime. Defaults to `target-percentile`."
required: false

target-tag-seconds:
description: "Target latency for tag runtime. Defaults to `target-default-seconds`."
required: false
target-tag-percentile:
description: "Target percentile for tag runtime. Defaults to `target-default-percentile`."
required: false

target-pr-seconds:
description: "Target latency for PR runtime. Defaults to `target-seconds`."
required: false
target-pr-percentile:
description: "Target percentile for PR runtime. Defaults to `target-percentile`."
required: false

target-pr-failure-seconds:
description: "Target latency for PR failure runtime. Defaults to `target-pr-seconds`."
required: false
target-pr-failure-percentile:
description: "Target percentile for PR failure runtime. Defaults to `target-pr-percentile`."
required: false

outputs:
hit-target-default-success-rate:
description: "Hit target default success rate"
value: ${{ steps.function.outputs.hit-target-default-success-rate }}
hit-target-tag-success-rate:
description: "Hit target tag success rate"
value: ${{ steps.function.outputs.hit-target-tag-success-rate }}
hit-target-pr-success-rate:
description: "Hit target PR success rate"
value: ${{ steps.function.outputs.hit-target-pr-success-rate }}

hit-target-seconds:
description: "Hit target seconds"
value: ${{ steps.function.outputs.hit-target-seconds }}

hit-target-default-success-percentile:
description: "Hit target default success percentile"
value: ${{ steps.function.outputs.hit-target-default-success-percentile }}
hit-target-tag-success-percentile:
description: "Hit target tag success rate"
value: ${{ steps.function.outputs.hit-target-tag-success-percentile }}
hit-target-pr-success-percentile:
description: "Hit target PR success percentile"
value: ${{ steps.function.outputs.hit-target-pr-success-percentile }}
hit-target-failure-pr-percentile:
description: "Hit target failure PR percentile"
value: ${{ steps.function.outputs.hit-target-failure-pr-percentile }}

runs:
using: "composite"
Expand All @@ -16,10 +98,34 @@ runs:

with:
path: ${{ steps.path.outputs.action_path }}
build: npm run test && npm run build

- name: summarizeHistory
id: function
uses: urcomputeringpal/github-script-ts@ffbd14d3da998a8c02d11cb421fe374104026b59 # v0.0.9
uses: actions/github-script@v6
# You can pass environment variables to your script and then
# read them from process.env.
# https://github.com/actions/github-script/#use-env-as-input
env:
TARGET_DEFAULT_SUCCESS_RATE: ${{ inputs.target-default-success-rate }}
TARGET_PR_SUCCESS_RATE: ${{ inputs.target-pr-success-rate }}
TARGET_TAG_SUCCESS_RATE: ${{ inputs.target-tag-success-rate }}
TARGET_SECONDS: ${{ inputs.target-seconds }}
TARGET_PERCENTILE: ${{ inputs.target-percentile }}
TARGET_DEFAULT_SECONDS: ${{ inputs.target-default-seconds }}
TARGET_DEFAULT_PERCENTILE: ${{ inputs.target-default-percentile }}
TARGET_TAG_SECONDS: ${{ inputs.target-tag-seconds }}
TARGET_TAG_PERCENTILE: ${{ inputs.target-tag-percentile }}
TARGET_PR_SECONDS: ${{ inputs.target-pr-seconds }}
TARGET_PR_PERCENTILE: ${{ inputs.target-pr-percentile }}
TARGET_PR_FAILURE_SECONDS: ${{ inputs.target-pr-failure-seconds }}
TARGET_PR_FAILURE_PERCENTILE: ${{ inputs.target-pr-failure-percentile }}
with:
path: ${{ steps.path.outputs.action_path }}
function: summarizeHistory
github-token: ${{ inputs.github-token }}
retries: 3
# missing 404 to allow for our own workflow run to take a few seconds to show up
retry-exempt-status-codes: 400,401,403,422
debug: true
script: |
const { summarizeHistory } = await import("${{ steps.github-script-ts.outputs.module }}");
return await summarizeHistory({github, core,context});
Loading

0 comments on commit 094e693

Please sign in to comment.