florianschanda / miss_hit

MATLAB Independent, Small & Safe, High Integrity Tools - code formatter and more
GNU General Public License v3.0
162 stars 21 forks source link

templates for continuous integration and git-hooks #152

Closed Remi-Gau closed 3 years ago

Remi-Gau commented 4 years ago

A couple of template files users could add to their repo or their .git/hook folder to make sure that their code is up to their standards before committing / pushing / merging.

For continuous integration:

For git hooks

florianschanda commented 4 years ago

@Remi-Gau: please do open a PR for the travis stuff, since I am very unfamiliar with it. That said, since the stuff you linked is pretty simple I can make a stab at my own version. But some comments on the linked config:

florianschanda commented 4 years ago

Also, in your opinion, what would you put in the pre-commit hook, and what would you put in the pre-push hook?

I can see two scenarios:

1

Pre-commit:

Post-commit:

2

Pre-commit:

Post-commit

Remi-Gau commented 4 years ago

@Remi-Gau: please do open a PR for the travis stuff, since I am very unfamiliar with it. That said, since the stuff you linked is pretty simple I can make a stab at my own version. But some comments on the linked config:

* Ideally clone the latest release, not master (I do try to keep things non-broken, but it's not guaranteed)

* I suppose for that I need to have a `stable` branch :)

* I was thinking of putting this into `doc` and describe it in https://florianschanda.github.io/miss_hit/configuration.html since that document will/should contain everything about configuring and setting up miss_hit for your project

Yup I am about to start some sort of template repo for matlab analysis, I would use that to test those config files for travis and github actions.

The thing is that I have some experiments to prepare for next week, so don't expect a first PR before the end of next week. :running_man:

Good point on using on a release for those CI things.

Good idea about having this in the doc. :smile: :rocket:

Remi-Gau commented 4 years ago

Also, in your opinion, what would you put in the pre-commit hook, and what would you put in the pre-push hook?

I can see two scenarios:

1

Pre-commit:

* mh_style --fix

Post-commit:

* mh_style

* mh_metric --ci

2

Pre-commit:

* mh_style --fix

* mh_metric --ci

Post-commit

* Nothing

Slight preference for scenario one, as it allows you to commit some code that you then get some metric info about so you can eventually refactor and to improve things.

I like to try to keep first draft and refactoring separated. But maybe that's just me.

What do you think ?

Remi-Gau commented 4 years ago

Started a quick and dirty repo to design a matlab analysis template. https://github.com/Remi-Gau/template_matlab_analysis/issues/1

Will create a the templates for the linter there and then make a PR on this repo. Is that good with you @florianschanda ?

florianschanda commented 4 years ago

Sounds good, yeah! I will try and write some more documentation soon!

Remi-Gau commented 4 years ago

hey @florianschanda

This could be a template for a .travis.yml. Very light weight but gets the job done

# Travis CI (https://travis-ci.org/)
# This will only work on your repo if you have an account on travis and you
# have set it up to run continuous integration on this this repo

# Linux distribution (bionic beaver)
dist: bionic

# Language and version
language: python
python:
  - "3.6" # current default Python on Travis CI

cache:
  apt: true # only works with Pro version

# Install the miss_hit linter
before_install:
  - pip3 install miss_hit

# Lists all the tasks we will do 
jobs:
  include:
    - name: "miss_hit: checking code quality"
      script: mh_metric . --ci
    - name: "miss_hit: checking code style"
      script: mh_style .
Remi-Gau commented 4 years ago

And this would be the template for a github action

name: miss_hit

on:
  push:
    branches:
      - master
  pull_request:
    branches: '*'

jobs:
  build:

    runs-on: ubuntu-latest

    steps:

    - uses: actions/checkout@v2
      with:
        submodules: true
        fetch-depth: 1

    - name: Set up Python 3.6
      uses: actions/setup-python@v2
      with:
        python-version: 3.6

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip setuptools
        pip3 install install miss_hit

    - name: Miss_hit code quality
      run: |
        mh_metric . --ci

    - name: Miss_hit code style
      run: |
        mh_style .
Remi-Gau commented 4 years ago

Let me know if you want me to open in the a PR to put that in the doc. :-)

florianschanda commented 4 years ago

Nah, I'll add it directly.

Now that I see it, using installation from pypi is the obvious way to get to the latest stable release :)

florianschanda commented 4 years ago

Done; see: https://florianschanda.github.io/miss_hit/configuration.html#cicd

wbekerom commented 3 years ago

Hi @florianschanda, first of all, awesome project! We've been looking for some automated MATLAB style checking (and fixing) for some time now. This project works like charm, your effort is much appreciated 👍

I wrote a hook for the pre-commit framework based on miss_hit. Would you be open for a PR to include it here?

If so, the only obstacle would be that pre-commit Python hooks require a repo to be installable via pip install . i.e. it requires a setup.py in the root. Not sure if this is a change you're willing to make though ... let me know what you think.

florianschanda commented 3 years ago

Hi @wbekerom thank you for the kind words!

Yes, by all means open a PR; we can always discuss the details in it.

As to having setup.py in the root of MISS_HIT; this is not so easy. Have a look in the makefile under "package", you can see there is careful swapping in-and-out of setup_gpl.py and setup_agpl.py.

wbekerom commented 3 years ago

Yeah, I already noticed the swapping the the makefile. Will have a go at it, a PR is coming your way.

florianschanda commented 3 years ago

Closing, since the pre-commit stuff seems to work pretty well. A naked hook might also be good to have, will add if there is demand.