Attempting a larger bug fix I - Planning
Tags: opensource, beginners, programming
Published: 2023-12-05 04:32:41

## Finding a bug when working on a different Issue
### Original Issue
Recently, I was working on updating a CI workflow in [Skyrim Community Shaders (CS)](https://github.com/doodlum/skyrim-community-shaders), a Skyrim shaders mod. The [CI workflow](https://github.com/doodlum/skyrim-community-shaders/blob/dev/.github/workflows/clang_format.yml) in question runs an external GitHub Action, [DoozyX/clang-format-lint](https://github.com/DoozyX/clang-format-lint-action) that lints the entire CS codebase using [clang-format](https://clang.llvm.org/docs/ClangFormat.html). The Issue I was working on involves modifying the CI workflow to lint only modified files. This would prevent `clang-format` from running on unintended targets and perhaps even speed up the workflow.

### The modified workflow
So far, I've been able to modify the workflow, by pairing `clang-format-lint` with [tj-actions/changed-files](https://github.com/tj-actions/changed-files), another Marketplace action that retrieves all modified files. By pairing these two actions, you can pass a list of modified files to `clang-format-lint`.

The modified workflow works! Here's a [successful workflow run](https://github.com/rjwignar/skyrim-community-shaders/actions/runs/6987335046/job/19013758175):

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g6mrtwsaztaciuh8hxt8.png)

### Don't forget to lint shader files
In this workflow run, only a couple C++ source files were modified. The `clang-format-lint` action should also run on shader files (files with the `.hlsl` and `.hlsli` extensions):

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/br6rpdm6rh3lypfjn1tx.png)

Some of the shader files have whitespaces in their filepaths. What happens when you modify one of these files and then [run the workflow](https://github.com/rjwignar/skyrim-community-shaders/actions/runs/6984314480/job/19006907593)?

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xu111q056xsfm1dn4kg0.png)

### Broken filepaths
Some of the filepaths are broken apart. Here are the four original filepaths:
```
features/Complex Parallax Materials/Shaders/ComplexParallaxMaterials/CRPM.hlsli
features/Complex Parallax Materials/Shaders/ComplexParallaxMaterials/ComplexParallaxMaterials.hlsli
src/Features/DistantTreeLighting.cpp
src/Features/DistantTreeLighting.h
```
Here's what happens when they're passed to the `clang-format-lint` action:
```
features/Complex,
Parallax,
Materials/Shaders/ComplexParallaxMaterials/CRPM.hlsli,
features/Complex,
Parallax,
Materials/Shaders/ComplexParallaxMaterials/ComplexParallaxMaterials.hlsli,
src/Features/DistantTreeLighting.cpp,
src/Features/DistantTreeLighting.h
```

### What's the deal?
I found a bug in one of the Marketplace GitHub Actions!
One solution would be to ignore shader files in the `clang-format-lint` step, as they appear to be the only files that have whitespaces in their filepaths. Alternatively, all directory names could be truncated to remove the whitespaces. However, a discussion with the maintainers showed both of these options were off the table. More importantly, these options are only a workaround, and won't address the bug found in one of these Marketplace actions.

The only solution here is to locate the bug in one of the Marketplace actions. Doing so will allow me to complete my original Pull Request.

### The Plan
The bug I found involves how the modified workflow handles filepaths with spaces in them. My modified workflow uses two external GitHub actions:
- tj-actions/changed-files, and
- DoozyX/clang-format-lint

The following are my objectives for fixing my observed bug:
1. Confirm the source of the Issue in one of the external GitHub Actions
2. File an Issue in the appropriate GitHub Action
3. Apply the bug fix in the GitHub Action.
4. Test and confirm the fix
5. Make a pull request to the GitHub Action
6. Work with the GitHub Action maintainer(s) on the Pull Request.
7. If/when the pull request is approved, continue working on my original Issue on [Skyrim Community Shaders](https://github.com/doodlum/skyrim-community-shaders)
8. Submit a Pull request to fix the [original Issue](https://github.com/doodlum/skyrim-community-shaders/issues/128) I was working on

### Current progress
At this point, I've already done some of the work and identified the bug one in of the external GitHub action. However, I need to collect some more information before filing the issue, so I can properly communicate to the maintainers that the bug is due to this GitHub action and not the other one.

At the same time, I'm also working on a fix for the external GitHub action. Over the next few days I plan to write about my experience filing the issue and making a Pull Request for the external GitHub Action.