DEV Community

Lucian Green
Lucian Green

Posted on • Edited on

Yet Another Open Source CI/CD Tool

Screenshot 2023-05-29 at 8 30 21 pm
Image of a female android by @deloan.

What is it?

In "DevOps" speak, CI means continuous integration of changes, and CD is continuous delivery and deployment, or placement of the best configuration of these changes back into the repository. If there are n changes, there are 2^n possible configurations of these changes, suggesting an upper limit of seven changes per run, meaning making few changes per time. The algorithm can be run on changes, allowing continuous code correctness.

Why I made it

I had recently written a List Prolog to Prolog pretty printer (which was its prerequisite). List Prolog is a variant of Prolog, a logic programming language in which programs are lists. I needed a way to check all the code before uploading it, preventing bugs and annoying installation problems.

Can it be used for other programming languages?

At its core is a diff by newline algorithm, so there's no reason why you couldn't modify it for programming languages other than Prolog. Every time it converts between Prolog and List Prolog, you would need to change it to convert between another language and List Prolog, which it procures tests from, checks for changed lines, and builds repositories.

Update: Lucian CI/CD can now process non-Prolog source files. These source files, coupled with tests, are integrated like Prolog.

Installing

  1. Download and install SWI-Prolog for your machine at https://www.swi-prolog.org/build/.
  2. Install LucianCICD using List Prolog Package Manager (LPPM):
git clone https://github.com/luciangreen/List-Prolog-Package-Manager.git
cd List-Prolog-Package-Manager
swipl
['lppm'].
lppm_install("luciangreen","luciancicd").
halt
Enter fullscreen mode Exit fullscreen mode

Setting up

  1. Create a folder "Github_lc" at the same level as your "GitHub" folder or the folder containing your repositories. This step is done by ['luciancicd.pl']. set_up_luciancicd.. NB. Please try the software with a folder other than "GitHub" such as "GitHub2" to see if it suits you.

NB. Edit the source and destination folder, such as "GitHub2", by modifying repositories_paths1//1 in luciancicd.pl. You can also edit folders to omit.

  1. Before running, enter or modify tests in the source files in the repositories, for example:
% remove_and_find_item_number([a,b,c],2,c,N2).
% N2 = 2.
% remove_and_find_item_number([a,b,b,c],2,c,N2).
% N2 = 3.
Enter fullscreen mode Exit fullscreen mode

Running

  • To load the algorithm, enter the following:
['luciancicd.pl'].
Enter fullscreen mode Exit fullscreen mode
  • Run with luciancicd. - This tests repositories with changes. Run before committing changes.

What it does - Integrates changes into a possible new repository.

Figure 1. "Diff output. These are the changes combinations were taken from. Key: Insertion, Change and Deletion
[
[[n,comment],["File delimiter","../../Github_lc/a","a.pl"]],
[[n,comment],["% a(A)."]],
[[n,comment],["% A=1."]],
[[n,a],[1]],
[[n,comment],["% b(C)."]],
[[n,comment],["% C=1."]],
[[n,b],[1]],
[[n,c],[1]],
[[n,d],[1]],
Change: [["[[n,comment],[""%e(1).""]],"],' -> ',["[[n,e],[1]],"]]
[[n,f],[1]],".
Screenshot 2023-05-29 at 7 43 10 pm

Figure 1 shows the changes to the source files. The algorithm develops possible configurations from these changes and tests them.

What it does - Builds repositories using dependencies stored in the file.

The algorithm finds repositories depending and dependent on modified files and includes them in the possible builds. You can edit the dependencies in the dependencies registry file (below), and the behaviour of the built algorithm based on dependencies included by the source files should reflect the dependencies listed in the registry file used at installation.

  • Note: Dependencies are in List-Prolog-Package-Manager/lppm_registry.txt, in form [[User,Repository,Description,Dependencies], etc].

  • For example:
    ["luciangreen", "State-Machine-to-List-Prolog",
    "Converts State Saving Interpreter State Machines to List Prolog algorithms.",
    [
    ["luciangreen","SSI"]
    ]]
    .

There are more instructions about how to edit dependencies at https://github.com/luciangreen/List-Prolog-Package-Manager.

What it does: Tests to find the correct repository configuration and moves files into the folder.

The algorithm tests all files in all repositories connected with changed files. The first build configuration, which has the fewest possible changes, is stopped with.

Figure 2. The Prolog script that runs the tests.

#!/usr/bin/swipl -f -q

:- include('a.pl').
:- initialization(catch(main, Err, handle_error(Err))).

handle_error(_Err):-
    halt(1).
main :-
    d(A),A=1, nl,
    halt.
main :- halt(1).
Enter fullscreen mode Exit fullscreen mode

Figure 2 shows the Prolog script, testcicd.pl, that loads the files and runs the tests collected. It runs with chmod +x testcicd.pl and swipl -f -q ./testcicd.pl.

One can read which tests failed in all combination builds, where, if a test fails, the algorithm doesn't move files into the repository.

NB. The algorithm moves finished files into the original repository, and the files in the repository swap places into ../private2/luciancicd-testing/.

What does it do, and does it work?

While one might think it would be simpler to make and test changes, this tool tries the usefulness of each changed line individually. One can ensure it works by entering tests to keep changes and make sure everything is stable.

Can it be integrated with ChatGPT?

Yes, the bottom-up Prolog version of Lucian CI/CD can be integrated with ChatGPT to complete or correct predicates with bugs. This would require the specs of all predicates in question and a ChatGPT API account.

Lucian Green

https://github.com/luciangreen/luciancicd

Top comments (0)