-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (81 loc) · 2.87 KB
/
run-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
name: Tests with Coverage Check
on:
push:
branches:
# - '*'
- 'main'
pull_request:
branches:
- main
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'yarn'
- name: Install Dependencies
run: yarn install --frozen-lockfile
- name: Run Jest Tests
run: yarn test --collectCoverage=false
# coverage:
# runs-on: ubuntu-latest
# needs: test
# steps:
# # - name: For act to work (local testing)
# # run: npm -g install yarn
# - uses: actions/checkout@v3
# with:
# fetch-depth: 0 # Fetch all history for accurate comparison
# - name: Setup Node
# uses: actions/setup-node@v3
# with:
# node-version: '18'
# cache: 'yarn'
# - name: Install Dependencies
# run: yarn install --frozen-lockfile
# - name: Checkout Main Branch
# uses: actions/checkout@v3
# with:
# ref: main
# path: main
# - name: Temp - Install Jest
# run: yarn add jest
# - name: Run Jest Coverage for Main
# working-directory: main
# run: yarn test --coverage
# - name: Run Jest Coverage for Current Branch
# run: yarn test --coverage
# - name: Get Coverage Difference
# id: coverage-difference
# run: |
# if [[ -f ./coverage/lcov.info ]] && [[ -f ./main/coverage/lcov.info ]]; then
# echo "Current Coverage:"
# currentCoverage=$(cat ./coverage/lcov.info | yarn jest-coverage-badges -r lcov | grep -oP '(?<=coverage: )\d+')
# echo "$currentCoverage"
# echo "Main Coverage:"
# mainCoverage=$(cat ./main/coverage/lcov.info | yarn jest-coverage-badges -r lcov | grep -oP '(?<=coverage: )\d+')
# echo "$mainCoverage"
# diff=$(echo "$mainCoverage" "$currentCoverage" | awk '{print ($2-$1)}')
# echo "::set-output name=diff::$diff"
# else
# echo "One or both coverage reports are missing. Skipping comparison."
# echo "::set-output name=diff::0" # Treat missing reports as no change
# fi
# - name: Fail if Coverage Decreased
# if: steps.coverage-difference.outputs.diff < 0
# run: |
# echo "🛑 Coverage decreased compared to main!"
# exit 1
# - name: Upload Coverage to Codecov
# uses: codecov/codecov-action@v3
# with:
# token: ${{ secrets.CODECOV_TOKEN }}
# - name: Coverage Summary
# run: |
# echo "✅ Jest coverage passed with:"
# echo "$(cat ./coverage/lcov.info | yarn jest-coverage-badges -r lcov)"
# echo "View detailed coverage report on Codecov."