Skip to content

Commit

Permalink
Add unit tests and refactor stages (#50)
Browse files Browse the repository at this point in the history
* Add unit tests and refactor stages

* Fix aws cp cmd

* Fixes

- remove test stage
- add regex for CODEBUILD_SRC_DIR
- add pre_build to sonar stage

* fix order of artifact download

* update reports dir

* fix regex

* Fix coverage format
  • Loading branch information
velomatt authored Aug 28, 2023
1 parent a6a6817 commit b3402f1
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 37 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/dss-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ on:
- synchronize

jobs:
dss-sdk:
build:
strategy:
matrix:
component:
- dss-sdk-build
- dss-sdk-unit-test
uses: OpenMPDK/DSS/.github/workflows/build-aws.yml@master
with:
component: dss-sdk
component: ${{ matrix.component }}
project-name: OpenMPDK_dss-sdk
compute-type-override: BUILD_GENERAL1_LARGE
secrets: inherit
Expand All @@ -33,3 +38,10 @@ jobs:
component: ${{ matrix.component }}
project-name: OpenMPDK_dss-sdk
secrets: inherit
scan:
uses: OpenMPDK/DSS/.github/workflows/build-aws.yml@master
with:
component: sonar-scanner
project-name: OpenMPDK_dss-sdk
secrets: inherit
needs: [build]
27 changes: 27 additions & 0 deletions buildspec/dss-sdk-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: 0.2

env:
secrets-manager:
DSSS3URI: Codebuild-DSS:DSSS3URI
variables:
DSSGLOBLIST: "nkv-sdk-*.tgz nkv-target-*.tgz"

phases:
build:
commands:
# Build dss-sdk with Sonar build-wrapper for C/C++ static analysis
- build-wrapper-linux-x86-64 --out-dir bw-output ./scripts/build_all.sh kdd-samsung-remote
post_build:
commands:
# Copy artifacts to branch dir if this is a merge
- /stagemergeartifacts.sh
# Copy df_out, host_out, and bw-output for later sonar-scanner stage
- aws s3 cp --recursive bw-output "$DSSS3URI/cache/dss-sdk/$GITHUB_RUN_NUMBER/sonar/bw-output" --only-show-errors
- aws s3 cp --recursive df_out "$DSSS3URI/cache/dss-sdk/$GITHUB_RUN_NUMBER/build/df_out" --only-show-errors
- aws s3 cp --recursive host_out "$DSSS3URI/cache/dss-sdk/$GITHUB_RUN_NUMBER/build/host_out" --only-show-errors
artifacts:
files:
- df_out/nkv-target-*.tgz
- host_out/nkv-sdk-bin-*.tgz
discard-paths: yes
name: builds/dss-sdk/$GITHUB_RUN_NUMBER
15 changes: 15 additions & 0 deletions buildspec/dss-sdk-unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: 0.2

env:
secrets-manager:
DSSS3URI: Codebuild-DSS:DSSS3URI

phases:
build:
commands:
# Build dss-sdk target with unit tests
- ./target/build.sh --run-tests --with-coverage
post_build:
commands:
# Copy df_out for later sonar-scanner stage
- aws s3 cp --recursive df_out "$DSSS3URI/cache/dss-sdk/$GITHUB_RUN_NUMBER/unit/df_out" --only-show-errors
35 changes: 0 additions & 35 deletions buildspec/dss-sdk.yml

This file was deleted.

36 changes: 36 additions & 0 deletions buildspec/sonar-scanner.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: 0.2

env:
secrets-manager:
SONAR_TOKEN: Codebuild-DSS:SONAR_TOKEN
DSSS3URI: Codebuild-DSS:DSSS3URI
variables:
SONAR_UNIT_TEST_REPORT: df_out/reports/sonar_qube_ut_coverage_report.xml

phases:
pre_build:
commands:
# Download build wrapper output from build job
- aws s3 cp --recursive "$DSSS3URI/cache/dss-sdk/$GITHUB_RUN_NUMBER/sonar" . --only-show-errors
# Download df_out and host_out
- aws s3 cp --recursive "$DSSS3URI/cache/dss-sdk/$GITHUB_RUN_NUMBER/build" . --only-show-errors
# Download unit test coverage report(s)
- aws s3 cp --recursive "$DSSS3URI/cache/dss-sdk/$GITHUB_RUN_NUMBER/unit/df_out/reports/" df_out/reports/ --only-show-errors
# Correct paths of target files in coverage report
- sed -i -r 's/path="/path="target\//g' $SONAR_UNIT_TEST_REPORT
# replace the old CODEBUILD_SRC_DIR with the current one in bw-output
- sed -i -r "s|/codebuild/output/src[^/]+/src/github.com/OpenMPDK/dss-sdk|$CODEBUILD_SRC_DIR|g" bw-output/build-wrapper-dump.json
build:
commands:
# Run sonar-scanner and ingest coverage report(s)
- |
sonar-scanner \
-Dsonar.branch.name="$([[ "$GITHUB_REF_NAME" != *"/merge" ]] && echo "$GITHUB_REF_NAME")" \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.pullrequest.github.summary_comment=true \
-Dsonar.pullrequest.provider=GitHub \
-Dsonar.pullrequest.github.repository=OpenMPDK/dss-sdk \
-Dsonar.pullrequest.key=$(echo $GITHUB_REF | grep -oP "^refs/pull/\K[^/]+") \
-Dsonar.pullrequest.base=$GITHUB_BASE_REF \
-Dsonar.pullrequest.branch=$GITHUB_HEAD_REF \
-Dsonar.coverageReportPaths=$SONAR_UNIT_TEST_REPORT

0 comments on commit b3402f1

Please sign in to comment.