DEV Community

Majd Al Mnayer
Majd Al Mnayer

Posted on

GitHub Workflows: The First Line of Defense

For this week, our task was to automate everything: GitHub workflows for testing, linting, building, and error checking. Additionally, I set up a dev container that contributors can use in GitHub Codespaces for a fast, hassle-free setup. Finally, we were assigned to write tests for a classmate's project!

Setting up the GitHub Actions CI workflow was straightforward, as I had already done it several weeks ago in release 0.1. The workflow includes several jobs. The first job builds the project and ensures there are no build errors. The second job runs eslint to ensure the code meets our linting standards. The third job runs the tests and verifies they all pass! I also configured the GitHub workflows to run only on pull requests when they are opened, reopened, marked as ready for review, or when new commits are pushed.

Setting up workflows is not new for me, as I’ve done it previously in the Cloud Computing course and in my job. As for adding tests to a pclassmate's project](https://github.com/cleobnvntra/genereadme/pull/19), The main difference between my partner’s testing setup and mine was in code granularity. I made sure my code is modular, with small, testable pieces working together, making it easier to test. My partner’s code, however, was constructed in a way that combined many elements in the same file, which made testing slightly harder. Still, I found that it’s possible to test effectively without needing extensive project context—I covered edge cases, handled errors, and more.

CI is amazing and should always be one of the first setups in a project, especially for testing and linting. It ensures that the project follows standards, all tests pass, and builds don’t fail before a change is pushed to the main branch!

For the optional challenges, I had already set up linting in my workflow, so this was already done. However, setting up the devcontainer was certainly challenging. I encountered an issue with the Docker visual studio code extension that caused the devcontainer's build to fail on Windows but pass on WSL. After some troubleshooting, I found a workaround: cleaning any locally cached files (using apt-get clean) before the build process started.

Finally, the devcontainer was set up with all the recommended extensions, rules, and settings required to provide a premium, hassle-free contribution experience for OptimizeIt!

And the coolest part? Anyone can use GitHub Codespaces to run the devcontainer instantly, allowing for the smoothest possible development experience when contributing. No more Operating System issues, no more “but it worked on my machine,” and no more time wasted on annoying setup steps—everything is ready for any contributor!

Codespaces

Summary

Overall, I’d say this week was essential for open-source development. Ensuring your repository is guarded against issues that might otherwise cause problems is the first line of defense. It’s crucial for maintaining cleanliness and adhering to standard guidelines. Additionally, having a ready-to-use development environment for contributors not only smooths the development experience but also encourages more people to contribute with ease!

Top comments (0)