-
Notifications
You must be signed in to change notification settings - Fork 3
/
action.yaml
100 lines (96 loc) · 3.32 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
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
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@v6
with:
github-token: ${{ github.token }}
script: |
const fs = require('fs');
const pytest_logs = fs.readFileSync('pytest-logs.txt', 'utf8');
const title = "${{ inputs.issue-title }}"
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}`
// Run GraphQL query against GitHub API to find the most recent open issue used for reporting failures
const query = `query($owner:String!, $name:String!, $creator:String!, $label:String!){
repository(owner: $owner, name: $name) {
issues(first: 1, states: OPEN, filterBy: {createdBy: $creator, labels: [$label]}, orderBy: {field: CREATED_AT, direction: DESC}) {
edges {
node {
body
id
number
}
}
}
}
}`;
const variables = {
owner: context.repo.owner,
name: context.repo.repo,
label: "${{ inputs.issue-label }}",
creator: "github-actions[bot]"
}
const result = await github.graphql(query, variables)
// If no issue is open, create a new issue,
// else update the body of the existing issue.
if (result.repository.issues.edges.length === 0) {
github.rest.issues.create({
owner: variables.owner,
repo: variables.name,
body: issue_body,
title: title,
labels: [variables.label],
assignees: assignees
})
} else {
github.rest.issues.update({
owner: variables.owner,
repo: variables.name,
issue_number: result.repository.issues.edges[0].node.number,
body: issue_body
})
}