For my fourth Hacktoberfest PR, I was determined to work on something related to CI/CD, Docker, or perhaps something DevOps-oriented. After hunting through several repositories, I found some promising CI/CD issues, but they often required touching multiple workflows or were deeply embedded in existing configurations. Given the potential risk of disrupting the projects with complex changes, I decided to keep looking until I found a better fit. That’s when I came across valid-gtin - a lightweight JavaScript library designed to validate GTINs (Global Trade Item Numbers).
At first glance, it was a straightforward repository with only a few files and a single function responsible for GTIN validation. But that’s what made it perfect: it was clean, lightweight, and, best of all, the issue at hand was exactly what I was looking for.
The Issue
The issue was focused on improving the test.yml GitHub Actions workflow file by adding path filtering to make testing more efficient by only running tests on specific file changes and thus reducing unnecessary runs. Earlier, every commit to the main branch or new pull requests, triggered tests, regardless of whether relevant files had changed. My goal was to update the workflow so that tests would only run when certain files (like .js, .ts, or GitHub workflow files) were modified. This was an ideal opportunity to learn about workflow filtering while keeping things relatively low-risk.
After forking the repository and cloning it locally, I created a new feature branch and started by researching GitHub Actions path filtering options. I had never actually set up path-specific filters in a workflow before, so I spent some time experimenting with different configurations to get a better understanding of how to target files accurately and found relevant documentation on GitHub Docs.
In the test.yml file, I updated the workflow to be more efficient by modifying the on event so it would listen only to changes in specific file types, hence making the CI/CD process lighter and more efficient. The updated workflow configuration included path filters which looked like this:
After configuring the workflow, I committed my changes, pushed the branch, and opened a pull request. Setting up CI/CD filters sounds straightforward, but it was surprisingly fun digging into the specifics and understanding how path filters could optimize workflows. I liked the idea of improving the efficiency of a smaller project, where every little optimization could streamline contributions and keep the repository agile. The repository owner reviewed the pull request fairly quickly and the PR was successfully merged.
This PR modifies the GitHub Actions workflow to trigger tests only when specific files are changed, reducing unnecessary test runs and saving CI resources. With this update, the tests will only run if any of the following files or patterns are modified:
Files with extensions .mjs, .js, .ts
.github/workflows/*.yml
package.json
tsconfig.json
Changes Made:
Updated .github/workflow/test.yml by adding paths filtering under push and pull_request triggers, specifying the relevant files to watch.
This PR marked a significant step for me in Hacktoberfest, allowing me to contribute to CI/CD workflows, which I’ve been interested in for a while. Working on a smaller repository was also refreshing, as it gave me space to try new configurations without the pressure of handling a huge codebase. I enjoyed this contribution for the balance it struck between learning something new and enhancing the project in a meaningful way.