Skip to content

Commit 8045ba2

Browse files
31chtumaisch
authored andcommitted
GitHub actions: add build/test
1 parent 0843b3b commit 8045ba2

16 files changed

+273
-168
lines changed

.github/workflows/docker-build-publish.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ on:
1111
- main
1212
paths:
1313
- ".devcontainer/Dockerfile"
14+
workflow_dispatch:
1415

1516
jobs:
1617
build-and-publish:
1718
runs-on: ubuntu-latest
1819

1920
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
2024
- name: Set up QEMU
2125
uses: docker/setup-qemu-action@v3
2226

@@ -33,6 +37,7 @@ jobs:
3337
- name: Build and push Docker image
3438
uses: docker/build-push-action@v6
3539
with:
36-
context: "{{defaultContext}}:.devcontainer"
40+
context: .
41+
file: .devcontainer/Dockerfile
3742
push: true
38-
tags: ghcr.io/${{ github.repository_owner }}/project-cplusplus:latest
43+
tags: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Build and test the project
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- ".devcontainer/Dockerfile"
9+
pull_request:
10+
branches:
11+
- main
12+
paths-ignore:
13+
- ".devcontainer/Dockerfile"
14+
workflow_dispatch:
15+
16+
# IMPORTANT: make sure to use the 'runner user'when running jobs in a container!
17+
# Otherwise there will be 'dubious ownership' issues reported by Git.
18+
# Therefore, make sure to use the '--user 1001' option for the container.
19+
jobs:
20+
build-doc:
21+
runs-on: ubuntu-latest
22+
container:
23+
image: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
24+
options: --user 1001
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v4
28+
- name: Build documentation
29+
run: ./tools/build-docs.sh
30+
- name: Upload documentation
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: documentation
34+
path: "build/html"
35+
retention-days: 1
36+
37+
build-app:
38+
runs-on: ubuntu-latest
39+
container:
40+
image: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
41+
options: --user 1001
42+
strategy:
43+
matrix:
44+
compiler: [gcc, clang]
45+
steps:
46+
- name: Checkout code
47+
uses: actions/checkout@v4
48+
with:
49+
submodules: "true"
50+
- name: Run clang-format
51+
run: ./tools/clang-format.sh
52+
- name: Build application
53+
run: |
54+
export ENABLE_IWYU=1
55+
export ENABLE_LWYU=1
56+
export ENABLE_CLANG_TIDY=1
57+
export ENABLE_CPPCHECK=1
58+
./tools/build-cmake-target.sh ${{ matrix.compiler }}-release cplusplus_training_project
59+
- name: Upload application
60+
uses: actions/upload-artifact@v4
61+
with:
62+
name: application-${{ matrix.compiler }}
63+
path: "build/${{ matrix.compiler }}-release/bin/cplusplus_training_project"
64+
retention-days: 1
65+
66+
test-app:
67+
runs-on: ubuntu-latest
68+
container:
69+
image: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
70+
options: --user 1001
71+
strategy:
72+
matrix:
73+
compiler: [gcc, clang]
74+
steps:
75+
- name: Checkout code
76+
uses: actions/checkout@v4
77+
with:
78+
submodules: "true"
79+
- name: Build tests
80+
run: ./tools/build-cmake-target.sh ${{ matrix.compiler }}-coverage calculate_test
81+
- name: Run tests
82+
run: ./tools/run-test.sh build/${{ matrix.compiler }}-coverage/bin/calculate_test build/${{ matrix.compiler }}
83+
- name: Upload test results
84+
uses: actions/upload-artifact@v4
85+
with:
86+
name: test-results-${{ matrix.compiler }}
87+
path: "build/${{ matrix.compiler }}/*.xml"
88+
retention-days: 1

.gitlab-ci.yml

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ default:
55
stages:
66
- build
77
- test
8+
- deploy
89

910
include:
1011
- template: Jobs/Code-Quality.gitlab-ci.yml
12+
- component: $CI_SERVER_FQDN/devminds-ch/gitlab-component-clang-format/gitlab-component-clang-format@main
1113

