Skip to content

Commit d434c8b

Browse files
Mrityunjeyan SarvabhoumanMrityunjeyan Sarvabhouman
authored andcommitted
Update workflows to run tests and comment results from any branch
1 parent 62eab2e commit d434c8b

3 files changed

Lines changed: 193 additions & 2 deletions

File tree

.github/workflows/actions-test.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
11
name: Reporterplus marketplace actions test
22

33
on:
4+
workflow_dispatch:
45
pull_request:
56
branches:
67
- main
78
- "[0-9]+\\.[0-9]+\\.[0-9]+"
9+
issue_comment:
10+
types: [created]
11+
12+
permissions:
13+
contents: read
14+
issues: write
15+
pull-requests: write
816

917
jobs:
1018
test:
19+
if: |
20+
github.event_name == 'pull_request' ||
21+
github.event_name == 'workflow_dispatch' ||
22+
(
23+
github.event_name == 'issue_comment' &&
24+
github.event.issue.pull_request &&
25+
contains(github.event.comment.body, 'run tests') &&
26+
(
27+
github.event.comment.author_association == 'OWNER' ||
28+
github.event.comment.author_association == 'MEMBER' ||
29+
github.event.comment.author_association == 'COLLABORATOR'
30+
)
31+
)
1132
runs-on: ubuntu-latest
1233

1334
strategy:
@@ -17,6 +38,8 @@ jobs:
1738
steps:
1839
- name: 📥 Checkout code
1940
uses: actions/checkout@v3
41+
with:
42+
ref: ${{ github.event_name == 'issue_comment' && format('refs/pull/{0}/head', github.event.issue.number) || github.ref }}
2043

2144
- name: 🐍 Set up Python ${{ matrix.python-version }}
2245
uses: actions/setup-python@v4
@@ -52,3 +75,34 @@ jobs:
5275
path: |
5376
report_output_playwright/
5477
78+
notify:
79+
if: always() && github.event_name == 'issue_comment'
80+
needs: test
81+
runs-on: ubuntu-latest
82+
83+
steps:
84+
- name: Comment PR with success
85+
if: needs.test.result == 'success'
86+
uses: actions/github-script@v7
87+
with:
88+
script: |
89+
const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
90+
await github.rest.issues.createComment({
91+
issue_number: context.issue.number,
92+
owner: context.repo.owner,
93+
repo: context.repo.repo,
94+
body: `✅ Marketplace action tests passed successfully.\n\nView the logs: ${runUrl}`
95+
});
96+
97+
- name: Comment PR with failure
98+
if: needs.test.result != 'success'
99+
uses: actions/github-script@v7
100+
with:
101+
script: |
102+
const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
103+
await github.rest.issues.createComment({
104+
issue_number: context.issue.number,
105+
owner: context.repo.owner,
106+
repo: context.repo.repo,
107+
body: `❌ Marketplace action tests failed.\n\nView the logs: ${runUrl}`
108+
});

.github/workflows/unit-test-windows.yml

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
11
name: Unit Tests on Windows
22

33
on:
4+
workflow_dispatch:
45
pull_request:
56
branches:
67
- main
78
- "[0-9]+\\.[0-9]+\\.[0-9]+"
9+
issue_comment:
10+
types: [created]
11+
12+
permissions:
13+
contents: read
14+
issues: write
15+
pull-requests: write
816

917
jobs:
1018
test:
19+
if: |
20+
github.event_name == 'pull_request' ||
21+
github.event_name == 'workflow_dispatch' ||
22+
(
23+
github.event_name == 'issue_comment' &&
24+
github.event.issue.pull_request &&
25+
contains(github.event.comment.body, 'run tests') &&
26+
(
27+
github.event.comment.author_association == 'OWNER' ||
28+
github.event.comment.author_association == 'MEMBER' ||
29+
github.event.comment.author_association == 'COLLABORATOR'
30+
)
31+
)
1132
runs-on: windows-latest
1233

1334
strategy:
@@ -17,6 +38,8 @@ jobs:
1738
steps:
1839
- name: 📥 Checkout code
1940
uses: actions/checkout@v4
41+
with:
42+
ref: ${{ github.event_name == 'issue_comment' && format('refs/pull/{0}/head', github.event.issue.number) || github.ref }}
2043

2144
- name: 🐍 Set up Python ${{ matrix.python-version }}
2245
uses: actions/setup-python@v5
@@ -95,4 +118,36 @@ jobs:
95118
uses: actions/upload-artifact@v4
96119
with:
97120
name: report-warnings-windows-${{ github.job }}-${{ github.run_number }}-${{ matrix.python-version }}
98-
path: report_output_warnings/
121+
path: report_output_warnings/
122+
123+
notify:
124+
if: always() && github.event_name == 'issue_comment'
125+
needs: test
126+
runs-on: ubuntu-latest
127+
128+
steps:
129+
- name: Comment PR with success
130+
if: needs.test.result == 'success'
131+
uses: actions/github-script@v7
132+
with:
133+
script: |
134+
const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
135+
await github.rest.issues.createComment({
136+
issue_number: context.issue.number,
137+
owner: context.repo.owner,
138+
repo: context.repo.repo,
139+
body: `✅ Unit Tests on Windows passed successfully.\n\nView the logs: ${runUrl}`
140+
});
141+
142+
- name: Comment PR with failure
143+
if: needs.test.result != 'success'
144+
uses: actions/github-script@v7
145+
with:
146+
script: |
147+
const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
148+
await github.rest.issues.createComment({
149+
issue_number: context.issue.number,
150+
owner: context.repo.owner,
151+
repo: context.repo.repo,
152+
body: `❌ Unit Tests on Windows failed.\n\nView the logs: ${runUrl}`
153+
});

