Skip to content

Commit 23c8936

Browse files
authored
Merge pull request #28 from urcomputeringpal/actor-branch-event
support filtering workflow runs
2 parents 094e693 + 5f937e7 commit 23c8936

File tree

7 files changed

+61
-15
lines changed

7 files changed

+61
-15
lines changed

.github/workflows/test.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,37 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- run: sleep 5
17-
workflow-run-history:
18-
name: Workflow
17+
18+
push:
19+
name: Push
20+
needs: test
21+
runs-on: ubuntu-latest
22+
if: github.event_name == 'push'
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
26+
- uses: ./
27+
id: summarizeHistory
28+
timeout-minutes: 2
29+
with:
30+
filter-event: push
31+
- run: echo "$HISTORY_OUTPUTS"
32+
env:
33+
HISTORY_OUTPUTS: ${{ toJSON(steps.summarizeHistory.outputs) }}
34+
35+
pull_request:
36+
name: Pull Request
1937
needs: test
2038
runs-on: ubuntu-latest
39+
if: github.event_name == 'pull_request'
2140
steps:
2241
- name: Checkout
2342
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
2443
- uses: ./
2544
id: summarizeHistory
2645
timeout-minutes: 2
46+
with:
47+
filter-event: pull_request
2748
- run: echo "$HISTORY_OUTPUTS"
2849
env:
2950
HISTORY_OUTPUTS: ${{ toJSON(steps.summarizeHistory.outputs) }}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ jobs:
4545
target-default-success-rate: "99"
4646
# This workflow should complete 90% of the time on PRs.
4747
target-pr-success-rate: "90"
48+
49+
# filter-actor: "urcomputeringpal"
50+
# filter-branch: "main"
51+
# filter-event: "push"
4852
- run: |
4953
echo "This workflow run hit its target performance: ${{ steps.history.outputs.hit-target-seconds }}"
5054
echo "This workflow has historically hit its target performance on PRs: ${{ steps.history.outputs.hit-target-pr-success-percentile }}"

action.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ inputs:
5555
description: "Target percentile for PR failure runtime. Defaults to `target-pr-percentile`."
5656
required: false
5757

58+
filter-actor:
59+
description: "Filter by actor"
60+
required: false
61+
filter-branch:
62+
description: "Filter by branch"
63+
required: false
64+
filter-event:
65+
description: "Filter by event"
66+
required: false
67+
5868
outputs:
5969
hit-target-default-success-rate:
6070
description: "Hit target default success rate"
@@ -120,6 +130,9 @@ runs:
120130
TARGET_PR_PERCENTILE: ${{ inputs.target-pr-percentile }}
121131
TARGET_PR_FAILURE_SECONDS: ${{ inputs.target-pr-failure-seconds }}
122132
TARGET_PR_FAILURE_PERCENTILE: ${{ inputs.target-pr-failure-percentile }}
133+
FILTER_ACTOR: ${{ inputs.filter-actor }}
134+
FILTER_BRANCH: ${{ inputs.filter-branch }}
135+
FILTER_EVENT: ${{ inputs.filter-event }}
123136
with:
124137
github-token: ${{ inputs.github-token }}
125138
retries: 3

index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ export async function summarizeHistory(args: GitHubScriptArguments): Promise<voi
1717
});
1818
const workflow_id = run.data.workflow_id;
1919

20-
// TODO link to the workflow history
21-
// const workflowResponse = await github.rest.actions.getWorkflow({
22-
// ...context.repo,
23-
// workflow_id,
24-
// });
20+
const actor = process.env.FILTER_ACTOR == "" ? undefined : process.env.FILTER_ACTOR;
21+
const branch = process.env.FILTER_BRANCH == "" ? undefined : process.env.FILTER_BRANCH;
22+
const event = process.env.FILTER_EVENT == "" ? undefined : process.env.FILTER_EVENT;
2523

26-
getWorkflowRuns(workflow_id, { github, context, core }).then(groupedWorkflowRuns => {
24+
getWorkflowRuns(workflow_id, actor, branch, event, { github, context, core }).then(groupedWorkflowRuns => {
2725
const totalRuns = Array.from(groupedWorkflowRuns.values()).reduce(
2826
(total, group) => total + group.runs.length,
2927
0

renovate.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
{
2-
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3-
"extends": [
4-
"github>urcomputeringpal/.github"
5-
]
2+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3+
"extends": ["github>urcomputeringpal/.github"]
64
}

src/workflowGroup.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ describe("getWorkflowRuns", () => {
260260
core,
261261
};
262262

263-
const groupedRuns = await getWorkflowRuns(1234, mockArgs);
263+
const groupedRuns = await getWorkflowRuns(1234, undefined, undefined, undefined, mockArgs);
264264

265265
expect(mockGithub.paginate.iterator).toHaveBeenCalledWith(mockGithub.rest.actions.listWorkflowRuns, {
266266
owner: "status",
@@ -315,12 +315,15 @@ describe("getWorkflowRuns", () => {
315315
core,
316316
};
317317

318-
const groupedRuns = await getWorkflowRuns(1234, mockArgs);
318+
const groupedRuns = await getWorkflowRuns(1234, "actor", "branch", "event", mockArgs);
319319

320320
expect(mockGithub.paginate.iterator).toHaveBeenCalledWith(mockGithub.rest.actions.listWorkflowRuns, {
321321
owner: "status",
322322
repo: "status",
323323
workflow_id: 1234,
324+
actor: "actor",
325+
branch: "branch",
326+
event: "event",
324327
created: expect.any(String),
325328
});
326329

src/workflowGroup.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,13 @@ export type GroupedWorkflowRuns = Map<string, WorkflowGroup>;
6464
type ListWorkflowRunsResponse =
6565
Endpoints["GET /repos/{owner}/{repo}/actions/workflows/{workflow_id}/runs"]["response"]["data"]["workflow_runs"];
6666

67-
export async function getWorkflowRuns(workflow_id: number, args: GitHubScriptArguments): Promise<GroupedWorkflowRuns> {
67+
export async function getWorkflowRuns(
68+
workflow_id: number,
69+
actor: string | undefined = undefined,
70+
branch: string | undefined = undefined,
71+
event: string | undefined = undefined,
72+
args: GitHubScriptArguments
73+
): Promise<GroupedWorkflowRuns> {
6874
const workflowRuns: WorkflowRun[] = [];
6975
const { github, context, core } = args;
7076
if (github === undefined || context == undefined || core === undefined) {
@@ -85,6 +91,9 @@ export async function getWorkflowRuns(workflow_id: number, args: GitHubScriptArg
8591
...context.repo,
8692
workflow_id,
8793
created,
94+
actor,
95+
branch,
96+
event,
8897
})) {
8998
const workflowRunResponse: ListWorkflowRunsResponse =
9099
response.data.length === undefined ? (response.data as any).workflow_runs : response.data;

0 commit comments

Comments
 (0)