-
Notifications
You must be signed in to change notification settings - Fork 1
113 lines (95 loc) · 2.86 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
name: API tests
on:
push:
branches:
- 'main'
tags:
- 'v*'
pull_request:
types: [opened, synchronize, reopened]
jobs:
tests:
runs-on: ubuntu-22.04
permissions:
# Required to checkout the code
contents: read
strategy:
# If set to true, Github will cancel all other jobs if one of the jobs fails
fail-fast: false
matrix:
branch:
- ${{ github.head_ref }}
- "main"
services:
postgres:
image: postgres
env:
POSTGRES_USER: codex
POSTGRES_DB: notes
POSTGRES_PASSWORD: postgres
ports:
- 127.0.0.1:5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
volumes:
- ./database:/var/lib/postgresql/data
steps:
- name: Wait for PostgreSQL
uses: jakejarvis/wait-action@master
with:
time: '20s'
- name: Make runner the owner of database folder
run: sudo chown -R $USER database
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ matrix.branch }}
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 20
- name: Install dependencies
run: yarn install
- name: Run tests
run: yarn coverage
- name: Get an appropriate name for an artifact
run: echo "ARTIFACT_NAME=coverage-${{ matrix.branch }}" | tr -d ':<>|*?\r\n\/\\' >> $GITHUB_ENV
- name: Upload coverage
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: coverage
report-coverage:
needs: tests
runs-on: ubuntu-22.04
permissions:
# Required to checkout the code
contents: read
# Required to put a comment into the pull-request
pull-requests: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Get a name of the artifact
run: echo ARTIFACT_NAME="coverage-${{ github.head_ref }}" | tr -d ":<>|*?\r\n\/\\" >> $GITHUB_ENV
- name: Download coverage artifacts for the current branch
uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: coverage
- name: Download coverage artifacts for the main branch
uses: actions/download-artifact@v4
with:
name: coverage-main
path: coverage-main
- name: Report coverage
# if: always() is set to generate the report even if tests are failing
if: always()
uses: davelosert/vitest-coverage-report-action@v2
with:
json-summary-compare-path: coverage-main/coverage-summary.json