From b59c37ef5e4085bea9942b3f958ccc8879459aeb Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 15 Aug 2021 12:05:15 +0800 Subject: [PATCH] Actions: Add CI for utest and coverage --- .github/workflows/release.yml | 2 +- .github/workflows/test.yml | 40 ++++++++++++++++++++++++++++++ README.md | 2 +- trunk/Dockerfile | 4 +-- trunk/Dockerfile.cov | 9 +++++++ trunk/Dockerfile.test | 9 +++++++ trunk/auto/coverage.sh | 46 +++++++++++++++++++---------------- 7 files changed, 87 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 trunk/Dockerfile.cov create mode 100644 trunk/Dockerfile.test diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 00418403a4c..e3be44e94be 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,7 +7,7 @@ on: jobs: k8s: - name: release-k8s + name: actions-release-k8s runs-on: ubuntu-20.04 steps: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000000..e9f76fe88fd --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,40 @@ +name: "Test" + +on: [push, pull_request] + +jobs: + utest: + name: actions-test-utest + runs-on: ubuntu-20.04 + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + ################################################################ + # Tests + - name: Build test image + run: docker build --tag srs:test -f trunk/Dockerfile.test trunk + # For utest + - name: Run SRS utest + run: docker run --rm srs:test bash -c 'make && ./objs/srs_utest' + coverage: + name: actions-test-coverage + runs-on: ubuntu-20.04 + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + ################################################################ + # Tests + - name: Build coverage image + run: docker build --tag srs:cov -f trunk/Dockerfile.cov trunk + # For coverage + - name: Run SRS covergae + if: ${{ startsWith(github.ref, 'refs/heads/') }} + run: | + SRS_BRANCH=$(echo ${{ github.ref }}| awk -F '/' '{print $3}') && SRS_SHA=${{ github.sha }} && SRS_PROJECT=/srs + echo "For ref=${{ github.ref }}, sha=${{ github.sha }}, SRS_BRANCH=$SRS_BRANCH, SRS_SHA=$SRS_SHA, SRS_PROJECT=$SRS_PROJECT" + docker run --rm --env SRS_BRANCH=$SRS_BRANCH --env SRS_SHA=$SRS_SHA --env SRS_PROJECT=$SRS_PROJECT \ + srs:cov bash -c 'make && ./objs/srs_utest && bash auto/coverage.sh' \ No newline at end of file diff --git a/README.md b/README.md index 7d9ec939f63..8aac68cb707 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # SRS(Simple Realtime Server) ![](http://ossrs.net/gif/v1/sls.gif?site=github.com&path=/srs/srs3) -[![](https://circleci.com/gh/ossrs/srs/tree/3.0release.svg?style=svg&circle-token=1ef1d5b5b0cde6c8c282ed856a18199f9e8f85a9)](https://circleci.com/gh/ossrs/srs/tree/3.0release) +[![](https://github.com/ossrs/srs/actions/workflows/test.yml/badge.svg?branch=3.0release)](https://github.com/ossrs/srs/actions?query=workflow%3ATest+branch%3A3.0release) [![](https://codecov.io/gh/ossrs/srs/branch/3.0release/graph/badge.svg)](https://codecov.io/gh/ossrs/srs/branch/3.0release) [![](https://cloud.githubusercontent.com/assets/2777660/22814959/c51cbe72-ef92-11e6-81cc-32b657b285d5.png)](https://github.com/ossrs/srs/wiki/v1_CN_Contact#wechat) diff --git a/trunk/Dockerfile b/trunk/Dockerfile index 34b6b0589b4..7fcb72aab03 100644 --- a/trunk/Dockerfile +++ b/trunk/Dockerfile @@ -4,8 +4,8 @@ FROM ossrs/srs:dev AS build RUN yum install -y gcc make gcc-c++ patch unzip perl git # Build and install SRS. -COPY . /trunk -WORKDIR /trunk +COPY . /srs/trunk +WORKDIR /srs/trunk RUN ./configure --jobs=2 && make -j2 && make install # All config files for SRS. diff --git a/trunk/Dockerfile.cov b/trunk/Dockerfile.cov new file mode 100644 index 00000000000..bc82642a7ab --- /dev/null +++ b/trunk/Dockerfile.cov @@ -0,0 +1,9 @@ +FROM ossrs/srs:dev + +# Install depends tools. +RUN yum install -y gcc make gcc-c++ patch unzip perl git + +# Build and install SRS. +COPY . /srs/trunk +WORKDIR /srs/trunk +RUN ./configure --with-utest --gcov --jobs=2 && make -j2 diff --git a/trunk/Dockerfile.test b/trunk/Dockerfile.test new file mode 100644 index 00000000000..ca41c207265 --- /dev/null +++ b/trunk/Dockerfile.test @@ -0,0 +1,9 @@ +FROM ossrs/srs:dev + +# Install depends tools. +RUN yum install -y gcc make gcc-c++ patch unzip perl git + +# Build and install SRS. +COPY . /srs/trunk +WORKDIR /srs/trunk +RUN ./configure --with-utest --jobs=2 && make -j2 diff --git a/trunk/auto/coverage.sh b/trunk/auto/coverage.sh index 55cb7ce46f2..7a2d2d3467d 100644 --- a/trunk/auto/coverage.sh +++ b/trunk/auto/coverage.sh @@ -1,36 +1,39 @@ #!/bin/bash # In .circleci/config.yml, generate *.gcno with -# ./configure --gcov --without-research --without-librtmp && make +# ./configure --gcov --with-utest --without-research --without-librtmp && make # and generate *.gcda by # ./objs/srs_utest # Workdir is objs/cover. workdir=`pwd`/objs/cover -# Tool git is required to map the right path. -git --version >/dev/null 2>&1 -ret=$?; if [[ $ret -ne 0 ]]; then echo "Tool git is required, ret=$ret"; exit $ret; fi - # Create trunk under workdir. mkdir -p $workdir && cd $workdir ret=$?; if [[ $ret -ne 0 ]]; then echo "Enter workdir failed, ret=$ret"; exit $ret; fi -# Collect all *.gcno and *.gcda to objs/cover. -cd $workdir && (rm -rf src && cp -R ../../src . && cp -R ../src/* src/) -ret=$?; if [[ $ret -ne 0 ]]; then echo "Collect *.gcno and *.gcda failed, ret=$ret"; exit $ret; fi - -# Generate *.gcov for coverage. -cd $workdir && -for file in `find src -name "*.cpp"|grep -v utest`; do - gcov $file -o `dirname $file` - ret=$?; if [[ $ret -ne 0 ]]; then echo "Collect $file failed, ret=$ret"; exit $ret; fi -done - -# Cook the gcov files. -cd $workdir && -find . -name "*.gcov"|grep -v srs|xargs rm -f -ret=$?; if [[ $ret -ne 0 ]]; then echo "Cook gcov files failed, ret=$ret"; exit $ret; fi +CODECOV_ARGS="" +if [[ $SRS_BRANCH != '' ]]; then + # -B branch Specify the branch name + CODECOV_ARGS="$CODECOV_ARGS -B $SRS_BRANCH" +fi +if [[ $SRS_SHA != '' ]]; then + # -C sha Specify the commit sha + CODECOV_ARGS="$CODECOV_ARGS -C $SRS_SHA" +fi +if [[ $SRS_PREFIX != '' ]]; then + # -k prefix Prefix filepaths to help resolve path fixing + CODECOV_ARGS="$CODECOV_ARGS -k $SRS_PREFIX" +fi +if [[ $SRS_PROJECT != '' ]]; then + # -R root dir Used when not in git/hg project to identify project root directory + # -p dir Project root directory. Also used when preparing gcov + CODECOV_ARGS="$CODECOV_ARGS -R $SRS_PROJECT -p $SRS_PROJECT" +fi +if [[ $SRS_SEARCH != '' ]]; then + # -s DIR Directory to search for coverage reports. + CODECOV_ARGS="$CODECOV_ARGS -s $SRS_SEARCH" +fi # Upload report with *.gcov # Remark: The file codecov.yml is not neccessary. It literally depends on git. @@ -41,5 +44,6 @@ ret=$?; if [[ $ret -ne 0 ]]; then echo "Cook gcov files failed, ret=$ret"; exit # https://circleci.com/gh/ossrs/srs/tree/3.0release cd $workdir && export CODECOV_TOKEN="493bba46-c468-4e73-8b45-8cdd8ff62d96" && -bash <(curl -s https://codecov.io/bash) && +bash <(curl -s https://codecov.io/bash) $CODECOV_ARGS && echo "Done" && exit 0 +