1214
build-project:
1315
stage: build
1416
before_script:
1517
- git submodule update --init --recursive
1618
script:
17-
- ./tools/build-project.sh
19+
- ./tools/build-cmake-target.sh gcc-release cplusplus_training_project
1820
artifacts:
1921
paths:
2022
- build/bin
@@ -25,7 +27,7 @@ build-unit-tests:
2527
before_script:
2628
- git submodule update --init --recursive
2729
script:
28-
- ./tools/build-unit-tests.sh
30+
- ./tools/build-cmake-target.sh gcc-coverage calculate_test
2931
artifacts:
3032
paths:
3133
- build/
@@ -37,10 +39,10 @@ build-documentation:
3739
- git submodule update --init --recursive
3840
- apt update && apt install -y doxygen
3941
script:
40-
- ./tools/build-documentation.sh
42+
- ./tools/build-docs.sh
4143
artifacts:
4244
paths:
43-
- build/doc
45+
- build/html/
4446
expire_in: 1 week
4547

4648
code_quality:
@@ -51,15 +53,23 @@ run-unit-tests:
5153
before_script:
5254
- apt update && apt install -y gcovr
5355
script:
54-
- ./build/gcc-coverage/bin/calculate_test --gtest_output="xml:test-report-gcc.xml"
55-
- gcovr -f src . --root ./ --exclude-unreachable-branches --xml-pretty --print-summary -o "coverage-gcc.xml"
56-
- mkdir -p build/gcov-html-gcc
57-
- gcovr -f src . --root ./ --exclude-unreachable-branches --html --html-details -o "build/gcov-html-gcc/index.html"
56+
- ./tools/run-test.sh build/gcc-coverage/bin/calculate_test build/gcc
5857
coverage: /^\s*lines:\s*\d+.\d+\%/
5958
artifacts:
6059
expire_in: 1 week
6160
reports:
62-
junit: test-report-gcc.xml
61+
junit: build/gcc/test-report.xml
6362
coverage_report:
6463
coverage_format: cobertura
65-
path: coverage-gcc.xml
64+
path: build/gcc/test-coverage.xml
65+
66+
pages:
67+
stage: deploy
68+
script:
69+
- mv build/html/ public/
70+
environment:
71+
name: "Pages production"
72+
url: "${CI_PAGES_URL}"
73+
artifacts:
74+
paths:
75+
- public/

CMakeLists.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,27 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
1212

1313
# Enable include-what-you-use (IWYU) if available
1414
find_program(IWYU_PATH NAMES include-what-you-use)
15-
if (IWYU_PATH)
15+
if (IWYU_PATH AND DEFINED ENV{ENABLE_IWYU})
1616
message(STATUS "Enabling: include-what-you-use")
1717
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "${IWYU_PATH}")
1818
endif()
1919

20-
# Enable link-what-you-use (LWYU)
21-
message(STATUS "Enabling: link-what-you-use")
22-
set(CMAKE_LINK_WHAT_YOU_USE TRUE)
20+
if(DEFINED ENV{ENABLE_LWYU})
21+
# Enable link-what-you-use (LWYU)
22+
message(STATUS "Enabling: link-what-you-use")
23+
set(CMAKE_LINK_WHAT_YOU_USE TRUE)
24+
endif()
2325

2426
# Enable cppcheck if available
2527
find_program(CPPCHECK_PATH NAMES cppcheck)
26-
if (CPPCHECK_PATH)
28+
if (CPPCHECK_PATH AND DEFINED ENV{ENABLE_CPPCHECK})
2729
message(STATUS "Enabling: cppcheck")
2830
set(CMAKE_CXX_CPPCHECK "${CPPCHECK_PATH}")
2931
endif()
3032

3133
# Enable clang-tidy if available
3234
find_program(CLANG_TIDY_PATH NAMES clang-tidy)
33-
if (CLANG_TIDY_PATH)
35+
if (CLANG_TIDY_PATH AND DEFINED ENV{ENABLE_CLANG_TIDY})
3436
message(STATUS "Enabling: clang-tidy")
3537
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_PATH}")
3638
endif()

