Skip to content
Snippets Groups Projects
Commit fc39ea66 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

ENH: Pipeline with working tests.

parent 45585467
Branches
Tags
No related merge requests found
Pipeline #10293 passed
FROM debian:buster
RUN apt-get update \
&& \
apt-get install -y \
make \
octave \
python3-pip \
python3-sphinx
RUN pip3 install breathe miss_hit sphinx-rtd-theme recommonmark
#
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2021 Indiscale GmbH <info@indiscale.com>
# Copyright (C) 2021 Daniel Hornung <d.hornung@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
variables:
OCTAVE_REGISTRY_IMAGE: $CI_REGISTRY_IMAGE/testenv:$CI_COMMIT_REF_NAME
# CPPINTTEST_PIPELINE: https://gitlab.indiscale.com/api/v4/projects/111/trigger/pipeline
# CPPINTTEST_BRANCHES: https://gitlab.indiscale.com/api/v4/projects/111/repository/branches
# GIT_SUBMODULE_STRATEGY: normal
# ## FOR DEBUGGING
# TRIGGERED_BY_REPO: CPPLIB
# TRIGGERED_BY_REF: $CI_COMMIT_REF_NAME
# TRIGGERED_BY_HASH: $CI_COMMIT_SHORT_SHA
image: $OCTAVE_REGISTRY_IMAGE
stages:
- setup
- test
- deploy
######## Setup ########
# Build a docker image in which tests for this repository can run
build-testenv:
tags: [ cached-dind ]
stage: setup
image: docker:20.10
only:
- main
- schedules
- f-pipeline
script:
- cd .docker
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
# Attempt to reuse the previously stored image.
- docker pull "$OCTAVE_REGISTRY_IMAGE" || true
- docker build
--pull
--cache-from "$OCTAVE_REGISTRY_IMAGE"
-t "$OCTAVE_REGISTRY_IMAGE" .
- docker push "$OCTAVE_REGISTRY_IMAGE"
# info:
# tags: [cached-dind]
# image: docker:20.10
# stage: info
# needs: []
# script:
# - echo "Pipeline triggered by $TRIGGERED_BY_REPO@$TRIGGERED_BY_REF ($TRIGGERED_BY_HASH)"
# - echo "$CPPLIB_REGISTRY_IMAGE"
# - echo "$CPPINTTEST_PIPELINE"
# - echo "$CPPINTTEST_BRANCHES"
# - echo "$GIT_SUBMODULE_STRATEGY"
# Build a docker image in which tests for this repository can run
# build-testenv:
# tags: [ cached-dind ]
# image: docker:20.10
# stage: setup
# script:
# - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
# # use here general latest or specific branch latest...
# - docker pull $CPPLIB_REGISTRY_IMAGE|| true
# - docker build
# --file .docker/Dockerfile
# --pull
# --cache-from $CPPLIB_REGISTRY_IMAGE
# --tag $CPPLIB_REGISTRY_IMAGE .
# - docker push $CPPLIB_REGISTRY_IMAGE
# Formatting with miss_hit
code_style:
tags: [ docker ]
stage: test
script:
- make style
allow_failure: true
# Unit tests
test:
tags: [ docker ]
stage: test
script:
- make test
# trigger the integration tests
# trigger_inttest:
# tags: [ docker ]
# stage: deploy
# script:
# ## Determine the cppinttest branch...
# # ... use an f-branch if posible...
# - if echo "$CI_COMMIT_REF_NAME" | grep -c "^f-" ; then
# CPPINT_REF=$CI_COMMIT_REF_NAME ;
# fi;
# # ... or use main if possible...
# - if [[ "$CI_COMMIT_REF_NAME" == "main" ]] ; then
# CPPINT_REF=main ;
# fi
# # ... and fall-back to dev
# - CPPINT_REF=${CPPINT_REF:-dev}
# - echo "Triggering caosdb-cppinttest@${CPPINT_REF}"
# - curl -w "%{stderr}HTTPCODE=%{http_code}" -X POST
# -F token=$CI_JOB_TOKEN
# -F "variables[TRIGGERED_BY_REPO]=$TRIGGERED_BY_REPO"
# -F "variables[TRIGGERED_BY_REF]=$TRIGGERED_BY_REF"
# -F "variables[TRIGGERED_BY_HASH]=$TRIGGERED_BY_HASH"
# -F "variables[CPPLIB_REGISTRY_IMAGE]=$CPPLIB_REGISTRY_IMAGE"
# -F ref=${CPPINT_REF} $CPPINTTEST_PIPELINE 2>HTTPCODE
# # fail if the request failed
# - grep -c "HTTPCODE=2" HTTPCODE
# Build the sphinx documentation and make it ready for deployment by Gitlab Pages
# Special job for serving a static website. See https://docs.gitlab.com/ee/ci/yaml/README.html#pages
# .pages_prepare: &pages_prepare
# tags: [ cached-dind ]
# stage: deploy
# script:
# - mkdir -p build
# - cd build
# - cmake ..
# - cmake --build . --target doc-sphinx
# - cp -r doc/sphinx_out ../public
# test_pages:
# <<: *pages_prepare
# pages:
# <<: *pages_prepare
# only:
# refs:
# - main
# artifacts:
# paths:
# - public
...@@ -3,3 +3,8 @@ ...@@ -3,3 +3,8 @@
* caosdb-cpplib * caosdb-cpplib
* octave >= 4.4 * octave >= 4.4
* liboctave-dev ? * liboctave-dev ?
## Useful tools ##
* Linter: [`miss_hit`](https://github.com/florianschanda/miss_hit): `pip3 install --user miss_hit`
...@@ -28,3 +28,11 @@ help: ...@@ -28,3 +28,11 @@ help:
.PHONY: doc .PHONY: doc
doc: doc:
$(MAKE) -C src/doc html $(MAKE) -C src/doc html
.PHONY: style
style:
mh_style --octave src
.PHONY: test
test:
cd src && octave Run_Test.m
# -*- mode:conf; -*-
# See https://florianschanda.github.io/miss_hit/style_checker.html
line_length: 100
regex_function_name: "[a-z]+(_[a-z]+)*"
suppress_rule: "whitespace_comments"
tab_width: 2
% (C) Copyright 2021 IndiScale GmbH <info@indiscale.com>
% (C) Copyright 2021 Daniel Hornung <d.hornung@indiscale.com>
%
% This file is a part of the CaosDB Project.
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU Affero General Public License as
% published by the Free Software Foundation, either version 3 of the
% License, or (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU Affero General Public License for more details.
%
% You should have received a copy of the GNU Affero General Public License
% along with this program. If not, see <https://www.gnu.org/licenses/>.
%% Example file with dummy code from https://www.gnu.org/software/octave/
x = -10:0.1:10; % Create an evenly-spaced vector from -10..10
y = sin(x); % y is also a vector
plot (x, y);
title ("Simple 2-D Plot");
xlabel ("x");
ylabel ("sin (x)");
% (C) Copyright 2021 IndiScale GmbH <info@indiscale.com>
% (C) Copyright 2021 Daniel Hornung <d.hornung@indiscale.com>
%
% This file is a part of the CaosDB Project.
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU Affero General Public License as
% published by the Free Software Foundation, either version 3 of the
% License, or (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU Affero General Public License for more details.
%
% You should have received a copy of the GNU Affero General Public License
% along with this program. If not, see <https://www.gnu.org/licenses/>.
% ------------------------------------------------------------------------
% Run the tests, exit with their value.
addpath("dummy");
[n, nmax, nxfail, nbug, nskip, nrtskip, nregression] = ...
test("some_function.m", "verbose");
disp(["Passed " num2str(n) " out of " num2str(nmax) " tests."]);
if n == nmax
exit(0);
end
exit(1);
% (C) Copyright 2021 IndiScale GmbH <info@indiscale.com>
% (C) Copyright 2021 Daniel Hornung <d.hornung@indiscale.com>
%
% This file is a part of the CaosDB Project.
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU Affero General Public License as
% published by the Free Software Foundation, either version 3 of the
% License, or (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU Affero General Public License for more details.
%
% You should have received a copy of the GNU Affero General Public License
% along with this program. If not, see <https://www.gnu.org/licenses/>.
function result = some_function(arg1, arg2)
if arg1 >= arg2
error("arg1 must be smaller than arg2!");
end
x = arg1:0.1:arg2;
result = sin(x);
end
%%%%%%%%%%
% See https://wiki.octave.org/Tests and
% https://octave.org/doc/interpreter/Test-Functions.html for unit tests.
%!assert (some_function(1, 2))
%!assert (some_function(-0.1, 0.1)(2) == 0)
%!error <arg1 must be smaller than arg2!> (some_function(3, 2))
%!demo
%! ## Try out some_function(a, b):
%! some_function([-1:1])
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
# Copyright (C) 2021 Daniel Hornung <d.hornung@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
## Example file with dummy code from https://www.gnu.org/software/octave/
x = -10:0.1:10; # Create an evenly-spaced vector from -10..10
y = sin(x); # y is also a vector
plot (x, y);
title ("Simple 2-D Plot");
xlabel ("x");
ylabel ("sin (x)");
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment