-
Notifications
You must be signed in to change notification settings - Fork 1
99 lines (96 loc) · 3.13 KB
/
coverage.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
# This workflow will run our tests and generate an lcov code coverage file.
# If our coverage has not dropped below a certain percent, it will send that
# coverage to Coveralls
name: Code Coverage
on:
workflow_call:
inputs:
test_script:
required: false
type: string
default: npx jest --coverage
comparison_branch:
required: false
type: string
default: main
secrets:
NPM_TOKEN:
required: false
MAPBOX_API_KEY:
required: false
caller_github_token:
required: true
jobs:
base-coverage:
runs-on: ubuntu-latest
outputs:
coverage-percent: ${{ steps.parse-coverage.outputs.coverage-percent }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.comparison_branch }}
- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 16.x
registry-url: 'https://registry.npmjs.org'
- run: npm ci --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: npm rebuild
- run: ${{ inputs.test_script }}
env:
MAPBOX_API_KEY: ${{ secrets.MAPBOX_API_KEY }}
- uses: yext/slapshot-reusable-workflows/get-coverage-percent@@node-20-upgrade
id: parse-coverage
- run: echo base coverage is ${{ steps.parse-coverage.outputs.coverage-percent }}%
current-coverage:
runs-on: ubuntu-latest
outputs:
coverage-percent: ${{ steps.parse-coverage.outputs.coverage-percent }}
steps:
- uses: actions/checkout@v3
- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 16.x
registry-url: 'https://registry.npmjs.org'
- run: npm ci --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: npm rebuild
- run: ${{ inputs.test_script }}
env:
MAPBOX_API_KEY: ${{ secrets.MAPBOX_API_KEY }}
- uses: yext/slapshot-reusable-workflows/get-coverage-percent@@node-20-upgrade
id: parse-coverage
- run: echo current coverage is ${{ steps.parse-coverage.outputs.coverage-percent }}%
- name: Upload lcov build artifact
uses: actions/upload-artifact@v3
with:
name: coverage
path: coverage/
retention-days: 1
Coveralls:
runs-on: ubuntu-latest
needs: [base-coverage, current-coverage]
steps:
- uses: actions/checkout@v3
- name: Check if percent is too low
run: |
percentIsTooLow=$(echo ${{ needs.base-coverage.outputs.coverage-percent }} ${{ needs.current-coverage.outputs.coverage-percent }} |
awk '{print ($1 - $2 > 2) }')
if [ $((percentIsTooLow)) -ne 0 ]
then
echo coverage dropped more than 2 percent, exiting action
exit 1
fi
- name: Download the current coverage
uses: actions/download-artifact@v3
with:
name: coverage
path: coverage/
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.caller_github_token }}