Jenkinsfile

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ pipeline {
4141
}
4242
stage('Build documentation') {
4343
steps {
44-
sh 'mkdir -p build/docs && cd docs && doxygen'
44+
sh './tools/build-docs.sh'
4545
archiveArtifacts(
46-
artifacts: 'build/docs/html/**',
46+
artifacts: 'build/html/**',
4747
onlyIfSuccessful: true
4848
)
4949
publishHTML([
5050
allowMissing: false,
5151
alwaysLinkToLastBuild: false,
5252
keepAll: false,
53-
reportDir: 'build/docs/html/',
53+
reportDir: 'build/html/',
5454
reportFiles: 'index.html',
5555
reportName: 'Documentation',
5656
reportTitles: '',
@@ -89,8 +89,7 @@ pipeline {
8989
stages {
9090
stage('Build project') {
9191
steps {
92-
sh "cmake --preset ${COMPILER}-release"
93-
sh "cmake --build --preset ${COMPILER}-release --target cplusplus_training_project"
92+
sh "./tools/build-cmake-target.sh ${COMPILER}-release cplusplus_training_project"
9493
archiveArtifacts(
9594
artifacts: "build/${COMPILER}-release/bin/cplusplus_training_project",
9695
onlyIfSuccessful: true
@@ -112,8 +111,7 @@ pipeline {
112111
}
113112
stage('Build tests') {
114113
steps {
115-
sh "cmake --preset ${COMPILER}-coverage"
116-
sh "cmake --build --preset ${COMPILER}-coverage --target calculate_test"
114+
sh "./tools/build-cmake-target.sh ${COMPILER}-coverage calculate_test"
117115
archiveArtifacts(
118116
artifacts: "build/${COMPILER}-coverage/bin/calculate_test",
119117
onlyIfSuccessful: true
@@ -133,28 +131,23 @@ pipeline {
133131
parallel {
134132
stage('Run tests [gcc]') {
135133
steps {
136-
sh './build/gcc-coverage/bin/calculate_test --gtest_output="xml:test-report-gcc.xml"'
134+
sh './tools/run-test.sh build/gcc-coverage/bin/calculate_test build/gcc'
137135
junit(
138-
testResults: 'test-report-gcc.xml'
136+
testResults: 'build/gcc/test-report.xml'
139137
)
140-
// Create Cobertura coverage report
141-
sh 'gcovr -f src . --root ./ --exclude-unreachable-branches --xml-pretty --print-summary -o "coverage-gcc.xml"'
142138
recordCoverage(
143139
name: 'GCC Coverage',
144140
id: 'gcc-coverage',
145141
tools: [
146-
[parser: 'JUNIT', pattern: 'report-gcc.xml'],
147-
[parser: 'COBERTURA', pattern: 'coverage-gcc.xml']
142+
[parser: 'JUNIT', pattern: 'build/gcc/test-report.xml'],
143+
[parser: 'COBERTURA', pattern: 'build/gcc/test-coverage.xml']
148144
]
149145
)
150-
// Create HTML coverage report
151-
sh 'mkdir -p build/gcov-html-gcc'
152-
sh 'gcovr -f src . --root ./ --exclude-unreachable-branches --html --html-details -o "build/gcov-html-gcc/index.html"'
153146
publishHTML([
154147
allowMissing: false,
155148
alwaysLinkToLastBuild: false,
156149
keepAll: false,
157-
reportDir: 'build/gcov-html-gcc',
150+
reportDir: 'build/gcc/html',
158151
reportFiles: 'index.html',
159152
reportName: 'GCC Coverage HTML',
160153
reportTitles: '',
@@ -164,28 +157,23 @@ pipeline {
164157
}
165158
stage('Run tests [clang]') {
166159
steps {
167-
sh './build/clang-coverage/bin/calculate_test --gtest_output="xml:test-report-clang.xml"'
160+
sh './tools/run-test.sh build/clang-coverage/bin/calculate_test build/clang'
168161
junit(
169-
testResults: 'test-report-clang.xml'
162+
testResults: 'build/clang/test-report.xml'
170163
)
171-
// Create Cobertura coverage report
172-
sh 'gcovr --gcov-executable "llvm-cov gcov" -f src . --root ./ --exclude-unreachable-branches --xml-pretty --print-summary -o "coverage-clang.xml"'
173164
recordCoverage(
174165
name: 'Clang Coverage',
175166
id: 'clang-coverage',
176167
tools: [
177-
[parser: 'JUNIT', pattern: 'report-clang.xml'],
178-
[parser: 'COBERTURA', pattern: 'coverage-clang.xml']
168+
[parser: 'JUNIT', pattern: 'build/clang/test-report.xml'],
169+
[parser: 'COBERTURA', pattern: 'build/clang/test-coverage.xml']
179170
]
180171
)
181-
// Create HTML coverage report
182-
sh 'mkdir -p build/gcov-html-clang'
183-
sh 'gcovr --gcov-executable "llvm-cov gcov" -f src . --root ./ --exclude-unreachable-branches --html --html-details -o "build/gcov-html-clang/index.html"'
184172
publishHTML([
185173
allowMissing: false,
186174
alwaysLinkToLastBuild: false,
187175
keepAll: false,
188-
reportDir: 'build/gcov-html-clang',
176+
reportDir: 'build/clang/html',
189177
reportFiles: 'index.html',
190178
reportName: 'Clang Coverage HTML',
191179
reportTitles: '',

0 commit comments

Comments
 (0)