Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linters for Docker, Go, Python, and Shell #57

Merged
merged 17 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
386ddd9
Add python linting and pre-commit configuration.
Jeffrey-Vervoort-KNMI Sep 22, 2023
20b10ad
To use environment variable change to install with pip.
Jeffrey-Vervoort-KNMI Sep 22, 2023
757fbf6
Update the readme with pre-commit information.
Jeffrey-Vervoort-KNMI Oct 20, 2023
1bbdd82
Run the pre-commit hook for the Python files.
Jeffrey-Vervoort-KNMI Oct 20, 2023
41dc76c
Run the pre-commit hook for the Docker files.
Jeffrey-Vervoort-KNMI Oct 20, 2023
85f9081
Add Docker linting.
Jeffrey-Vervoort-KNMI Sep 22, 2023
a17e00e
Set permissions to read in the workflow.
Jeffrey-Vervoort-KNMI Sep 27, 2023
7b3ca07
Add GoLang linting.
Jeffrey-Vervoort-KNMI Oct 20, 2023
1a83420
Apply go format.
Jeffrey-Vervoort-KNMI Oct 20, 2023
95679b3
Update readme with better instructions on the pre-commit hook.
Jeffrey-Vervoort-KNMI Oct 23, 2023
6078f50
Add Go to the local pre-commit hook configuration.
Jeffrey-Vervoort-KNMI Oct 23, 2023
3291145
Add ShellCheck to the pre-commit hook and git actions.
Jeffrey-Vervoort-KNMI Oct 23, 2023
823d9a9
Disable go vet as it requires the protoc files to be generated. This …
Jeffrey-Vervoort-KNMI Oct 23, 2023
36887a2
Increase line length to 120.
Jeffrey-Vervoort-KNMI Oct 24, 2023
76b56c2
Apply pre-commit hook with line-length of 120.
Jeffrey-Vervoort-KNMI Oct 24, 2023
dd1449f
Replace git actions with pre-commit hook. Did not use the pre-commit …
Jeffrey-Vervoort-KNMI Oct 24, 2023
83bb212
Add a number to comments so that they are not removed by the pre-comm…
Jeffrey-Vervoort-KNMI Oct 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,29 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+'

permissions:
contents: read

jobs:
pre-commit-hook:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- name: Install pre-commit
run: python -m pip install pre-commit
shell: bash
- name: Show pre-commit requirements
run: python -m pip freeze --local
shell: bash
- uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: Run pre-commit for all files
run: pre-commit run --config './.pre-commit-config.yaml' --all-files --color=always --show-diff-on-failure
shell: bash

test:
runs-on: ubuntu-latest
steps:
Expand Down
73 changes: 73 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
repos:
- repo: local
hooks:
# go-fmt ~ Enforces Go standard formatting (whitespace, indentation, et cetera)
- id: go-fmt
name: go-fmt
description: "Enforces Go standard formatting (whitespace, indentation, et cetera)."
entry: ./ci/go/go-fmt.sh
language: script
pass_filenames: false
# # go-vet ~ Finds subtle issues in Go where your code may not work as intended
# - id: go-vet
# name: go-vet
# description: "Finds subtle issues in Go where your code may not work as intended."
# entry: ./ci/go/go-vet.sh
# language: script
# pass_filenames: false

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
# Formatting
- id: end-of-file-fixer # Makes sure files end in a newline and only a newline.
- id: pretty-format-json
args: ["--autofix", "--indent=4", "--no-ensure-ascii", "--no-sort-keys"] # Formats and sorts your JSON files.
- id: trailing-whitespace # Trims trailing whitespace.
# Checks
- id: check-json # Attempts to load all json files to verify syntax.
- id: check-merge-conflict # Check for files that contain merge conflict strings.
- id: check-shebang-scripts-are-executable # Checks that scripts with shebangs are executable.
- id: check-yaml
# only checks syntax not load the yaml:
# https://stackoverflow.com/questions/59413979/how-exclude-ref-tag-from-check-yaml-git-hook
args: ["--unsafe"] # Parse the yaml files for syntax.

# reorder-python-imports ~ sort python imports
- repo: https://github.com/asottile/reorder_python_imports
rev: v3.12.0
hooks:
- id: reorder-python-imports

