-
Notifications
You must be signed in to change notification settings - Fork 1
72 lines (59 loc) · 2.28 KB
/
ci.yml
File metadata and controls
72 lines (59 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
name: ci
# Run this workflow every time a new commit pushed to your repository
on: push
jobs:
# Set the job key. The key is displayed as the job name
# when a job name is not provided
run-unit-tests:
# Name the Job
name: Run unit tests
# Set the type of machine to run on
runs-on: ubuntu-latest
steps:
# Checks out a copy of your repository on the ubuntu-latest machine
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
- name: NPM install
run: npm install
- name: NPM run tests
run: npm run test
- name: Get code coverage
run: |
# Generate a temporary script for reading the code coverage
echo "
import json;
coverage = json.load(open('coverage/coverage-summary.json'))['total']['lines']['pct'];
print(coverage, end='');
" >> get_coverage.py
# Get the code coverage, set as Github env var
COVERAGE=$(python3 get_coverage.py)
echo "COVERAGE=$(echo ${COVERAGE})" >> $GITHUB_ENV
- name: Generate code coverage file name
run: |
# Create a temporary script for converting the refs name
echo "
import os, sys;
refs = sys.stdin.read();
# refs/heads/feature/added-command-handler --> feature-added-command-handler
branch_name = '-'.join(refs.split('/')[2:]);
print(branch_name, end='');
" >> get_branch_name.py
# Generate the branch name, assign to GITHUB_ENV
REF=${{ github.ref }}
echo "github.ref: $REF"
BRANCH_NAME=$(echo $REF | python3 get_branch_name.py)
echo "BRANCH_NAME=$(echo ${BRANCH_NAME})" >> $GITHUB_ENV
- name: Create code coverage badge
uses: schneegans/dynamic-badges-action@v1.0.0
with:
auth: ${{ secrets.GIST_SECRET }}
gistID: 1708995a4933a08f4838df0243926653
filename: cilly__${{ env.BRANCH_NAME }}.json
label: coverage
labelColor: "#24292E" # Dark grey
message: ${{ env.COVERAGE }}%
color: "#34D058" # Green
namedLogo: mocha
logoColor: "#959DA5" # Grey