-
Notifications
You must be signed in to change notification settings - Fork 3
/
action.yaml
103 lines (98 loc) · 3.39 KB
/
action.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: Create Issue From pytest log
description: >-
Create an issue for failed tests from a pytest-reportlog file.
inputs:
log-path:
description: >-
The path to the log file
required: true
issue-title:
description: >-
Title of issue being created or updated. Can be a parametrized string, in which case
a new issue will be opened for all variations.
required: false
default: "⚠️ Nightly upstream-dev CI failed ⚠️"
issue-label:
description: >-
Labels to apply to issue
required: false
default: "CI"
assignees:
description: >-
Comma-separated users to assign to the issue (no spaces). All assigned users have to
have commit rights.
required: false
default: ""
outputs: {}
branding:
color: "red"
icon: "alert-triangle"
runs:
using: composite
# TODO: learn enough javascript / node.js to write the reportlog parsing
steps:
- name: print environment information
shell: bash -l {0}
run: |
python --version
python -m pip list
- name: install dependencies
shell: bash -l {0}
run: |
python -m pip install pytest more-itertools
- name: produce the issue body
shell: bash -l {0}
run: |
python $GITHUB_ACTION_PATH/parse_logs.py ${{ inputs.log-path }}
- name: create the issue
uses: actions/github-script@v7
with:
github-token: ${{ github.token }}
script: |
const fs = require('fs');
const pytest_logs = fs.readFileSync('pytest-logs.txt', 'utf8');
const assignees = "${{inputs.assignees}}".split(",");
const workflow_url = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
const issue_body = `[Workflow Run URL](${workflow_url})\n${pytest_logs}`;
const variables = {
owner: context.repo.owner,
name: context.repo.repo,
label: "${{ inputs.issue-label }}",
creator: "app/github-actions",
title: "${{ inputs.issue-title }}"
};
const query_string = `repo:${variables.owner}/${variables.name} author:${variables.creator} label:${variables.label} is:open in:title ${variables.title}`;
// Run GraphQL query against GitHub API to find the most recent open issue used for reporting failures
const query = `query {
search(query: "${query_string}", type:ISSUE, first: 1) {
edges {
node {
... on Issue {
body
id
number
}
}
}
}
}`;
const result = await github.graphql(query);
// If no issue is open, create a new issue,
// else update the body of the existing issue.
if (result.search.edges.length === 0) {
github.rest.issues.create({
owner: variables.owner,
repo: variables.name,
body: issue_body,
title: variables.title,
labels: [variables.label],
assignees: assignees
});
} else {
github.rest.issues.update({
owner: variables.owner,
repo: variables.name,
issue_number: result.search.edges[0].node.number,
body: issue_body
});
}