-
-
Notifications
You must be signed in to change notification settings - Fork 7
69 lines (56 loc) · 1.91 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
name: Tests
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Install pnpm
run: npm install -g pnpm
- run: pnpm install
# Run tests and output results to a file
- name: Run tests and capture output
run: |
pnpm test > test-result.txt
env:
CI: true
# Sanitize the test-result.txt by removing non-printable characters
- name: Sanitize test output
run: |
tr -cd '\11\12\15\40-\176' < test-result.txt > sanitized-test-result.txt
- name: Check Node.js version
run: node -v
- name: Print sanitized test output
run: cat sanitized-test-result.txt
# Extract passing test count from the sanitized output
- name: Parse passing test count
id: test_count
run: |
PASSING_TESTS=$(grep -Eo '[0-9]+ passing' sanitized-test-result.txt | grep -Eo '[0-9]+')
echo "Passing tests: $PASSING_TESTS"
# Create JSON file with the test count
echo "{ \"schemaVersion\": 1, \"label\": \"tests\", \"message\": \"$PASSING_TESTS tests passing\", \"color\": \"green\" }" > tests-status.json
# Commit the updated JSON file back to the repo
- name: Commit test count JSON
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
git add tests-status.json
git commit -m "Update test count"
git push origin main
# Prevents workflow from failing if no changes are made
continue-on-error: true