-
Notifications
You must be signed in to change notification settings - Fork 0
111 lines (100 loc) · 3.64 KB
/
test.yaml
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
name: 🧪 Test Workflow
on:
# This workflow is called by the CI/CD Workflow (see ./cicd.yaml)
workflow_call:
secrets:
CODECOV_TOKEN: { required: true }
outputs:
success:
description: "Whether the tests passed"
value: ${{ jobs.run-tests.outputs.success }}
# This workflow can be manually triggered
workflow_dispatch:
jobs:
run-tests:
name: 🧪 Run Tests
runs-on: ubuntu-latest
outputs:
success: ${{ steps.run-tests.outputs.success }}
permissions:
contents: read # to checkout the code
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
- name: Install Dependencies
run: npm ci --include=dev
- name: Run Linters
run: npm run lint
- name: Run Tests
id: run-tests
run: |
npm run test:ci
echo "success=$( [ $? == 0 ] && echo true || echo false )" >> "$GITHUB_OUTPUT"
- name: Upload Test Coverage Reports
uses: actions/upload-artifact@v4
with:
name: test-coverage-reports
path: ./coverage
update-codecov:
name: ☂️ Update CodeCov
runs-on: ubuntu-latest
needs: run-tests # run job if tests passed
if: needs.run-tests.outputs.success == 'true'
steps:
- uses: actions/download-artifact@v4
with: { name: test-coverage-reports }
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
update-pull-request:
name: 📝 Update PR
runs-on: ubuntu-latest
needs: run-tests # run job if event=PR and tests passed
if: github.event_name == 'pull_request' && needs.run-tests.outputs.success == 'true'
permissions:
contents: write # to auto-merge dependabot PRs
pull-requests: write # to update the PR
steps:
- uses: actions/checkout@v4
- name: Download Test Coverage Reports
uses: actions/download-artifact@v4
with: { name: test-coverage-reports, path: ./coverage }
- name: Add Vitest Test Coverage Report to PR
uses: davelosert/vitest-coverage-report-action@v2
- name: "(dependabot🤖) Approve & Auto-Merge PR"
if: github.actor == 'dependabot[bot]'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_URL: ${{ github.event.pull_request.html_url }}
run: |
gh pr review --approve "$PR_URL"
gh pr merge --auto --merge "$PR_URL"
update-github-commit-status:
name: 📡 Update GitHub Commit Status
runs-on: ubuntu-latest
needs: run-tests # always run job unless the workflow was cancelled
if: ${{ !cancelled() }}
permissions:
statuses: write # to update commit status
steps:
- run: |
if [ ${{ needs.run-tests.outputs.success }} == 'true' ]; then
commit_status_state='success'
description='Tests passed'
else
commit_status_state='failure'
description='Tests failed'
fi
curl --request POST \
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
--header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'Accept: application/vnd.github+json' \
--header 'X-GitHub-Api-Version: 2022-11-28' \
--data "{
\"context\": \"tests\",
\"state\": \"$commit_status_state\",
\"description\": \"$description\",
\"target_url\": \"https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}\"
}"