Skip to content

Commit

Permalink
Merge pull request #404 from hypsug0/github_actions
Browse files Browse the repository at this point in the history
Some new GitHub actions
  • Loading branch information
lpofredc authored Mar 28, 2024
2 parents 883b211 + dd53e77 commit 3bedaf1
Show file tree
Hide file tree
Showing 104 changed files with 989 additions and 660 deletions.
2 changes: 1 addition & 1 deletion .angulardoc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"repoId": "2b14cce7-db7a-476a-a8b9-f41927e3728b",
"lastSync": 0
}
}
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ exclude =
build,
dist,
migrations
max-complexity = 10
max-complexity = 10
80 changes: 80 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: "📚 Documentation"

on:
push:
branches:
- master
paths:
- ".github/workflows/documentation.yml"
- "docs/*/**"
tags:
- "*"

pull_request:
branches:
- master
paths:
- ".github/workflows/documentation.yml"
- docs/**/*

workflow_dispatch:

# Allow one concurrent deployment per branch/pr
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
PYTHON_VERSION: 3.11

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Get source code
uses: actions/checkout@v4

- name: Run image
uses: abatilo/actions-poetry@v3
#------------------------------------
# ----- Install dependencies -----
#------------------------------------
- name: Install dependencies
run: |
cd backend
poetry install --only=docs
- name: Build doc using Sphinx
run: |
cd backend
poetry run sphinx-build -b html -d ../docs/_build/cache -j auto ../docs ../docs/_build/html
- name: Save build doc as artifact
uses: actions/upload-artifact@v4
with:
name: documentation
path: docs/_build/html/*
if-no-files-found: error
retention-days: 30

- name: Setup Pages
uses: actions/configure-pages@v4
if: github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main')

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
if: github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main')
with:
path: docs/_build/html/

- name: Deploy to GitHub Pages
id: deployment
if: github.event_name == 'push' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main')
uses: actions/deploy-pages@v4
57 changes: 57 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: "✅ Linter"

on:
push:
branches: [master, dev]
paths:
- "backend/**/*.py"
- "frontend/*"

pull_request:
branches: [master, dev]
paths:
- "backend/**/*.py"
- "frontend/*"

env:
BACKEND_FOLDER: "backend"
FRONTEND_FOLDER: "frontend"
PYTHON_VERSION: 3.9

jobs:
lint-py:
name: Python 🐍

runs-on: ubuntu-latest

steps:
- name: Get source code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install project requirements
run: |
python -m pip install -U pip setuptools wheel
python -m pip install -U flake8
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 ${{ env.BACKEND_FOLDER }} --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings.
flake8 ${{ env.BACKEND_FOLDER }} --count --exit-zero --statistics
lint-node:
name: NodeJS 🐍
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: "${{ env.FRONTEND_FOLDER }}/.nvmrc"
- run: cd ${{ env.FRONTEND_FOLDER }} && npm ci
- run: cd ${{ env.FRONTEND_FOLDER }} && npm run lint
46 changes: 46 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
exclude: ".venv|__pycache__|tests/dev/|tests/fixtures/"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-added-large-files
args: ["--maxkb=500"]
- id: check-case-conflict
- id: check-xml
- id: check-yaml
- id: detect-private-key
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: fix-encoding-pragma
args: [--remove]
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]

- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
- id: black

# - repo: https://github.com/pycqa/isort
# rev: 5.13.2
# hooks:
# - id: isort
# args: ["--profile", "black", "--filter-files"]

- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
files: ^pyqgis_resource_browser/.*\.py$
additional_dependencies: ["flake8-qgis<2"]
args:
[
"--config=setup.cfg",
"--select=E9,F63,F7,F82,QGS101,QGS102,QGS103,QGS104,QGS106",
]

ci:
autoupdate_schedule: quarterly
skip: []
submodules: false
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ENV LANG fr_FR.utf8
ENV TERM xterm

RUN adduser --uid 1001 --gecos "" --disabled-password appuser
RUN usermod -aG sudo appuser
RUN usermod -aG sudo appuser
RUN echo "appuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

COPY . /home/appuser/citizen
Expand Down
2 changes: 1 addition & 1 deletion backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tests
.venv
__pycache__
__pycache__
4 changes: 2 additions & 2 deletions backend/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ WORKDIR /app

RUN pip install --upgrade pip \
&& pip install poetry
CMD poetry install; poetry run python3 wsgi.py

CMD poetry install; poetry run python3 wsgi.py
3 changes: 1 addition & 2 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Moteur de la plateforme
# Moteur de la plateforme

Déployé avec le framework python Flask