# black ~ Formats Python code
- repo: https://github.com/psf/black
rev: 23.10.0
hooks:
- id: black
args: ["--line-length=120"]

# flake8 ~ Enforces the Python PEP8 style guide
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
args:
[
"--ignore=W503",
"--max-line-length=120",
]

# hadolint ~ Docker linter
- repo: https://github.com/hadolint/hadolint
rev: v2.12.0
hooks:
- id: hadolint-docker
args: [
"--ignore=DL3008", # Pin versions in apt get install.
]

# ShellCheck ~ Gives warnings and suggestions for bash/sh shell scripts
- repo: https://github.com/koalaman/shellcheck-precommit
rev: v0.9.0
hooks:
- id: shellcheck
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# e-soh-datastore-poc
E-SOH datastore PoCs


## Pre-commit
### Setup
1. Go to the root of the repository.
2. Install the python pre-commit package with `pip install pre-commit`.
lukas-phaf marked this conversation as resolved.
Show resolved Hide resolved
3. Reinitialize there repository with `git init`.
4. Install the hooks defined in `.pre-commit-config.yaml` with `pre-commit install`.

### Useful Commands
- To update the pre-commit hooks in `.pre-commit-config.yaml` run: `pre-commit autoupdate`.
- To run the pre-commit for every file in the repository run `pre-commit run --config './.pre-commit-config.yaml' --all-files`.
- To commit without the pre-commit hook `git commit -m "Some message" --no-verify`
2 changes: 1 addition & 1 deletion api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ ENV PROJECT_DATASTORE_PATH="datastore"
ENV PROJECT_PYTHON_PATH="api"
ENV DOCKER_PATH="/app"

# hadolint ignore=DL3013
RUN apt-get update \
&& apt-get -y upgrade \
&& apt-get install -y --no-install-recommends git \
Expand All @@ -19,6 +18,7 @@ RUN apt-get update \
COPY "${PROJECT_DATASTORE_PATH}/protobuf/datastore.proto" "/protobuf/datastore.proto"
COPY "${PROJECT_PYTHON_PATH}/requirements.txt" "${DOCKER_PATH}/requirements.txt"

# hadolint ignore=DL3013
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir --upgrade -r "${DOCKER_PATH}/requirements.txt"

Expand Down
26 changes: 21 additions & 5 deletions api/locustfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import random

from locust import HttpUser, between, task
from locust import HttpUser
from locust import task


parameters = ["ff", "dd", "rh", "pp", "tn"]
stations = ["06203", "06204", "06205", "06207", "06208", "06211", "06214", "06215", "06235", "06239", "06242", "06251", "06260", "06269", "06270", "06275", "06279", "06280", "06290", "06310", "06317", "06319", "06323", "06330", "06340", "06344", "06348", "06350", "06356", "06370", "06375", "06380", "78871", "78873"]

# fmt: off
stations = [
"06203", "06204", "06205", "06207", "06208", "06211", "06214", "06215", "06235", "06239",
"06242", "06251", "06260", "06269", "06270", "06275", "06279", "06280", "06290", "06310",
"06317", "06319", "06323", "06330", "06340", "06344", "06348", "06350", "06356", "06370",
"06375", "06380", "78871", "78873",
]
# fmt: on
headers = {"Accept-Encoding": "br"}


Expand All @@ -14,8 +21,17 @@ class WebsiteUser(HttpUser):
def get_data_single_station_single_parameter(self):
parameter = random.choice(parameters)
station_id = random.choice(stations)
self.client.get(f"/collections/observations/locations/{station_id}?parameter-name={parameter}", name=f"single station {parameter}", headers=headers)
self.client.get(
f"/collections/observations/locations/{station_id}?parameter-name={parameter}",
name=f"single station {parameter}",
headers=headers,
)

@task
def get_data_bbox_three_parameters(self):
self.client.get(f"/collections/observations/area?parameter-name=dd,ff,rh&coords=POLYGON((5.0 52.0,6.0 52.0,6.0 52.1,5.0 52.1,5.0 52.0))", name=f"bbox", headers=headers)
self.client.get(
"/collections/observations/area?parameter-name=dd,ff,rh&"
"coords=POLYGON((5.0 52.0,6.0 52.0,6.0 52.1,5.0 52.1,5.0 52.0))",
name="bbox",
headers=headers,
)
Loading