Skip to content

🧪 Test Workflow

🧪 Test Workflow #48

Workflow file for this run

name: Test Workflow
on:
pull_request:
types: [opened, reopened, synchronize] # default PR types
branches: [main, next]
paths: ["src/**/*", "package*.json"]
# 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:
permissions:
contents: read # to checkout the code
pull-requests: write # to add coverage reports to the PR
statuses: write # to update commit status
jobs:
run-tests:
name: Test
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 # only run if tests passed
if: needs.run-tests.outputs.success == 'true'
steps:
- uses: actions/download-artifact@v4
with: { name: test-coverage-reports, path: . }
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
update-pr-with-coverage-info:
name: Update PR with Coverage Reports
runs-on: ubuntu-latest
needs: run-tests # only run if tests passed and the event is a PR
if: needs.run-tests.outputs.success == 'true' && github.event_name == 'pull_request'
permissions:
pull-requests: write # to add coverage reports to the PR
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with: { name: test-coverage-reports, path: . }
- uses: davelosert/vitest-coverage-report-action@v2
update-github-commit-status:
name: Update GitHub Commit Status
runs-on: ubuntu-latest
needs: run-tests # always run 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 }}\"
}"