From a3b2a9866566b7908e01e9ee7f2c753df22e43d2 Mon Sep 17 00:00:00 2001 From: Evan Sims Date: Wed, 3 Apr 2024 22:06:54 -0500 Subject: [PATCH] chore(ci): add code coverage support --- .codecov.yml | 4 ++++ .github/workflows/main.yaml | 33 ++++++++++++++++++++------------- .github/workflows/semgrep.yaml | 12 ++++++------ .openapi-generator/FILES | 1 + package.json | 2 +- tests/jest.config.js | 2 ++ 6 files changed, 34 insertions(+), 20 deletions(-) create mode 100644 .codecov.yml diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 0000000..0385c10 --- /dev/null +++ b/.codecov.yml @@ -0,0 +1,4 @@ +coverage: + precision: 2 + range: "60...80" + round: down diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index c7a17c1..d5b4686 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -18,7 +18,7 @@ jobs: node-version: [14.x, 16.x, 18.x, 20.x] steps: - - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: fetch-depth: 0 @@ -26,10 +26,10 @@ jobs: uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 with: node-version: ${{ matrix.node-version }} - registry-url: 'https://registry.npmjs.org' - scope: '@openfga' + registry-url: "https://registry.npmjs.org" + scope: "@openfga" always-auth: false - cache: 'npm' + cache: "npm" - name: Install dependencies run: npm ci @@ -41,15 +41,15 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: fetch-depth: 0 - name: Set up node uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 with: - node-version: '20' - cache: 'npm' + node-version: "20" + cache: "npm" - name: Install dependencies run: npm ci @@ -63,6 +63,13 @@ jobs: - name: Run tests run: npm test + - name: Upload coverage to Codecov + uses: codecov/codecov-action@c16abc29c95fcf9174b58eb7e1abf4c866893bc8 # v4.1.1 + continue-on-error: true + with: + token: ${{ secrets.CODECOV_TOKEN }} + slug: openfga/js-sdk + publish: runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/v') @@ -72,18 +79,18 @@ jobs: id-token: write steps: - - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: fetch-depth: 0 - name: Set up node uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 with: - node-version: '20' - registry-url: 'https://registry.npmjs.org' - scope: '@openfga' + node-version: "20" + registry-url: "https://registry.npmjs.org" + scope: "@openfga" always-auth: false - cache: 'npm' + cache: "npm" - name: Install dependencies run: npm ci @@ -101,7 +108,7 @@ jobs: contents: write steps: - - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: fetch-depth: 0 diff --git a/.github/workflows/semgrep.yaml b/.github/workflows/semgrep.yaml index 5626ba6..78ab43f 100644 --- a/.github/workflows/semgrep.yaml +++ b/.github/workflows/semgrep.yaml @@ -11,9 +11,9 @@ jobs: image: returntocorp/semgrep if: (github.actor != 'dependabot[bot]' && github.actor != 'snyk-bot') steps: - - uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2 - with: - fetch-depth: 0 - - run: semgrep ci --no-suppress-errors - env: - SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }} + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + fetch-depth: 0 + - run: semgrep ci --no-suppress-errors + env: + SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }} diff --git a/.openapi-generator/FILES b/.openapi-generator/FILES index 3c77657..3bdd2bf 100644 --- a/.openapi-generator/FILES +++ b/.openapi-generator/FILES @@ -1,3 +1,4 @@ +.codecov.yml .eslintignore .eslintrc.js .fossa.yml diff --git a/package.json b/package.json index 5763601..01d61a1 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "scripts": { "build": "tsc --outDir dist/", "prepublishOnly": "rm -rf dist/ && npm run build", - "test": "jest --config ./tests/jest.config.js", + "test": "jest --coverage --config ./tests/jest.config.js", "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix" }, diff --git a/tests/jest.config.js b/tests/jest.config.js index a587f88..5559dc0 100644 --- a/tests/jest.config.js +++ b/tests/jest.config.js @@ -1,4 +1,6 @@ module.exports = { + collectCoverage: true, + coverageReporters: ['text', 'cobertura'], testEnvironment: "node", preset: "ts-jest", coveragePathIgnorePatterns: ["/node_modules/", "/tests/"],