Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-sentry committed Feb 22, 2024
0 parents commit 8dd6f8b
Show file tree
Hide file tree
Showing 31 changed files with 39,617 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"env": {
"browser": true,
"commonjs": true,
"es2021": true
},
"extends": [
"google",
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"linebreak-style": 0
}
}
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2
updates:
- package-ecosystem: npm
directory: /
schedule:
interval: daily
open-pull-requests-limit: 10
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
open-pull-requests-limit: 10
51 changes: 51 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Workflow for Codecov Action
on: [pull_request]
jobs:
run:
permissions: read-all
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
steps:
- name: Checkout
uses: actions/[email protected]
- name: Install dependencies
run: npm install
- name: Lint
run: npm run lint
- name: Upload test results to Codecov (calculator)
uses: ./
with:
files: ./demo/calculator/junit.xml
flags: ${{ matrix.os }}
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload test results to Codecov (demo)
uses: ./
with:
files: ./demo/coverage-test/junit.xml
flags: ${{ matrix.os }}
verbose: true
token: ${{ secrets.CODECOV_TOKEN }}

- name: verify comment was made (not windows)
if: ${{ matrix.os != 'windows-latest' }}
run: |
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/joseph-sentry/test-results-action/issues/${{ github.event.pull_request.number }}/comments | \
jq -e '.[] | {user: .user.login, message: .body} | select((.user | contains("codecov[bot]")) and (.message | contains("Test Failures Detected")))'
- name: verify comment was made (windows)
if: ${{ matrix.os == 'windows-latest' }}
run: |
curl -L `
-H "Accept: application/vnd.github+json" `
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" `
-H "X-GitHub-Api-Version: 2022-11-28" `
https://api.github.com/repos/joseph-sentry/test-results-action/issues/${{ github.event.pull_request.number }}/comments | `
jq -e '.[] | {user: .user.login, message: .body} | select((.user | contains("codecov[bot]")) and (.message | contains("Test Failures Detected")))'
95 changes: 95 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# react / gatsby
public/

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# macOS Finder metadata
.DS_Store
13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Contribution Guide

:tada: Thanks for taking the time to contribute! :tada:

The following is a set of guidelines for contributing to this repository, which is hosted in the [Codecov Organization](https://github.com/codecov) on GitHub.

## What does this repo do?

This repo is a GitHub Action, meaning it integrates with the GitHub Actions CI/CD pipeline. It's meant to take formatted reports with code coverage stats and upload them to codecov.io. Our Node action uses the Actions toolkit to make system calls that allow us to run Codecov's bash uploader inside of Node. Essentially what we're doing in this action is downloading Codecov's bash uploader script from codecov.io/bash, saving it as a file in the current directory, executing the file via `exec` calls, then removing the script from the current directory.

## PRs, Issues, and Support

Feel free to clone, modify code and request a PR to this repository. All PRs and issues will be reviewed by the Codecov team. If your PR/issue has been sitting for a while or if you have any questions, ping us at [email protected]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019-2020 Codecov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
93 changes: 93 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: 'Codecov Test Result Action'
description: 'GitHub Action that uploads test result reports for your repository to codecov.io'
author: 'Codecov'
inputs:
token:
description: 'Repository Codecov token. Used to authorize report uploads'
required: false
codecov_yml_path:
description: 'Specify the path to the Codecov YML'
required: false
commit_parent:
description: 'Override to specify the parent commit SHA'
required: false
directory:
description: 'Directory to search for test result reports.'
required: false
disable_search:
description: 'Disable search for test result files. This is helpful when specifying what files you want to upload with the --file option.'
required: false
dry_run:
description: "Don't upload files to Codecov"
required: false
env_vars:
description: 'Environment variables to tag the upload with (e.g. PYTHON | OS,PYTHON)'
required: false
exclude:
description: 'Folders to exclude from search'
required: false
fail_ci_if_error:
description: 'Specify whether or not CI build should fail if Codecov runs into an error during upload'
required: false
file:
description: 'Path to test result file to upload'
required: false
files:
description: 'Comma-separated list of files to upload'
required: false
flags:
description: 'Flag upload to group test results (e.g. py3.10 | py3.11 | py3.12)'
required: false
handle_no_reports_found:
description: 'Raise no exceptions when no test result reports found'
required: false
name:
description: 'User defined upload name. Visible in Codecov UI'
required: false
os:
description: 'Override the assumed OS. Options are linux | macos | windows.'
required: false
override_branch:
description: 'Specify the branch name'
required: false
override_build:
description: 'Specify the build number'
required: false
override_build_url:
description: 'The URL of the build where this is running'
required: false
override_commit:
description: 'Specify the commit SHA'
required: false
override_pr:
description: 'Specify the pull request number'
required: false
report_code:
description: 'The code of the report. If unsure, do not include'
required: false
root_dir:
description: 'Used when not in git/hg project to identify project root directory'
required: false
slug:
description: 'Specify the slug manually (Enterprise use)'
required: false
url:
description: 'Specify the base url to upload (Enterprise use)'
required: false
verbose:
description: 'Specify whether the Codecov output should be verbose'
required: false
version:
description: 'Specify which version of the Codecov CLI should be used. Defaults to `latest`'
required: false
working-directory:
description: 'Directory in which to execute codecov.sh'
required: false

branding:
color: 'red'
icon: 'umbrella'

runs:
using: 'node20'
main: 'dist/index.js'
11 changes: 11 additions & 0 deletions demo/calculator/calculator.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Calculator from './calculator';

test('adds 2 + 3 to equal 5', () => {
const calc = new Calculator();
expect(calc.add(2, 3)).toBe(4);
});

test('subtracts 2 - 3 to equal -1', () => {
const calc = new Calculator();
expect(calc.subtract(2, 3)).toBe(1);
});
10 changes: 10 additions & 0 deletions demo/calculator/calculator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default class Calculator {

add(x : number, y : number) : number {
return x + y;
}

subtract(x: number, y: number) : number {
return x - y;
}
}
43 changes: 43 additions & 0 deletions demo/calculator/junit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="jest tests" tests="2" failures="2" errors="0" time="1.159">
<testsuite name="undefined" errors="0" failures="2" skipped="0" timestamp="2024-02-22T18:44:45" time="1.104" tests="2">
<testcase classname=" adds 2 + 3 to equal 5" name=" adds 2 + 3 to equal 5" time="0.002">
<failure>Error: expect(received).toBe(expected) // Object.is equality

Expected: 4
Received: 5
at Object.&lt;anonymous&gt; (/Users/josephsawaya/dev/test-result-action/demo/calculator/calculator.test.ts:5:26)
at Promise.then.completed (/Users/josephsawaya/dev/test-result-action/node_modules/jest-circus/build/utils.js:298:28)
at new Promise (&lt;anonymous&gt;)
at callAsyncCircusFn (/Users/josephsawaya/dev/test-result-action/node_modules/jest-circus/build/utils.js:231:10)
at _callCircusTest (/Users/josephsawaya/dev/test-result-action/node_modules/jest-circus/build/run.js:316:40)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at _runTest (/Users/josephsawaya/dev/test-result-action/node_modules/jest-circus/build/run.js:252:3)
at _runTestsForDescribeBlock (/Users/josephsawaya/dev/test-result-action/node_modules/jest-circus/build/run.js:126:9)
at run (/Users/josephsawaya/dev/test-result-action/node_modules/jest-circus/build/run.js:71:3)
at runAndTransformResultsToJestFormat (/Users/josephsawaya/dev/test-result-action/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21)
at jestAdapter (/Users/josephsawaya/dev/test-result-action/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19)
at runTestInternal (/Users/josephsawaya/dev/test-result-action/node_modules/jest-runner/build/runTest.js:367:16)
at runTest (/Users/josephsawaya/dev/test-result-action/node_modules/jest-runner/build/runTest.js:444:34)</failure>
</testcase>
<testcase classname=" subtracts 2 - 3 to equal -1" name=" subtracts 2 - 3 to equal -1" time="0">
<failure>Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: -1
at Object.&lt;anonymous&gt; (/Users/josephsawaya/dev/test-result-action/demo/calculator/calculator.test.ts:10:31)
at Promise.then.completed (/Users/josephsawaya/dev/test-result-action/node_modules/jest-circus/build/utils.js:298:28)
at new Promise (&lt;anonymous&gt;)
at callAsyncCircusFn (/Users/josephsawaya/dev/test-result-action/node_modules/jest-circus/build/utils.js:231:10)
at _callCircusTest (/Users/josephsawaya/dev/test-result-action/node_modules/jest-circus/build/run.js:316:40)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at _runTest (/Users/josephsawaya/dev/test-result-action/node_modules/jest-circus/build/run.js:252:3)
at _runTestsForDescribeBlock (/Users/josephsawaya/dev/test-result-action/node_modules/jest-circus/build/run.js:126:9)
at run (/Users/josephsawaya/dev/test-result-action/node_modules/jest-circus/build/run.js:71:3)
at runAndTransformResultsToJestFormat (/Users/josephsawaya/dev/test-result-action/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21)
at jestAdapter (/Users/josephsawaya/dev/test-result-action/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19)
at runTestInternal (/Users/josephsawaya/dev/test-result-action/node_modules/jest-runner/build/runTest.js:367:16)
at runTest (/Users/josephsawaya/dev/test-result-action/node_modules/jest-runner/build/runTest.js:444:34)</failure>
</testcase>
</testsuite>
</testsuites>
11 changes: 11 additions & 0 deletions demo/coverage-test/coverage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Coverage from './coverage';

test('test uncovered if', () => {
const coverageObj = new Coverage();
expect(coverageObj.uncovered_if()).toEqual(true);
});

test('fully covered', () => {
const coverageObj = new Coverage();
expect(coverageObj.fully_covered()).toEqual(false);
});
Loading

0 comments on commit 8dd6f8b

Please sign in to comment.