1 change: 0 additions & 1 deletion backend/gncitizen/core/commons/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/python3
# -*- coding:utf-8 -*-
from flask import current_app, flash
from flask_admin.contrib.sqla.view import ModelView
from flask_admin.form.upload import FileUploadField
Expand Down
16 changes: 11 additions & 5 deletions backend/gncitizen/core/commons/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""Commons models"""

import json
Expand All @@ -12,14 +11,15 @@
from geoalchemy2.functions import ST_GeomFromGeoJSON, ST_GeomFromKML, ST_SetSRID
from geoalchemy2.shape import to_shape
from geojson import Feature
from gncitizen.utils.env import MEDIA_DIR, db
from sqlalchemy import ForeignKey
from sqlalchemy.dialects.postgresql import JSONB, UUID
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy.orm import relationship
from sqlalchemy.sql import expression
from utils_flask_sqla_geo.serializers import geoserializable, serializable

from gncitizen.utils.env import MEDIA_DIR, db


class TimestampMixinModel:
"""Structure commune de suivi des modifications d'une table"""
Expand Down Expand Up @@ -163,7 +163,9 @@ class ProgramsModel(TimestampMixinModel, db.Model):
unique_id_program = db.Column(
UUID(as_uuid=True), default=uuid.uuid4, unique=True, nullable=False
)
id_project = db.Column(db.Integer, db.ForeignKey(ProjectModel.id_project), nullable=False)
id_project = db.Column(
db.Integer, db.ForeignKey(ProjectModel.id_project), nullable=False
)
title = db.Column(db.String(50), nullable=False)
short_desc = db.Column(db.String(200), nullable=False)
long_desc = db.Column(db.Text(), nullable=False)
Expand All @@ -184,8 +186,12 @@ class ProgramsModel(TimestampMixinModel, db.Model):
is_active = db.Column(
db.Boolean(), server_default=expression.true(), default=True, nullable=False
)
id_geom = db.Column(db.Integer, db.ForeignKey(GeometryModel.id_geom), nullable=False)
id_form = db.Column(db.Integer, db.ForeignKey(CustomFormModel.id_form), nullable=True)
id_geom = db.Column(
db.Integer, db.ForeignKey(GeometryModel.id_geom), nullable=False
)
id_form = db.Column(
db.Integer, db.ForeignKey(CustomFormModel.id_form), nullable=True
)
custom_form = relationship("CustomFormModel")
geometry = relationship("GeometryModel")
project = relationship("ProjectModel")
Expand Down
10 changes: 4 additions & 6 deletions backend/gncitizen/core/commons/routes.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from flask import Blueprint, current_app, request, send_from_directory
from flask_admin.contrib.fileadmin import FileAdmin
from flask_jwt_extended import jwt_required
from geojson import FeatureCollection
from sqlalchemy import and_, case, desc, distinct
from sqlalchemy.sql import func
from utils_flask_sqla.response import json_resp

from gncitizen.core.observations.models import ObservationMediaModel, ObservationModel
from gncitizen.core.sites.admin import SiteTypeView
from gncitizen.core.sites.models import (
Expand All @@ -23,6 +18,9 @@
from gncitizen.utils.helpers import get_filter_by_args, set_media_links
from gncitizen.utils.jwt import get_id_role_if_exists
from server import db
from sqlalchemy import and_, case, desc, distinct
from sqlalchemy.sql import func
from utils_flask_sqla.response import json_resp

from .admin import CustomFormView, GeometryView, ProgramView, ProjectView
from .models import (
Expand Down Expand Up @@ -425,7 +423,7 @@ def get_medias():
)
.filter(
(func.coalesce(ObservationModel.id_observation, MediaOnVisitModel.id_data_source))
!= None
is not None
)
.with_entities(
MediaModel.id_media,
Expand Down
13 changes: 9 additions & 4 deletions backend/gncitizen/core/observations/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-

from enum import Enum

Expand Down Expand Up @@ -155,7 +154,9 @@ def get_feature(self):
"""get obs data as geojson feature"""

result_dict = self.as_dict(True)
result_dict["observer"] = self.observer.as_simple_dict() if self.observer else None
result_dict["observer"] = (
self.observer.as_simple_dict() if self.observer else None
)
result_dict["validator"] = (
self.validator_ref.as_simple_dict() if self.validator_ref else None
)
Expand All @@ -169,7 +170,9 @@ def get_feature(self):
for k in result_dict:
if k in OBS_KEYS:
feature["properties"][k] = (
result_dict[k].name if isinstance(result_dict[k], Enum) else result_dict[k]
result_dict[k].name
if isinstance(result_dict[k], Enum)
else result_dict[k]
)
feature["properties"]["photos"] = [
{
Expand All @@ -187,7 +190,9 @@ def get_feature(self):
for taxon in taxon_repository
if taxon and taxon["cd_nom"] == feature["properties"]["cd_nom"]
)
feature["properties"]["taxref"] = {key: taxon["taxref"][key] for key in TAXREF_KEYS}
feature["properties"]["taxref"] = {
key: taxon["taxref"][key] for key in TAXREF_KEYS
}
feature["properties"]["medias"] = [
{key: media[key] for key in MEDIA_KEYS} for media in taxon["medias"]
]
Expand Down
Loading

0 comments on commit 3bedaf1

Please sign in to comment.