| Comments

Problem Description

Suppose one task in your Continuous Integration (CI) pipeline is triggered on every commit to the project repository. Some the files in the repository require passing the check of the CI task, while some other files do not require passing the check. What should the CI task do to decide if it is needed to perform the needed checking on the commit?

Design the CI task

The CI task need have the ability to analyze the files included in the commit, and decide whether the commit requires passing a check, or not. We need tell the CI task which files require passing a check through configurations.

Configuration

There are multiple ways to design the configurations, such as:

1. Only list the files or paths requiring the check

2. Only list the files or paths do not require the check

3. List the files or paths requiring the check, and also list the subset files or paths that do not require the check

The 3rd way probably is the optimal one because it provides the flexibility for you to put a large scope path as the files need check, and then exclude a subset from the large scope path. For example:

To apply the 3rd method, the configuration of the CI task will include two types: inclusion, and exclusion.

Analyze files in the commit

The needed analysis process of the CI task is:

• If none of the files in the commit matches the inclusion in configuration, skip the check

• If all the files in the commit matching the inclusion in configuration also matching the exclusion in configuration, skip the check

• In other cases, the check for this commit is needed

The complexity of the given process is O(n2).

A mistake that could happen in the analysis process is when you analyze the exclusion cases, you should do the analysis only on the files that match inclusion configuration, which is a subset of files in the commit.

Example with the Python

Here is the code written in Python for demonstrating the case discussed above.

• commit_files: a list containing all the files in the commit

• config: a dictionary containing inclusion and exclusion configurations

• config['include']: a list containing all the files or paths need check

• config['exclude']: a list containing the files or paths do not need check