-
Notifications
You must be signed in to change notification settings - Fork 53
92 lines (90 loc) · 3.32 KB
/
unit_test.yml
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: CI unit testing
on:
workflow_call:
secrets:
GHCR_USERNAME:
required: true
GHCR_TOKEN:
required: true
CODECOV_TOKEN:
required: true
jobs:
run_unit_tests:
runs-on: ubuntu-latest
steps:
-
name: Log in to the Container registry
uses: docker/login-action@master
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GHCR_TOKEN }}
-
name: Repo checkout
uses: actions/checkout@master
-
name: Set up environment
run: |
if [ ${{ github.base_ref }} == 'main' ]; then
branch=''
else
branch=`echo "-""${{ github.base_ref }}" | awk '{print tolower($0)}'`
fi
narrative_version=`grep '\"version\":' src/config.json.templ | awk '{print $2}' | sed 's/"//g'`
narrative_git_hash=`grep '\"git_commit_hash\":' src/config.json.templ | awk '{print $2}' | sed 's/"//g' | sed 's/,//'`
echo "APP_IMAGE_TAG=ghcr.io/${{ github.repository }}${branch}:pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
echo "APP_VERSION_IMAGE_TAG=ghcr.io/${{ github.repository }}${branch}_version:pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
echo "BRANCH=${branch}" >> $GITHUB_ENV
echo "BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_ENV
echo "NARRATIVE_GIT_HASH=${narrative_git_hash}" >> $GITHUB_ENV
echo "NARRATIVE_VERSION=${narrative_version}" >> $GITHUB_ENV
echo "PR=pr-${{ github.event.pull_request.number }}" >> $GITHUB_ENV
echo "VCS_REF=$(echo "${{ github.event.pull_request.head.sha }}" | cut -c -7)" >> $GITHUB_ENV
-
name: Pull docker image
shell: bash -l {0}
run: docker pull ${{ env.APP_IMAGE_TAG }}
-
name: Run backend tests
id: test_backend
shell: bash -l {0}
run: |
mkdir -p ${{ github.workspace }}/output
sudo chown nobody ${{ github.workspace }}/output
sudo chmod -R 0777 ${{ github.workspace }}/output
docker run -v "${{ github.workspace }}/output:/tmp/output" --user nobody ${{ env.APP_IMAGE_TAG }} /bin/bash scripts/run_backend_tests.sh
continue-on-error: true
-
name: Use Node JS 20
uses: actions/setup-node@main
with:
node-version: 20
-
name: Install JS dependencies
run: |
npm ci
npm run install-npm
cp src/config.json kbase-extension/static/kbase/config/
-
name: Run Narrative Frontend Unit Tests
id: test_frontend
shell: bash -l {0}
run: bash scripts/run_tests.sh -u -c ${{ env.APP_IMAGE_TAG }}
continue-on-error: true
-
name: Send to Codecov
id: send_to_codecov
uses: codecov/codecov-action@main
continue-on-error: true
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./output/coverage.xml,./js-coverage/lcov/lcov.info
fail_ci_if_error: true
-
name: outcome
if: steps.test_backend.outcome != 'success' || steps.test_frontend.outcome != 'success' || steps.send_to_codecov.outcome != 'success'
run: |
echo "backend tests: ${{ steps.test_backend.outcome }}"
echo "frontend tests: ${{ steps.test_frontend.outcome }}"
echo "upload coverage: ${{ steps.send_to_codecov.outcome }}"
exit 1