-
Notifications
You must be signed in to change notification settings - Fork 24
129 lines (107 loc) · 4.02 KB
/
unit_test.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
126
127
128
129
name: CI Pipeline
on:
push:
branches:
- "@feature/unit_tests"
pull_request:
branches:
- "@feature/unit_tests"
permissions:
contents: write
checks: write
pull-requests: write
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
# Backend Setup and Testing
# - name: Install system dependencies
# run: |
# sudo apt-get update
# sudo apt-get install -y build-essential python3-dev
# - name: Set up Python
# uses: actions/setup-python@v4
# with:
# python-version: "3.9"
# - name: Install Backend Dependencies
# run: pip install -r requirements.txt
# - name: Run Backend Unit Tests
# run: |
# pytest --html=report.html --self-contained-html --cov=. --cov-report=html || true
# continue-on-error: true
# - name: Ensure Report is Generated
# run: |
# if [ ! -f report.html ]; then
# echo "<html><body><h1>No report generated</h1></body></html>" > report.html
# fi
# # Frontend Setup and Testing
# - name: Set up Node.js
# uses: actions/setup-node@v3
# with:
# node-version: "19"
# - name: Install Frontend Dependencies
# working-directory: ./web
# run: npm install
# - name: Run Frontend Unit Tests
# working-directory: ./web
# run: npm run test
# - name: Generate Frontend Coverage Report
# working-directory: ./web
# run: npm run test:coverage
# - name: Prepare Report Directory
# run: |
# mkdir -p ./public/reports/frontend
# mkdir -p ./public/reports/frontend/coverage
# mv ./web/reports/test-report.html ./public/reports/frontend/
# mv ./web/coverage/lcov-report/* ./public/reports/frontend/coverage/
# mkdir -p ./public/reports/backend
# mkdir -p ./public/reports/backend/coverage
# mv report.html ./public/reports/backend/
# mv htmlcov/* ./public/reports/backend/coverage/
# # Deploy reports to GitHub Pages
# - name: Deploy to GitHub Pages
# if: success()
# uses: peaceiris/actions-gh-pages@v3
# with:
# github_token: ${{ secrets.GITHUB_TOKEN }}
# publish_dir: ./public/reports
# Create a GitHub Check Run with Report Links
- name: Create Check Run with Report Links
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { repo, owner } = context.repo;
const reportComment = `
### Test Reports:
- [Frontend Coverage](https://DrDroidLab.github.io/PlayBooks/reports/frontend/coverage/index.html)
- [Frontend Report](https://DrDroidLab.github.io/PlayBooks/reports/frontend/test-report.html)
- [Backend Coverage](https://DrDroidLab.github.io/PlayBooks/reports/backend/coverage/index.html)
- [Backend Report](https://DrDroidLab.github.io/PlayBooks/reports/backend/report.html)
`;
// Create a Check Run using github object
await github.rest.checks.create({
owner: owner,
repo: repo,
name: 'Test Report Links',
head_sha: context.sha,
status: 'completed',
conclusion: 'success',
output: {
title: 'Test Reports',
summary: reportComment,
text: 'Click the links above to view the test coverage and report details.'
}
});
// Comment on the Pull Request if it exists
if (context.payload.pull_request) {
const pr_number = context.payload.pull_request.number;
await github.rest.issues.createComment({
owner: owner,
repo: repo,
issue_number: pr_number,
body: reportComment
});
}