-
Notifications
You must be signed in to change notification settings - Fork 12
125 lines (109 loc) · 4.24 KB
/
regression_tests.yml
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# .github/workflows/update_regression_tests.yml
# for details on triggering a workflow from a comment, see:
# https://dev.to/zirkelc/trigger-github-workflow-for-comment-on-pull-request-45l2
name: Regression Tests
on:
issue_comment: # trigger from comment; event runs on the default branch
types: [created]
jobs:
update_regression_tests:
name: update_regression_tests
runs-on: ubuntu-20.04
# Trigger from a comment that contains '/test_regression'
if: github.event.issue.pull_request && contains(github.event.comment.body, '/test_regression')
# workflow needs permissions to write to the PR
permissions:
contents: write
pull-requests: write
issues: read
steps:
- name: Create initial status comment
uses: actions/github-script@v7
id: initial-comment
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const response = await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '## Regression Test\n⏳ Workflow is currently running...'
});
return response.data.id;
- name: Check if PR is from fork
id: check-fork
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
return pr.data.head.repo.fork;
- uses: actions/checkout@v3
with:
ref: main
lfs: true
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
architecture: 'x64'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"
- name: Update baseline
id: update-baseline
run: |
NEW_BASELINE=1 pytest -m regression
cp tests/regression_test_baselines.json /tmp/regression_test_baselines.json
- name: Get PR branch
uses: xt0rted/pull-request-comment-branch@v3
id: comment-branch
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout PR branch
uses: actions/checkout@v3
with:
ref: ${{ steps.comment-branch.outputs.head_sha }} # using head_sha vs. head_ref makes this work for forks
lfs: true
fetch-depth: 0 # This ensures we can checkout main branch too
- name: Run comparison
id: comparison
run: |
cp /tmp/regression_test_baselines.json tests/regression_test_baselines.json
pytest -m regression
- name: Update comment with results
uses: actions/github-script@v7
if: always() # Run this step even if previous steps fail
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
let status = '${{ steps.comparison.outcome }}' === 'success' ? '✅' : '❌';
let message = '## Regression Baseline Update\n' + status + ' Process completed\n\n';
try {
const TestReport = fs.readFileSync('tests/regression_test_report.txt', 'utf8');
message += '```\n' + TestReport + '\n```\n\n';
// Add information about where the changes were pushed
if ('${{ steps.comparison.outcome }}' === 'success') {
if (!${{ fromJson(steps.check-fork.outputs.result) }}) {
message += '✨ Changes have been pushed directly to this PR\n';
} else {
const prNumber = '${{ steps.create-pr.outputs.pull-request-number }}';
message += `✨ Changes have been pushed to a new PR #${prNumber} because this PR is from a fork\n`;
}
}
} catch (error) {
message += '⚠️ No test report was generated\n';
}
await github.rest.issues.updateComment({
comment_id: ${{ steps.initial-comment.outputs.result }},
owner: context.repo.owner,
repo: context.repo.repo,
body: message
});