.github/workflows/unit-test.yml

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
11
name: Unit Tests
22

33
on:
4+
workflow_dispatch:
45
pull_request:
56
branches:
67
- main
78
- "[0-9]+\\.[0-9]+\\.[0-9]+"
9+
issue_comment:
10+
types: [created]
11+
12+
permissions:
13+
contents: read
14+
issues: write
15+
pull-requests: write
816

917
jobs:
1018
test:
19+
if: |
20+
github.event_name == 'pull_request' ||
21+
github.event_name == 'workflow_dispatch' ||
22+
(
23+
github.event_name == 'issue_comment' &&
24+
github.event.issue.pull_request &&
25+
contains(github.event.comment.body, 'run tests') &&
26+
(
27+
github.event.comment.author_association == 'OWNER' ||
28+
github.event.comment.author_association == 'MEMBER' ||
29+
github.event.comment.author_association == 'COLLABORATOR'
30+
)
31+
)
1132
runs-on: ubuntu-latest
1233

1334
strategy:
@@ -17,6 +38,8 @@ jobs:
1738
steps:
1839
- name: 📥 Checkout code
1940
uses: actions/checkout@v4
41+
with:
42+
ref: ${{ github.event_name == 'issue_comment' && format('refs/pull/{0}/head', github.event.issue.number) || github.ref }}
2043

2144
- name: 🐍 Set up Python ${{ matrix.python-version }}
2245
uses: actions/setup-python@v5
@@ -50,6 +73,7 @@ jobs:
5073
--cov=pytest_html_plus \
5174
--cov-fail-under=39 \
5275
--cov-report=term \
76+
--cov-report=xml:coverage.xml \
5377
--reruns 1 \
5478
--ignore=tests/browser \
5579
--generate-xml \
@@ -87,4 +111,62 @@ jobs:
87111
uses: actions/upload-artifact@v4
88112
with:
89113
name: report-warnings-${{ github.job }}-${{ github.run_number }}-${{ matrix.python-version }}
90-
path: report_output_warnings/
114+
path: report_output_warnings/
115+
116+
- name: 📤 Upload Coverage XML
117+
if: always() && matrix.python-version == '3.11'
118+
uses: actions/upload-artifact@v4
119+
with:
120+
name: coverage-${{ github.job }}-${{ github.run_number }}-${{ matrix.python-version }}
121+
path: coverage.xml
122+
123+
notify:
124+
if: always() && github.event_name == 'issue_comment'
125+
needs: test
126+
runs-on: ubuntu-latest
127+
128+
steps:
129+
- name: 📥 Download Coverage XML
130+
if: needs.test.result == 'success'
131+
uses: actions/download-artifact@v4
132+
with:
133+
name: coverage-test-${{ github.run_number }}-3.11
134+
path: coverage-artifact
135+
136+
- name: 📊 Read Coverage Percentage
137+
if: needs.test.result == 'success'
138+
id: coverage
139+
run: |
140+
python3 - <<'PY' >> "$GITHUB_OUTPUT"
141+
import xml.etree.ElementTree as ET
142+
143+
tree = ET.parse("coverage-artifact/coverage.xml")
144+
line_rate = float(tree.getroot().attrib["line-rate"]) * 100
145+
print(f"value={line_rate:.2f}%")
146+
PY
147+
148+
- name: Comment PR with success
149+
if: needs.test.result == 'success'
150+
uses: actions/github-script@v7
151+
with:
152+
script: |
153+
const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
154+
await github.rest.issues.createComment({
155+
issue_number: context.issue.number,
156+
owner: context.repo.owner,
157+
repo: context.repo.repo,
158+
body: `✅ Unit Tests passed successfully.\n\nCoverage: ${{ steps.coverage.outputs.value }}\n\nView the logs: ${runUrl}`
159+
});
160+
161+
- name: Comment PR with failure
162+
if: needs.test.result != 'success'
163+
uses: actions/github-script@v7
164+
with:
165+
script: |
166+
const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`;
167+
await github.rest.issues.createComment({
168+
issue_number: context.issue.number,
169+
owner: context.repo.owner,
170+
repo: context.repo.repo,
171+
body: `❌ Unit Tests failed.\n\nView the logs: ${runUrl}`
172+
});

0 commit comments

Comments
 (0)