One of the things we need more of in my new day-job is automation, something we were good at in my previous role. To get started with GitHub Actions I have decided to start with linting in one of my repositories, Slurm Helpers, and this post documents the journey to getting that working.
Splitting the code up.
Currently the repository consists of a bunch of Python scripts, however it is porbable that Bash scripts will be added in the future and other languages too. To massively ease the burden of linting each language, I moved the scripts into language-specific directories:
mkdir python for file in bin/*; do mv $file python/$( basename $file ).py; done for file in python/*; do ln -s ../$file bin/$( basename $file .py ); done mkdir bash touch bash/.gitignore # To make git keep the directory until we have some bash scripts
I have added the bash directory, even though it is empty in order to setup the bash linter.
Doing the linting
Actions are enabled by default in GitHub, so we just need to create a configuration file and it will automatically start working.
The configuration needs to be in the directory
.github/workflows at the top of the repository, so start by creating that:
mkdir -p .github/workflows
Next, we need the configuration. I called it
name: Linting # When will the action run? on: # Push or pull request events but on for branch 'main' push: branches: [ main ] pull_request: branches: [ main ] # What will the workflow do? Jobs can run sequentially or in prallel jobs: # This workflow is a single job called 'lint' lint: # Type of runner to run on runs-on: ubuntu-latest steps: # Checks out the repository to $GITHUB_WORKSPACE - uses: actions/checkout@v2 # Shell linting - name: Shell linter uses: email@example.com with: # This is why we split bash scripts to their own directory path: "bash" # Python linting - name: Python linter uses: cclauss/GitHub-Actionfirstname.lastname@example.org with: # 'python' is the path to our python files args: "pylint python"
Making it pass
The final thing to do, is to fix the linting issues so that the linter no longer complains and change this:
Your code has been rated at -2.73/10
Your code has been rated at 10.00/10