An example of ABAP continuous integration based on abapgit and abaplint

Time:2021-12-7

This is the sixty-first article of Jerry in 2021, and the 338th official account of the Wang Zixi public number.

Short song line
Cao Cao

Sing when drinking, life is geometric!

For example, the morning dew is much more bitter.

Be generous and unforgettable.

How to relieve worries? Only Du Kang.

Qingqingzijin, leisurely my heart.

But for your sake, I ponder so far.

Yo yo, deer crow, eat wild apples.

I have a guest who plays the drum, the harp and the Sheng.

As bright as the moon, when can I do it?

Sorrow comes from it and cannot be cut off.

Cross the paths and cross the paths in vain.

Qikuo talks about the past and remembers the old kindness.

The moon is bright and the stars are rare. Black magpies fly south.

Three turns around the tree, what branch can we rely on?

The mountains are never tired of being high and the sea is never tired of being deep.

Zhou Gong spits and feeds, and the world returns to its heart.

An example of ABAP continuous integration based on abapgit and abaplint

Jerry wrote an article before,Use abapgit to transfer code between ABAP on premises system and SAP cloud platform ABAP environment, this paper introduces the basic usage of abapgit, an open source tool.

In this article, Jerry introduces a specific scenario of realizing ABAP continuous integration based on abapgit and another open source tool, abaplint: when new code is submitted to the ABAP code warehouse, ABAP code detection is automatically triggered.

Of course, continuous integration means that as long as new code is submitted, the build and test will be run automatically and the running results will be fed back. Only when you can ensure that the newly submitted code meets the expectations, can you integrate the new code into the trunk. Therefore, the example introduced in this article is only a small step in ABAP continuous integration.

Let’s first have a brief look at abaplint. Friends who use SAP ui5 must have been exposed to eslint, a JavaScript code detection tool.

Jerry uses angular to develop SAP commerce cloud UI every day, and also uses the extension of visual studio code named tslint to detect typescript code.

An example of ABAP continuous integration based on abapgit and abaplint

Similarly, abaplint is also an open source tool for detecting ABAP code according to specified rules, which is written based on typescript.

Here is a demo website:

https://playground.abaplint.org/

Abaplint.json is a configuration file that defines detection rules. The code violating the rules will be highlighted by a red wavy line:

An example of ABAP continuous integration based on abapgit and abaplint

I adjusted the code according to the prompts detected by abaplint, and then the warning messages disappeared.

An example of ABAP continuous integration based on abapgit and abaplint

Note that abaplint’s detection of the code is completely different from the syntax check of the code on the ABAP server. The latter is completed by the compiler located in the ABAP kernel, while the former is only the detection based on the source code text level implemented by typescript. Abaplint itself cannot recognize the ABAP language from the syntax level, but mechanically completes the detection task defined in abaplint.json based on text static analysis.

The following describes how to configure abapgit and abaplint to achieve the simplest ABAP continuous integration. This example does not require any development, only contains some configuration work, which can be completed in less than half an hour.

(1) Create a GitHub repository to store ABAP code. I chose to put all the ABAP code in the SRC folder.

Note: abaplint can only scan ABAP code files in special format, that is, ABAP code submitted through abapgit.
An example of ABAP continuous integration based on abapgit and abaplint

Create a new. GitHub folder with a subfolder workflow, which contains an abaplint.yml file.

An example of ABAP continuous integration based on abapgit and abaplint

This abaplint.yml file is responsible for specifying the operation content to be performed through GitHub workflow when new code is submitted in the code warehouse. The on instruction starting from line 2 tells GitHub to execute a job named abaplint when a push or pull request arrives in the main branch. The specific steps of the latter are defined from the steps instruction on line 14.

The uses instruction in line 15 means to reuse GitHub’s own setup node action to complete the preparation of the node.js running environment.

The setup node action is implemented in the GitHub repository as follows:

https://github.com/actions/se…

An example of ABAP continuous integration based on abapgit and abaplint

The following command line maintained in the run command means that after the node.js running environment is ready, install the abaplint command line tool and execute it.

npm -g install @abaplint/cli
abaplint

(2) Create abaplint.json under the root directory and define ABAP code detection rules. For demonstration purposes, I only enabled a few simple rules as shown in the figure below. For all detection rules supported by abaplint.json, please refer to this link:

https://github.com/abapGit/ab…

An example of ABAP continuous integration based on abapgit and abaplint

After creating the abaplint.yml and abaplint.json files, submit any code to the main branch, and you can see the automatic abaplint detection records for these code submissions in the actions tab of the code warehouse:

An example of ABAP continuous integration based on abapgit and abaplint

Click one to see the reason for the current workflow execution failure – the code violates my customized abaplint detection rule: the defined keyword needs to be lowercase, and the keyword add marked as obsolete is used, etc.

An example of ABAP continuous integration based on abapgit and abaplint

At present, automated tools for continuous integration construction and testing emerge in an endless stream in the open source community. The sap commerce cloud Spartacus UI development team worked by Jerry uses Travis

An example of ABAP continuous integration based on abapgit and abaplint

Travis supports binding GitHub’s code warehouse. As long as new code is submitted, it will be automatically fetched. Then provide a running environment, execute the test and complete the build.

In order to enable Travis to capture the code submitted by my ABAP code warehouse, I created a. Travis.yml file in the project root directory. The content is shown in the following figure. The command line in the script area is exactly the same as that in abaplint.yml described above. I won’t repeat it here.

An example of ABAP continuous integration based on abapgit and abaplint

After editing the. Travis.yml file, resubmit it, log in to the Travis console, and find that this submission triggers a new Travis build:

https://app.travis-ci.com/git…

An example of ABAP continuous integration based on abapgit and abaplint

The reason for the build failure is that it violates the rules defined by abaplint.json:

An example of ABAP continuous integration based on abapgit and abaplint

Honestly, according to the results output by abaplint, repair and resubmit all violations of the rules in the ABAP code. This time, the GitHub workflow and the build log in Travis finally show a green light.

An example of ABAP continuous integration based on abapgit and abaplint

An example of ABAP continuous integration based on abapgit and abaplint

The ABAP code warehouse address used for this demonstration is as follows:

https://github.com/wangzixi-d…

summary

Through a specific example, this paper introduces how to use abapgit, abaplint and Travis to realize the steps of automatic code detection based on new code submission in ABAP continuous integration scenario.

In the actual SAP product development project, the scenario complexity of continuous integration is much greater than this example, so it is usually completed by a specially assigned person or even a special team.

Thanks for reading.

More Jerry’s original articles are: “Wang Zixi”:
An example of ABAP continuous integration based on abapgit and abaplint
Jerry’s ABAP topic

Recommended Today

Heavyweight Tencent cloud open source industry’s first etcd one-stop governance platform kstone

​ Kstone open source At the kubecon China Conference held by CNCF cloud native foundation on December 9, 2021,Tencent cloud container tke team released the open source project of kstone etcd governance platform. KstoneIt was initiated by the TKE team of Tencent cloud containerCloud native one-stop etcd governance project based on kubernetes。 The project originates […]