Skip to content

Instantly share code, notes, and snippets.

@AdrianWR
Last active March 7, 2024 21:54
Show Gist options
  • Save AdrianWR/15ec13be2760d17a0edc54705b85ac74 to your computer and use it in GitHub Desktop.
Save AdrianWR/15ec13be2760d17a0edc54705b85ac74 to your computer and use it in GitHub Desktop.
name: norminette
on: pull_request
jobs:
linter:
runs-on: ubuntu-18.04
steps:
- name: Checkout to project repository
uses: actions/checkout@v2
- name: Checkout linter from public repository
uses: actions/checkout@v2
with:
repository: 42sp/norminette-client
path: linter
- name: Set up Ruby version
uses: actions/setup-ruby@v1
with:
ruby-version: '2.6'
- name: Install ruby gem bundler
run: gem install bundler
- name: Install norminette ruby gem
run: (cd linter; bundle)
- name: Runs norminette linter
run: |
LOGS=$(mktemp)
./linter/norminette.rb $(find -regex '.*/.*\.\(c\|h\)$' -not -path '*/test/*') | tee $LOGS
echo "ERRORS=$(grep -E 'Error|Warning' $LOGS | wc -l)" >> $GITHUB_ENV
- name: Checks norminette linter result
run: |
echo "Norminette errors found: $ERRORS"
[[ $ERRORS == 0 ]]
@AdrianWR
Copy link
Author

AdrianWR commented Nov 9, 2020

Norminette Linter

A good code is a readable code.

What the heck is this?

This YAML script describes a simple linting workflow, using the norminette as the linter to check on source and header files of the C programming language. In 42 schools, all C projects must follow the norm, and the norminette is a linter application that help us on checking code style before submitting our projects. As it's mandatory to our projects, it might be useful to create a CI workflow to check if our projects have the ideal code style.

With Github Actions, it's possible to automate our continuous integration pipelines, which helps a lot in the development workflow. In this case, the workflow will run on every push, applying the norminette linter on every .c and .h file on your project directory. You can view the logs of the workflow in the Github Actions tab of your project, and the Actions badge would suit as a great cherry on the top of your 42 project. Here's an example of action log.

image

Okay, this seems interesting, how can I use it on my project?

Github Actions makes the CI process pretty simple. Just dump all this code on a file on the path .github/workflows, with the .yaml extension. For example, I like to create a .github/workflows/linter.yaml file. After inserting the code, just push it in a commit into your remote repository. Yep, that's it. Let's move on!

Hmmm... okay, but why? I can use norminette on my local machine...

Yeah, that's true. However, implementing a CI pipeline is a great way to learn more about how things are done on a work environment. With the rise of the DevOps culture, it's a good idea to try to automate these tasks. We can start with linting, and later move on to build or test workflows on our pipeline. We don't need to bother with the boring stuff, let's worry more about code.

Great! And how about the badge?

That's my favorite part. To create a badge on a README.md file, just write the following line of code on the desired position:

[![norminette Actions Status](https://github.com/<MY_GITHUB_PROFILE>/<MY_REPOSITORY>/workflows/norminette/badge.svg)](https://github.com/<MY_GITHUB_PROFILE>/<MY_REPOSITORY>/actions)

If everything works fine, you may have one of the following states, depending on the result status of the linting process.

image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment