Skip to content

Commit

Permalink
add linting and tests workflow + update precommit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
arbakker committed Dec 8, 2023
1 parent 8619351 commit eb8253d
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 150 deletions.
12 changes: 6 additions & 6 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ then
exit 0
fi

PY_FILES=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g' | { grep -E "\.py$" || test $? = 1; })
YAML_FILES=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g' | { grep -E "\.ya?ml$" || test $? = 1; })
PY_FILES=$(git ls-files --cached --modified --other --exclude-standard | { grep -E "\.py$" || test $? = 1; })
YAML_FILES=$(git ls-files --cached --modified --other --exclude-standard | { grep -E "\.ya?ml$" || test $? = 1; })

if [ -n "$PY_FILES" ]; then
command_available "mypy"
Expand All @@ -54,19 +54,19 @@ if [ -n "$PY_FILES" ]; then

command_available "black"
print_message "running Black formatting" 1 "" true
echo "$PY_FILES" | xargs black --stdin-filename "{}"
black .

command_available "ruff"
print_message "running ruff linting" 1 "" true
echo "$PY_FILES" | xargs ruff --fix
ruff --fix .

echo "$PY_FILES" | xargs git add
echo "$PY_FILES" | xargs git add
fi

if [ -n "$YAML_FILES" ]; then
command_available "prettier"
print_message "running prettier yaml formatting" 1 "" true
echo "$YAML_FILES" | xargs prettier --ignore-unknown --stdin-filepath
echo "$YAML_FILES" | xargs prettier --ignore-unknown --stdin-filepath --write > /dev/null
echo "$YAML_FILES" | xargs git add
fi

Expand Down
File renamed without changes.
80 changes: 80 additions & 0 deletions .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [main]
pull_request:
branches: ["main"]
schedule:
- cron: "28 8 * * 3"

jobs:
analyze:
name: Analyze
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners
# Consider using larger runners for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: ["python"]
# CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ]
# Use only 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality

# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
81 changes: 0 additions & 81 deletions .github/workflows/codeql.yml

This file was deleted.

46 changes: 46 additions & 0 deletions .github/workflows/linting-and-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Run linting and unit tests

on:
pull_request:

jobs:
linting_and_tests:
name: Linting and Tests | python=${{ matrix.python-version }}

runs-on: ubuntu-latest

strategy:
matrix:
python-version: ["3.11"]

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # to fetch all history for all branches and tags; required because we derive app version from latest tag
fetch-tags: true
- name: Setup conda
uses: s-weigand/setup-conda@v1
with:
update-conda: true
python-version: ${{ matrix.python-version }}
conda-channels: anaconda, conda-forge

- name: Conda install dependencies
run: conda install -c conda-forge pyproj==3.6.0

- name: Install dependencies
run: |
python${{ matrix.python-version }} -m pip install --upgrade pip
python${{ matrix.python-version }} -m pip install --force-reinstall -e ".[dev]"
- name: Lint with black
run: |
python${{ matrix.python-version }} -m black --check .
- name: Lint with ruff
run: |
python${{ matrix.python-version }} -m ruff -v .
- name: Test with pytest and generate coverage report
run: |
python${{ matrix.python-version }} -m coverage run --source=src/coordinate_transformation_api -m pytest -v tests
2 changes: 1 addition & 1 deletion .markdownlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ MD013: false
MD004:
style: "sublist"
MD007:
indent: 4
indent: 4
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ classifiers = [
]
readme = { file = "./README.md", content-type = "text/markdown" }
dependencies = [
"fastapi == 0.104.1",
"fastapi[all] == 0.104.1",
"uvicorn == 0.24.0.post1",
"pyyaml == 6.0.1",
"geojson_pydantic == 1.0.1",
Expand All @@ -29,6 +29,8 @@ dev = [
"mypy == 1.7.1",
"pytest == 7.4.3",
"ruff == 0.1.7",
"types-ujson == 5.8.0.1",
"types-PyYAML == 6.0.12.12",
]

[build-system]
Expand Down Expand Up @@ -119,6 +121,7 @@ exclude = [
"dist",
"node_modules",
"venv",
"build"
]

line-length = 120
Expand Down
Loading

0 comments on commit eb8253d

Please sign in to comment.