Skip to content

refactor: Update CardHeader component to support optional top border,… #14

refactor: Update CardHeader component to support optional top border,…

refactor: Update CardHeader component to support optional top border,… #14

Workflow file for this run

name: Unit Tests and Linting
on:
push:
pull_request:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x]
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: npm ci
- name: Run ESLint
run: |
if [[ ${{ github.event_name }} == 'pull_request' ]]; then
npm run lint:ci
else
npm run lint
fi
continue-on-error: ${{ github.event_name == 'pull_request' }}
- name: Comment ESLint warnings/errors on PR
if: ${{ github.event_name == 'pull_request' }}
uses: actions/github-script@v5
with:
script: |
const fs = require('fs');
const eslintOutput = fs.readFileSync('eslint-output.txt', 'utf8');
if (eslintOutput) {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "ESLint warnings/errors:\n```\n" + eslintOutput + "\n```"
});
}
- name: Run Unit Tests
run: |
if [[ ${{ github.event_name }} == 'pull_request' ]]; then
npm run test:ci
else
npm run test
fi
continue-on-error: ${{ github.event_name == 'pull_request' }}
- name: Comment failed unit tests on PR
if: ${{ github.event_name == 'pull_request' }}
uses: actions/github-script@v5
with:
script: |
const fs = require('fs');
const testOutput = fs.readFileSync('jest-output.txt', 'utf8');
const jestOutputObj = JSON.parse(fs.readFileSync('jest-output.json', 'utf8'));
if (jestOutputObj.numFailedTests > 0) {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "Failed unit tests:\n```\n" + testOutput + "\n```"
});
}
- name: Fail workflow if there are ESLint errors or failed unit tests
if: ${{ github.event_name == 'pull_request' }}
uses: actions/github-script@v5
with:
script: |
const fs = require('fs');
const eslintOutput = fs.readFileSync('eslint-output.txt', 'utf8');
const jestOutput = JSON.parse(fs.readFileSync('jest-output.json', 'utf8'));
const eslintErrorRegex = /[1-9]\d* errors?/;
if (eslintErrorRegex.test(eslintOutput) || jestOutput.numFailedTests > 0) {
core.setFailed('ESLint errors or failed unit tests detected');
}
- name: Run Build
run: npm run build