DEV Community

Sp1983
Sp1983

Posted on

DSCI series / Rakulang CI

In this series I'm going to show how one can use DSCI to build CI/CD pipelines for various languages and stacks. And in today's episode we talk about Raku


Building Raku module usually involves installing dependencies and running unit tests:

.dsci/jobs.yaml

jobs:
  - 
    id: ci
    path: .
Enter fullscreen mode Exit fullscreen mode

.dsci/task.bash

set -e
cd ../
ls -l
zef install . --deps-only
zef test .
echo "done"
Enter fullscreen mode Exit fullscreen mode

In this simple Bash task we install module dependencies first and then run unit tests for the module. Easy step. Also zef and Raku is preinstalled on DSCI job runner, which makes things even easier for you.


Test coverage.

Say, we'd like run test coverage report to make it sure module has enough test coverage. We are going to use Test::Coverage (which excellently explained in Liz post ) for that. It's logical to add separate task that installs Test::Coverage first, before doing anything. Let's refactor out pipeline, as DSCI is just a tiny YAML layer and everything else is regular programming language, so it's easy to do that:

.dsci/job.raku - holds all the tasks executed by the job:

run_task "deps";
run_task "ci";
Enter fullscreen mode Exit fullscreen mode

Tasks should reside under tasks/ folder, so we have two tasks:

.dsci/tasks/deps/task.bash

zef install --/test Test::Coverage
Enter fullscreen mode Exit fullscreen mode

And .dsci/tasks/ci/task.bash modified (from .dsci/task.bash) to:

set -e
cd ../
ls -l
zef install . --deps-only
raku -I. xt/coverage.rakutest
echo "done"
Enter fullscreen mode Exit fullscreen mode

When I run the pipeline against my dummy rakudist-teddy-bear module, I get these expected results:

09:59:18 :: All candidates are currently installed
09:59:18 :: # Failed test 'Coverage 33.33% >= 80%'
09:59:18 :: # at xt/coverage.rakutest line 5
09:59:18 :: # You failed 1 test of 2
09:59:18 :: task exit status: 1
09:59:18 :: task . FAILED
Enter fullscreen mode Exit fullscreen mode

Switching on/off test coverage

Sometimes module author might want to disable running test coverage on their code, for example when you're contributing to someone's module adding some lines of code, but still have not done with new tests for them yet, DSCI allows to tune pipeline in many ways and one of the simplest method is to rely on commit messages. So, let's say if a committer add no_coverage string into commit message, then test coverage logic is disabled, let's modify the pipeline according to new requirements:

.dsci/job.raku:

my $msg = config()<DSCI_MESSAGE>;

unless $msg ~~ /no_coverage/ {
  run_task "deps";
}
run_task "ci", %(
  skip_coverage => ( $msg ~~ /no_coverage/ ?? True !! False )
);
Enter fullscreen mode Exit fullscreen mode

And .dsci/tasks/ci/task.bash:

set -e
cd ../
ls -l
zef install . --deps-only
if test "$skip_coverage" = "True"; then
  zef test .
else 
 raku -I. xt/coverage.rakutest
fi
echo "done"
Enter fullscreen mode Exit fullscreen mode

That's it. Thanks for reading. Stay tuned for other languages and stacks examples. As one can see DSCI is extremely flexible and easy to work with as it's just a normal programming languages experience with a tiny YAML layer on top of it (to configure workflow). Combining the best of two worlds - declarative DSL and regular programming.

Top comments (0)