WIP: feat(nix): Begin adding actions #848

Draft
thubrecht wants to merge 4 commits from nix-actions into master
19 changed files with 307 additions and 152 deletions

10
.flake8 Normal file
View file

@ -0,0 +1,10 @@
[flake8]
exclude = migrations
max-line-length = 88
ignore =
# whitespace before ':' (not PEP8-compliant for slicing)
E203,
# lambda expression
E731,
# line break before binary operator (not PEP8-compliant)
W503

View file

@ -0,0 +1,15 @@
jobs:
migrations_check:
runs-on: nix
steps:
- uses: actions/checkout@v3
with: {}
- name: Setup dev secrets...
run: cp gestioasso/settings/secret_example.py gestioasso/settings/secret.py
- name: Check that all migrations exist
run: nix-shell --run "python manage.py makemigrations --dry-run --check bda
bds clubs cofcms events gestioncof kfet kfetauth kfetcms open petitscours
shared"
name: Check for missing migrations
'on':
- pull_request

View file

@ -0,0 +1,15 @@
jobs:
pre-commit:
runs-on: nix
steps:
- uses: actions/checkout@v3
- name: Check stage pre-commit
run: nix-shell -A pre-commit --run 'pre-commit run --all-files --hook-stage
pre-commit --show-diff-on-failure'
- name: Check stage pre-push
run: nix-shell -A pre-commit --run 'pre-commit run --all-files --hook-stage
pre-push --show-diff-on-failure'
name: Run pre-commit on all files
'on':
- push
- pull_request

1
.gitignore vendored
View file

@ -21,3 +21,4 @@ media/
# VSCode # VSCode
.vscode/ .vscode/
.direnv .direnv
.pre-commit-config.yaml

1
.pre-commit-config.yaml Symbolic link
View file

@ -0,0 +1 @@
/nix/store/s6xfmmc25y8kgg0xh35qlg7sc0h7rllb-pre-commit-config.json

View file

@ -1,4 +1,5 @@
from django.apps import AppConfig, apps as global_apps from django.apps import AppConfig
from django.apps import apps as global_apps
from django.db.models import Q from django.db.models import Q
from django.db.models.signals import post_migrate from django.db.models.signals import post_migrate

130
default.nix Normal file
View file

