Skip to content

Commit

Permalink
Add github workflow to validate pull requests
Browse files Browse the repository at this point in the history
  • Loading branch information
l-peacock committed Feb 10, 2024
1 parent 5717649 commit 50eea04
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/runTests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Run all Jest tests in the project on Pull Request
# If any tests fail, or if there is insufficient code coverage, the pull request will be blocked.

# This yaml is based on the example provided here:
# https://joelhooks.com/jest-and-github-actions/

name: Run Tests

on: [pull_request]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install npm and run jest tests
uses: actions/setup-node@v1
with:
node-version: "12"
- run: npm install
- run: npm run test:unit:coverage:

- name: Tests Passed ✅
if: ${{ success() }}
run: |
curl --request POST \
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
--data '{
"context": "tests",
"state": "success",
"description": "Tests passed",
"target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}'
- name: Test Failure ⛔️
if: ${{ failure() }}
run: |
curl --request POST \
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
--data '{
"context": "tests",
"state": "failure",
"description": "Tests failed",
"target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}'
8 changes: 8 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ export default {
"!**/node_modules/**",
"!**/vendor/**",
],
coverageThreshold: {
global: {
branches: 70,
functions: 70,
lines: 70,
statements: 70,
},
},
};

0 comments on commit 50eea04

Please sign in to comment.