Skip to content

Commit

Permalink
Adding pull request CI (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
code-ape authored May 7, 2022
1 parent e843854 commit 2090e61
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
63 changes: 63 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: PR CI

on:
pull_request:
branches: ['**']

jobs:
node_ci:
name: Node.js CI
runs-on: ${{ matrix.os }}
timeout-minutes: 5
defaults:
run:
shell: bash

strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node_version: ['12.22.12', '14.19.2', '16.15.0']

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v3
with:
node-version: '${{ matrix.node_version }}'
cache: 'npm'
- run: npm ci
- run: npm run build
- run: npm pack

deno_ci:
name: Deno CI
runs-on: ${{ matrix.os }}
timeout-minutes: 5
defaults:
run: { shell: bash }

strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
deno_version: ['v1.17.0', 'v1.21.1', 'vx.x.x']

steps:
- uses: actions/checkout@v2
- name: Use Deno ${{ matrix.deno_version }}
uses: denoland/setup-deno@v1
with:
deno-version: '${{ matrix.deno_version }}'
- run: deno fmt --check
if: matrix.deno_version == 'vx.x.x'
- run: deno lint
if: matrix.deno_version == 'vx.x.x'
- run: deno test --allow-all
- name: deno coverage cov_profile/
if: matrix.deno_version == 'vx.x.x'
run: |
rm -rf cov_profile/ || true
deno test --allow-all --coverage=cov_profile/ > /dev/null 2>%1
deno coverage cov_profile/
- name: Check coverage 100%
if: matrix.deno_version == 'vx.x.x'
run: ./scripts/check-coverage 100
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# result.js

Typescript implementation of Rust's Result
Zero dependency Typescript implementation of Rust's Result.

## Supported Environments

| Environment | Versions |
| ----------- | ------------------------------------ |
| Deno | `v1.17.0` and `v1.21.1` |
| Node.js | `12.22.12`, `14.19.2`, and `16.15.0` |
51 changes: 51 additions & 0 deletions scripts/check-coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash

set -e

repo_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." >/dev/null 2>&1 && pwd )"

help_text="
check-coverage
This script check test coverage output in cov_profile/ directory.
Usage: build_nexe MININUM_PERCENT
"

case "$1" in
"help"|"--help"|"-h"|"")
echo "$help_text"
exit 0
;;
*)
integer_regex='^[0-9]+$'
if ! [[ $1 =~ $integer_regex ]] ; then
echo "error: Input is not an integer: $1"
exit 1
fi
if ! [[ -d "$repo_dir/cov_profile/" ]]; then
echo "Code coverage directory not found. Run: deno test --allow-all --coverage=cov_profile/"
exit 1
fi
echo "Running deno coverage report ..."
coverage_report="$(deno coverage cov_profile | sed $'s,\x1b\\[[0-9;]*[a-zA-Z],,g')"
coverage_stats="$(echo "$coverage_report" | grep -E '^cover \S+ \.\.\.')"
failed_files=""
echo -e "Checking all files in deno coverage report meet minimum ...\n"
while IFS= read -r coverage_stat; do
coverage_number="$(echo "$coverage_stat" | rev | cut -d ' ' -f 2 | rev | sed 's|%||g')"
if (( $(echo "$coverage_number < $1" | bc -l) )); then
failed_files="$failed_files$coverage_stat\n"
fi
done <<< "$coverage_stats"
if [[ "$failed_files" == "" ]]; then
echo "PASSED"
exit 0
else
echo "FAILED"
echo -e "$failed_files"
exit 1
fi
;;
esac

0 comments on commit 2090e61

Please sign in to comment.