@ -0,0 +1,130 @@
{
sources ? import ./npins,
pkgs ? import sources.nixpkgs { },
}:
let
###
# Pkgs configuration
inherit (pkgs.lib)
genAttrs
mapAttrs
mapAttrs'
nameValuePair
removeSuffix
;
nix-pkgs = import sources.nix-pkgs { inherit pkgs; };
kat-pkgs = import sources.kat-pkgs { inherit pkgs; };
python3 = pkgs.python3.override {
packageOverrides = final: prev: {
inherit (nix-pkgs)
authens
django-bootstrap-form
django-cas-ng
loadcredential
;
inherit (kat-pkgs.python3Packages)
django-djconfig
django-hCaptcha
wagtail-modeltranslation
wagtailmenus
;
};
};
###
# CI configuration
nix-actions = import sources.nix-actions { inherit pkgs; };
workflows = nix-actions.install {
src = ./.;
buildCheck = false;
workflows = mapAttrs' (
name: _:
nameValuePair (removeSuffix ".nix" name) (
import ./workflows/${name} {
inherit nix-actions;
inherit (pkgs) lib;
}
)
) (builtins.readDir ./workflows);
};
git-hooks = (import sources.git-hooks).run {
src = ./.;
hooks = genAttrs [ "black" "isort" "commitizen" ] (_: {
enable = true;
});
};
in
{
devShell = pkgs.mkShell {
shellHook = ''
${git-hooks.shellHook}
${workflows.shellHook}
if [ ! -d .static ]; then
mkdir .static
fi
'';
env = {
CREDENTIALS_DIRECTORY = builtins.toString ./.credentials;
DJANGO_SETTINGS_MODULE = "gestioasso.settings.local";
GESTIOCOF_DEBUG = true;
GESTIOCOF_STATIC_ROOT = builtins.toString ./.static;
GESTIOBDS_DEBUG = true;
GESTIOBDS_STATIC_ROOT = builtins.toString ./.static;
};
packages = [
(python3.withPackages (
ps: with ps; [
django
pillow
authens
channels
configparser
django-autocomplete-light
django-bootstrap-form
django-cas-ng
django-cors-headers
django-djconfig
django-hCaptcha
django-js-reverse
django-widget-tweaks
icalendar
loadcredential
python-dateutil
statistics
wagtail-modeltranslation
wagtail
wagtailmenus
django-debug-toolbar
ipython
black
flake8
isort
]
))
pkgs.npins
] ++ git-hooks.enabledPackages;
passthru = mapAttrs (name: value: pkgs.mkShell (value // { inherit name; })) {
pre-commit.shellHook = git-hooks.shellHook;
};
};
preferLocalBuild = true;
}

View file

@ -4,6 +4,7 @@ Active toutes les applications (de GestioCOF et de GestioBDS).
Surcharge les settings définis dans common.py Surcharge les settings définis dans common.py
""" """
import os import os
from . import bds_prod from . import bds_prod

View file

@ -6,7 +6,6 @@ Charge des données de test dans la BDD
- Petits cours - Petits cours
""" """
import os import os
import random import random

View file

@ -1,8 +1,6 @@
from gestioncof.models import Event from gestioncof.models import Event
from shared.tests.mixins import ( from shared.tests.mixins import CSVResponseMixin
CSVResponseMixin, from shared.tests.mixins import ViewTestCaseMixin as BaseViewTestCaseMixin
ViewTestCaseMixin as BaseViewTestCaseMixin,
)
from .utils import create_member, create_staff, create_user from .utils import create_member, create_staff, create_user

View file

@ -8,11 +8,9 @@ from django.contrib import messages
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.auth.views import ( from django.contrib.auth.views import LoginView as DjangoLoginView
LoginView as DjangoLoginView, from django.contrib.auth.views import LogoutView as DjangoLogoutView
LogoutView as DjangoLogoutView, from django.contrib.auth.views import redirect_to_login
redirect_to_login,
)
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.core.mail import send_mail from django.core.mail import send_mail
from django.http import Http404, HttpResponse, HttpResponseForbidden from django.http import Http404, HttpResponse, HttpResponseForbidden
@ -23,7 +21,8 @@ from django.utils import timezone
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views.generic import FormView, TemplateView from django.views.generic import FormView, TemplateView
from django_cas_ng.views import LogoutView as CasLogoutView from django_cas_ng.views import LogoutView as CasLogoutView
from icalendar import Calendar, Event as Vevent from icalendar import Calendar
from icalendar import Event as Vevent
from bda.models import Spectacle, Tirage from bda.models import Spectacle, Tirage
from gestioncof.autocomplete import cof_autocomplete from gestioncof.autocomplete import cof_autocomplete

View file

@ -1,4 +1,5 @@
from datetime import datetime, timedelta, timezone as tz from datetime import datetime, timedelta
from datetime import timezone as tz
from decimal import Decimal from decimal import Decimal
from unittest import mock from unittest import mock

View file

@ -105,12 +105,8 @@ from kfet.statistic import SCALE_DICT, DayScale, MonthScale, WeekScale, scale_ur
from shared.views import AutocompleteView from shared.views import AutocompleteView
from .auth import KFET_GENERIC_TRIGRAMME from .auth import KFET_GENERIC_TRIGRAMME
from .auth.views import ( # noqa from .auth.views import AccountGroupUpdate # noqa
AccountGroupCreate, from .auth.views import AccountGroupCreate, account_group, login_generic
AccountGroupUpdate,
account_group,
login_generic,
)
def put_cleaned_data_in_dict(dict, form): def put_cleaned_data_in_dict(dict, form):

View file

@ -1,5 +1,17 @@
{ {
"pins": { "pins": {
"git-hooks": {
"type": "Git",
"repository": {
"type": "GitHub",
"owner": "cachix",
"repo": "git-hooks.nix"
},
"branch": "master",
"revision": "a5a961387e75ae44cc20f0a57ae463da5e959656",
"url": "https://github.com/cachix/git-hooks.nix/archive/a5a961387e75ae44cc20f0a57ae463da5e959656.tar.gz",
"hash": "0pfpiz3z2l5l3h9ml1z75zn11jbq2qhb1ph8jn277ds6x8dl0mnw"
},
"kat-pkgs": { "kat-pkgs": {
"type": "Git", "type": "Git",
"repository": { "repository": {
@ -11,6 +23,20 @@
"url": null, "url": null,
"hash": "0204f91vxa5qglihpfkf3j5w3k7v98wry861xf2skl024faf9idf" "hash": "0204f91vxa5qglihpfkf3j5w3k7v98wry861xf2skl024faf9idf"
}, },
"nix-actions": {
"type": "GitRelease",
"repository": {
"type": "Git",
"url": "https://git.dgnum.eu/DGNum/nix-actions"
},
"pre_releases": false,
"version_upper_bound": null,
"release_prefix": null,
"version": "v0.3.0",
"revision": "15a5f4cd9909cad78c8be852d176def42d5ab3cd",
"url": null,
"hash": "16gssfs2qxy1nqnfqpbn076i79zna295jzix897346ic3gy11610"
},
"nix-pkgs": { "nix-pkgs": {
"type": "Git", "type": "Git",
"repository": { "repository": {
@ -18,9 +44,9 @@
"url": "https://git.hubrecht.ovh/hubrecht/nix-pkgs" "url": "https://git.hubrecht.ovh/hubrecht/nix-pkgs"
}, },
"branch": "main", "branch": "main",
"revision": "ac4ff5a34789ae3398aff9501735b67b6a5a285a", "revision": "a9133ed1b96f1e01a9fc1a12dc2602c41c5f70cd",
"url": null, "url": null,
"hash": "16n37f74p6h30hhid98vab9w5b08xqj4qcshz2kc1jh67z5n49p6" "hash": "17wah3x9fflw1699c5jvsi06i2rbb33bxkglwyjhjnnjz7zag871"
}, },
"nixpkgs": { "nixpkgs": {
"type": "Channel", "type": "Channel",

View file

@ -1,9 +1,24 @@
[tool.black] [tool.isort]
# Automatically ignore files in .gitignore (opened at this time): profile = "black"
# https://github.com/ambv/black/issues/475
exclude = ''' [tool.coverage.run]
/( source = [
\.pyc "bda",
| venv "bds",
)/ "clubs",
''' "events",
"gestioasso",
"gestioncof",
"kfet",
"petitscours",
"shared",
]
omit = [
"*migrations*",
"*test*.py",
]
branch = true
[tool.coverage.report]
precision = 2
show_missing = true

View file

@ -1,41 +0,0 @@
[coverage:run]
source =
bda
bds
clubs
events
gestioasso
gestioncof
kfet
petitscours
shared
omit =
*migrations*
*test*.py
branch = true
[coverage:report]
precision = 2
show_missing = true
[flake8]
exclude = migrations
max-line-length = 88
ignore =
# whitespace before ':' (not PEP8-compliant for slicing)
E203,
# lambda expression
E731,
# line break before binary operator (not PEP8-compliant)
W503
[isort]
# For black compat: https://github.com/ambv/black#how-black-wraps-lines
combine_as_imports = true
default_section = THIRDPARTY
force_grid_wrap = 0
include_trailing_comma = true
known_first_party = bda,bds,clubs,cof,events,gestioncof,kfet,petitscours,shared
line_length = 88
multi_line_output = 3
sections = FUTURE,STDLIB,THIRDPARTY,FIRSTPARTY,LOCALFOLDER

View file

@ -1,81 +1 @@
{ (import ./. { }).devShell
sources ? import ./npins,
pkgs ? import sources.nixpkgs { },
}:
let
nix-pkgs = import sources.nix-pkgs { inherit pkgs; };
kat-pkgs = import sources.kat-pkgs { inherit pkgs; };
python3 = pkgs.python3.override {
packageOverrides = final: prev: {
inherit (nix-pkgs)
authens
django-bootstrap-form
django-cas-ng
loadcredential
;
inherit (kat-pkgs.python3Packages)
django-djconfig
django-hCaptcha
wagtail-modeltranslation
wagtailmenus
;
};
};
in
pkgs.mkShell {
shellHook = ''
if [ ! -d .static ]; then
mkdir .static
fi
'';
env = {
CREDENTIALS_DIRECTORY = builtins.toString ./.credentials;
DJANGO_SETTINGS_MODULE = "gestioasso.settings.local";
GESTIOCOF_DEBUG = true;
GESTIOCOF_STATIC_ROOT = builtins.toString ./.static;
GESTIOBDS_DEBUG = true;
GESTIOBDS_STATIC_ROOT = builtins.toString ./.static;
};
packages = [
(python3.withPackages (
ps: with ps; [
django
pillow
authens
channels
configparser
django-autocomplete-light
django-bootstrap-form
django-cas-ng
django-cors-headers
django-djconfig
django-hCaptcha
django-js-reverse
django-widget-tweaks
icalendar
loadcredential
python-dateutil
statistics
wagtail-modeltranslation
wagtail
wagtailmenus
django-debug-toolbar
ipython
black
flake8
isort
]
))
pkgs.npins
];
allowSubstitutes = false;
}

View file

@ -0,0 +1,39 @@
{ nix-actions, ... }:
let
apps = [
"bda"
"bds"
"clubs"
"cofcms"
"events"
"gestioncof"
"kfet"
"kfetauth"
"kfetcms"
"open"
"petitscours"
"shared"
];
in
{
name = "Check for missing migrations";
on = [ "pull_request" ];
jobs.migrations_check = {
runs-on = "nix";
steps = [
(nix-actions.steps.checkout { })
{
name = "Setup dev secrets...";
run = # bash
"cp gestioasso/settings/secret_example.py gestioasso/settings/secret.py";
}
{
name = "Check that all migrations exist";
run = ''nix-shell --run "python manage.py makemigrations --dry-run --check ${builtins.concatStringsSep " " apps}"'';
}
];
};
}

29
workflows/pre-commit.nix Normal file
View file

@ -0,0 +1,29 @@
# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
#
# SPDX-License-Identifier: EUPL-1.2
{ ... }:
{
name = "Run pre-commit on all files";
on = [
"push"
"pull_request"
];
jobs.pre-commit = {
runs-on = "nix";
steps =
[ { uses = "actions/checkout@v3"; } ]
++ (builtins.map
(stage: {
name = "Check stage ${stage}";
run = "nix-shell -A pre-commit --run 'pre-commit run --all-files --hook-stage ${stage} --show-diff-on-failure'";
})
[
"pre-commit"
"pre-push"
]
);
};
}