Skip to content
Snippets Groups Projects
Commit bdb6e1d5 authored by Mark de Wever's avatar Mark de Wever
Browse files

Partly adresses review comments.

Mainly to test the CI, more changes will be amended.
parent 578f777a
No related branches found
No related tags found
1 merge request!1CWG-10 Skeleton C++.
Pipeline #36967 passed
# Copyright (C) ASTRON (Netherlands Institute for Radio Astronomy)
# SPDX-License-Identifier: Apache-2.0
workflow:
rules:
# Don't create a pipeline if it's a commit pipeline on a branch and that branch has open merge requests
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- when: always
# Set to 1 to force a rebuild of the Docker image
variables:
BUILD_DOCKER_IMAGE: "0"
stages:
- versioning
- prepare
- linting
- build
- test
- pages
# This step determines the SHA1 of the Docker file used. It's stored in
# versions.env artifact. The environment variables are available for all steps
# depending on this step.
versioning:
stage: versioning
image: bitnami/git
script:
- echo BASE_IMAGE=${CI_REGISTRY_IMAGE}/base:$(git log -n 1 --pretty=format:%H -- ci/ubuntu_22_04-base) > versions.env
- cat versions.env
artifacts:
reports:
dotenv: versions.env
# Builds the Docker image containing the dependencies of the application.
# This image is cached, as long as the Dockerfile isn't modified new jobs reuse
# this image.
build-docker-ubuntu-22.04:
stage: prepare
needs: ["versioning"]
image: docker:latest
script:
- |
if ! docker manifest inspect $BASE_IMAGE > /dev/null || [ "$BUILD_DOCKER_IMAGE" = "1" ]; then
docker build --tag $BASE_IMAGE -f ci/ubuntu_22_04-base .
docker push $BASE_IMAGE
fi
before_script:
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
workflow: # Copyright (C) ASTRON (Netherlands Institute for Radio Astronomy)
rules: # SPDX-License-Identifier: Apache-2.0
# Don't create a pipeline if it's a commit pipeline on a branch and that branch has open merge requests
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- when: always
# Set to 1 to force a rebuild of the Docker image include: .gitlab-ci.common.yml
variables:
BUILD_DOCKER_IMAGE: "0"
stages:
- versioning
- prepare
- linting
- build
- test
#- publish Where to upload "packages" and which format
#- pages Doxygen or Read the Docs?
# This step determines the SHA1 of the Docker file used. It's stored in
# versions.env artifact. The environment variables are available for all steps
# depending on this step.
versioning:
stage: versioning
image: bitnami/git
script:
- echo BASE_IMAGE=${CI_REGISTRY_IMAGE}/base:$(git log -n 1 --pretty=format:%H -- ci/ubuntu_22_04-base) > versions.env
- cat versions.env
artifacts:
reports:
dotenv: versions.env
# Builds the Docker image containing the dependencies of the application.
# This image is cached, as long as the Dockerfile isn't modified new jobs reuse
# this image.
build-docker-ubuntu-22.04:
stage: prepare
needs: ["versioning"]
image: docker:latest
script:
- |
if ! docker manifest inspect $BASE_IMAGE > /dev/null || [ "$BUILD_DOCKER_IMAGE" = "1" ]; then
docker build --tag $BASE_IMAGE -f ci/ubuntu_22_04-base .
docker push $BASE_IMAGE
fi
before_script:
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
lint: lint:
stage: linting stage: linting
...@@ -72,7 +28,7 @@ test: ...@@ -72,7 +28,7 @@ test:
script: script:
- mkdir build - mkdir build
- cd build - cd build
- cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DCMAKE_CXX_FLAGS="-coverage" -DCMAKE_EXE_LINKER_FLAGS="-coverage" -G Ninja .. - cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTINDBUILD_TESTSG=ON -DCMAKE_CXX_FLAGS="-coverage" -DCMAKE_EXE_LINKER_FLAGS="-coverage" -G Ninja ..
- ninja - ninja
- ctest --output-on-failure |& tee ctest.out - ctest --output-on-failure |& tee ctest.out
- mkdir coverage - mkdir coverage
...@@ -98,3 +54,13 @@ build: ...@@ -98,3 +54,13 @@ build:
- cd build - cd build
- cmake -DCMAKE_BUILD_TYPE=Release -G Ninja .. - cmake -DCMAKE_BUILD_TYPE=Release -G Ninja ..
- ninja - ninja
pages:
stage: pages
needs: ["versioning", "build-docker-ubuntu-22.04"]
image: $BASE_IMAGE
script:
- mkdir build
- cd build
- cmake -DBUILD_DOCUMENTATION=ON -G Ninja ..
- ninja sphinx
# C++ project # C++ project
An example repository of an CI/CD pipeline for building, testing and deploying a C++ project An example repository of an CI/CD pipeline for building, testing and deploying a C++ project.
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://git.astron.nl/templates/cpp-project.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://git.astron.nl/templates/cpp-project/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description ## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges The repository can be used as a basis for new projects using C++ within ASTRON.
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. The code is intended to be copied in a new repository and used as basis for the
new project. After copying the code needs to be adjusted for the specific
project. The template offers:
## Visuals - CI jobs for building, testing, and generating documentation
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation - A basic Docker file to be used in the CI
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - A CMake project skeleton
- A Doxygen and Sphinx skeleton for documentation
- Formatting scripts for the code
## Usage Note: The project is intended to be used for C++ projects without Fortran code.
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. At the moment of writing there is no Fortran support for Ninja. This means the
project needs to be changed to use `make`.
## Support ## Getting started
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap - Clone the project in the directory `$repo`
If you have ideas for releases in the future, it is a good idea to list them in the README. - Install all dependencies as listed in `ci/ubuntu_22_04-base`
- Create the project: `cmake -DBUILD_TESTING=ON -H$repo -B$repo/build -G Ninja`
- Build the project: `ninja -C $repo/build`
## Contributing ## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. To contribute, please create a feature branch and a "Draft" merge request. Upon
completion, the merge request should be marked as ready and a reviewer should be
## Authors and acknowledgment assigned.
Show your appreciation to those who have contributed to the project.
## License ## License
For open source projects, say how it is licensed. This project is licensed under the Apache License Version 2.0.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
# Copyright (C) ASTRON (Netherlands Institute for Radio Astronomy)
# SPDX-License-Identifier: Apache-2.0
find_package(Doxygen REQUIRED) find_package(Doxygen REQUIRED)
find_package(Sphinx REQUIRED) find_package(Sphinx REQUIRED)
#
# The code is based on
# https://devblogs.microsoft.com/cppblog/clear-functional-c-documentation-with-sphinx-breathe-doxygen-cmake/
#
# #
# Determine the public headers for the API documentation. # Determine the public headers for the API documentation.
# #
...@@ -51,4 +59,4 @@ add_custom_command( ...@@ -51,4 +59,4 @@ add_custom_command(
COMMENT "Generating documentation with Sphinx") COMMENT "Generating documentation with Sphinx")
# Nice named target so we can run the job easily # Nice named target so we can run the job easily
add_custom_target(Sphinx ALL DEPENDS ${SPHINX_INDEX_FILE}) add_custom_target(sphinx ALL DEPENDS ${SPHINX_INDEX_FILE})
#ifndef CPP_INCLUDE_HELLO_HPP_INCLUDED // Copyright (C) ASTRON (Netherlands Institute for Radio Astronomy)
#define CPP_INCLUDE_HELLO_HPP_INCLUDED // SPDX-License-Identifier: Apache-2.0
#ifndef CPP_INCLUDE_HELLO_HPP
#define CPP_INCLUDE_HELLO_HPP
namespace lib { namespace lib {
...@@ -8,4 +11,4 @@ void Hello(); ...@@ -8,4 +11,4 @@ void Hello();
} // namespace lib } // namespace lib
#endif // CPP_INCLUDE_HELLO_HPP_INCLUDED #endif // CPP_INCLUDE_HELLO_HPP
# Copyright (C) ASTRON (Netherlands Institute for Radio Astronomy)
# SPDX-License-Identifier: Apache-2.0
add_subdirectory(lib) add_subdirectory(lib)
add_executable(cpp main.cpp) add_executable(cpp main.cpp)
......
# Copyright (C) ASTRON (Netherlands Institute for Radio Astronomy)
# SPDX-License-Identifier: Apache-2.0
add_library(hello SHARED hello.cpp) add_library(hello SHARED hello.cpp)
target_include_directories(hello PUBLIC "${CMAKE_SOURCE_DIR}/include") target_include_directories(hello PUBLIC "${CMAKE_SOURCE_DIR}/include")
// Copyright (C) ASTRON (Netherlands Institute for Radio Astronomy)
// SPDX-License-Identifier: Apache-2.0
#include "hello.hpp" #include "hello.hpp"
#include <iostream> #include <iostream>
......
// Copyright (C) ASTRON (Netherlands Institute for Radio Astronomy)
// SPDX-License-Identifier: Apache-2.0
#include "hello.hpp" #include "hello.hpp"
int main(int, const char **) { lib::Hello(); } int main(int, const char **) { lib::Hello(); }
# Copyright (C) ASTRON (Netherlands Institute for Radio Astronomy)
# SPDX-License-Identifier: Apache-2.0
find_package( find_package(
Boost Boost
COMPONENTS unit_test_framework COMPONENTS unit_test_framework
......
// Copyright (C) ASTRON (Netherlands Institute for Radio Astronomy)
// SPDX-License-Identifier: Apache-2.0
#include "hello.hpp" #include "hello.hpp"
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
......
// Copyright (C) ASTRON (Netherlands Institute for Radio Astronomy)
// SPDX-License-Identifier: Apache-2.0
#define BOOST_TEST_MODULE DP3 #define BOOST_TEST_MODULE DP3
#include <boost/test/unit_test.hpp> #include <boost/test/unit_test.hpp>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment