Skip to content

Commit

Permalink
Merge pull request #20 from FrankMaverick/main
Browse files Browse the repository at this point in the history
Refactor and Documentation Enhancements
  • Loading branch information
Clou-dia authored Jul 15, 2024
2 parents d4798ab + e1db74e commit d19c50b
Show file tree
Hide file tree
Showing 20 changed files with 159 additions and 742 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests
pip install pytest
pip install requests pytest
- name: Run tests
run: pytest -s ./tests/
run: pytest -s ./tests/*.py
1 change: 0 additions & 1 deletion .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ jobs:
- name: Run a script
run: |-
pip install pre-commit
pip install rdflib
pre-commit autoupdate
pre-commit run --all-files --verbose
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Insert here the files/folders/extensions you would like to exclude from git tracking
*.py[co]
.*
!.github/
__pycache__
*.log

Expand Down
127 changes: 94 additions & 33 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,38 +1,99 @@
repos:
- repo: https://github.com/teamdigitale/dati-semantic-cookiecutter
rev: 931e0529c8839f6fa8c1ae315839ba7c3060c5f2
hooks:
- id: check-repo-structure
args: ["assets/controlled-vocabularies/", "assets/ontologies/", "assets/schemas/"]
- id: check-filename-format
args: ["assets/controlled-vocabularies/", "assets/ontologies/", "assets/schemas/"]
- id: check-filenames-match-uri
args: ["assets/controlled-vocabularies/", "assets/ontologies/", "assets/schemas/"]
- id: check-filenames-match-directories
args: ["assets/controlled-vocabularies/", "assets/ontologies/", "assets/schemas/"]
- id: check-supported-files
args: ["assets/controlled-vocabularies/", "assets/ontologies/", "assets/schemas/"]
- id: check-versioning-pattern
args: ["assets/controlled-vocabularies/", "assets/ontologies/", "assets/schemas/"]
#
# Run pre-commit hooks. You can run them without installing
# the hook with
#
# $ pre-commit run --all-files
#
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

#
# Python code checks
# If you don't have Python code to check,
# you can leave these hooks commented out
#
# repos:
# - repo: https://github.com/pre-commit/pre-commit-hooks
# rev: v4.6.0
# hooks:
# - id: trailing-whitespace
# - id: end-of-file-fixer
# - id: check-yaml
# args: [--allow-multiple-documents]
# - id: check-added-large-files
# args:
# - "--maxkb=4000"
# - repo: https://github.com/myint/autoflake
# rev: v2.3.1
# hooks:
# - id: autoflake
# args:
# - --in-place
# - --remove-unused-variables
# - --remove-all-unused-imports
# - repo: https://github.com/psf/black
# rev: 24.4.2
# hooks:
# - id: black
# - repo: https://github.com/pycqa/isort
# rev: 5.12.0
# hooks:
# - id: isort
# name: isort (python)
# args: ["--profile", "black"]
# - id: isort
# name: isort (cython)
# types: [cython]
# - id: isort
# name: isort (pyi)
# types: [pyi]
# - repo: https://github.com/PyCQA/flake8
# rev: 7.0.0
# hooks:
# - id: flake8
# - repo: https://github.com/PyCQA/bandit
# rev: 1.7.8
# hooks:
# - id: bandit
# name: bandit
# args: ["-c", ".bandit.yaml"]
# description: 'Bandit is a tool for finding common security issues in Python code'
# entry: bandit
# language: python
# language_version: python3
# types: [python]
# - repo: https://github.com/Lucas-C/pre-commit-hooks-safety
# rev: v1.3.3
# hooks:
# - id: python-safety-dependencies-check

#
# Semantic checks.
#
- repo: https://github.com/teamdigitale/json-semantic-playground
rev: 0b4ad4cc883a49878fdfd4539e694ae56b041e29
- repo: https://github.com/teamdigitale/dati-semantic-tools
rev: c2074cd9c90dc1751f5535459afc3da6d21ab60d
hooks:
- id: validate-csv
files: >-
^assets\/controlled-vocabularies/.*\.csv
- id: validate-oas-schema
files: >-
^assets\/schemas\/.*.oas3.yaml
- id: validate-turtle
files: >-
^assets\/ontologies\/[^\/]+\/latest\/.*\.ttl
- id: validate-turtle
files: >-
^assets\/controlled-vocabularies\/.*\.ttl
- id: validate-turtle
files: >-
^assets\/schemas\/.*\.ttl
- id: validate-repo-structure
files: ^assets\/.*
- id: validate-filename-format
files: ^assets\/.*
- id: validate-filename-match-uri
files: ^assets\/.*\.ttl
- id: validate-filename-match-directory
files: ^assets\/.*
- id: validate-directory-versioning-pattern
files: ^assets\/.*\.ttl
- id: validate-mandatory-files-presence
files: ^assets\/.*
- id: validate-utf8-file-encoding
files: ^assets\/.*
- id: validate-turtle
files: ^assets/.*\.ttl$
- id: validate-oas-schema
files: ^assets/.*\.schema.yaml
- id: validate-openapi-schema
files: ^assets/.*\.oas3.yaml
- id: validate-directory-versioning
files: ^assets/.*\.ttl
- id: validate-csv
files: ^assets/.*\.csv
74 changes: 0 additions & 74 deletions .pre-commit-hooks.yaml

This file was deleted.

46 changes: 33 additions & 13 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,52 @@ to the
[dedicated section in the Operational Manual of the Catalog](https://teamdigitale.github.io/dati-semantic-guida-ndc-docs/docs/manuale-operativo/istruzioni-su-come-predisporre-il-repository-in-cui-pubblicare-le-risorse-semantiche.html).


## Automated Checks and Testing
## Automatic Checks and Tests

Below are described the procedures for automated checks and testing implemented, essential for ensuring the quality and integrity of the repository content.
This section describes the automatic check and test procedures
used to ensure the quality and integrity of the repository content.

### Automated Checks (Pre-commit)
The controls may be disabled if they are not applicable to your specific use case. For example, if you have already implemented a solution for stable URIs, the check on the equality between the names of files and related folders and the check between the names of files and related resources in URIs can be commented out.

This repository implements automated checks using [pre-commit](https://pre-commit.com/). The specifications of the checks are defined in the file [`.pre-commit-config.yaml`](.pre-commit-config.yaml).
### Automatic Checks (Pre-commit)

These checks can be executed using GitHub Actions. The `validate.yaml` file in `.github/workflows` automatically enables pre-commit checks after each push or pull request (PR). Additionally, these checks can be manually activated at any time.
This repository uses [pre-commit](https://pre-commit.com/)
for automatic checks. The checks are specified
in the [`.pre-commit-config.yaml`](.pre-commit-config.yaml) file.

To enable pre-commit checks in another repository, simply copy the [`.pre-commit-config.yaml`](.pre-commit-config.yaml) file and the [`.github/workflows/validate.yaml`](.github/workflows/validate.yaml) file.
These checks can be run via GitHub Actions.
The `validate.yaml` file in `.github/workflows`
automatically enables pre-commit checks after each push or pull request (PR).
You can also run them manually at any time.

### URL Testing
To enable pre-commit checks in another repository,
copy the [`.pre-commit-config.yaml`](.pre-commit-config.yaml) file
and the [`.github/workflows/validate.yaml`](.github/workflows/validate.yaml) file.

In the `tests` directory, there is a script named `test_urls.py`, which verifies GitHub-related URLs present in the files of the `assets` subdirectories.
### URL Tests

This test can also be automated using GitHub Actions. The `test.yaml` file in `.github/workflows` automatically activates tests after each push or pull request. Similarly, these tests can be manually initiated at any time.
The `test_urls.py` script in the `tests` directory verifies
GitHub-related URLs in the `assets` subdirectory files.

To enable URL testing in another repository, simply copy the [`/tests/test_urls.py`](/tests/test_urls.py) file and the [`.github/workflows/test.yaml`](.github/workflows/test.yaml) file.
This test can also be automated using GitHub Actions.
The `test.yaml` file in `.github/workflows`
automatically runs the tests after each push or pull request.
You can also run them manually at any time.

### Local Checks and Testing
To enable URL tests in another repository,
copy the [`/tests/test_urls.py`](/tests/test_urls.py) file
and the [`.github/workflows/test.yaml`](.github/workflows/test.yaml) file.

Local checks and testing can be performed using Docker or simply Python. An integrated test environment to reproduce the CI pipeline is available through `docker-compose`, which executes a series of steps.
### Local Checks and Tests

Checks and tests can also be run locally
using Docker or Python. Use `docker-compose`
to replicate the CI pipeline:

```bash
docker-compose -f docker-compose-test.yml up
```

Note: If you wish to transfer this environment to another repository, it's important to note that the Docker environment requires the Dockerfiles present in the tests directory (such as Dockerfile.precommit and Dockerfile.pytest).
Note: To transfer this environment to another repository,
include the Dockerfiles in the `tests` directory
(such as `Dockerfile.precommit` and `Dockerfile.pytest`).
37 changes: 27 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Per la leggibilità:
- Tutti i file JSON sono serializzati come YAML;
- Tutti i file RDF sono serializzati come `text/turtle`;

### Asset semantici (schemi, vocabolari, ontologie)
### Risorse semantici (schemi, vocabolari, ontologie)

Tutte le risorse semantiche da raccogliere / pubblicare sono in `assets/`;
I file al di fuori di questa directory vengono ignorati dal catalogo
Expand Down Expand Up @@ -52,31 +52,48 @@ fai riferimento alla

## Controlli Automatici e Test

Di seguito vengono descritte le procedure di controllo automatico e di test implementate, utili per garantire la qualità e l'integrità del contenuto del repository
Questa sezione descrive le procedure di controllo automatico e test,
utili per garantire la qualità e l'integrità del contenuto del repository.

I controlli implementati possono essere disattivati se non applicabili al proprio caso d'uso. Ad esempio, se si è già implementata una propria soluzione per le URI stabili, il controllo sull'uguaglianza tra i nomi dei file e delle relative cartelle e tra il nome dei file e delle relative risorse negli URI non devono essere necessariamente superati, quindi possono essere commentati.

### Controlli Automatici (Pre-commit)

Questo repository implementa i controlli automatici utilizzando [pre-commit](https://pre-commit.com/). Le specifiche delle verifiche sono definite nel file [`.pre-commit-config.yaml`](.pre-commit-config.yaml).
Questo repository implementa i controlli automatici utilizzando [pre-commit](https://pre-commit.com/).
Le specifiche delle verifiche sono definite nel file [`.pre-commit-config.yaml`](.pre-commit-config.yaml).

È possibile eseguire tali verifiche mediante GitHub Actions. Il file `validate.yaml` in `.github/workflows` abilita automaticamente i controlli pre-commit dopo ogni push o pull request (PR). Inoltre, è possibile attivare manualmente tali controlli in qualsiasi momento.
È possibile eseguire tali verifiche mediante GitHub Actions.
Il file `validate.yaml` in `.github/workflows` abilita automaticamente
i controlli pre-commit dopo ogni push o pull request (PR).
Inoltre, è possibile eseguirli manualmente in qualsiasi momento.

Per abilitare i controlli pre-commit in un altro repository, è sufficiente copiare il file [`.pre-commit-config.yaml`](.pre-commit-config.yaml) e il file [`.github/workflows/validate.yaml`](.github/workflows/validate.yaml).
Per abilitare i controlli pre-commit in un altro repository,
copiare il file [`.pre-commit-config.yaml`](.pre-commit-config.yaml) e il file [`.github/workflows/validate.yaml`](.github/workflows/validate.yaml).

### Test URL

Nella directory `tests` è presente uno script denominato `test_urls.py`, che consente di verificare gli URL relativi a GitHub presenti nei file delle sottodirectory `assets`.
Lo script `test_urls.py` nella directory `tests` consente di verificare
gli URL relativi a GitHub presenti nei file delle sottodirectory `assets`.

Anche questo test può essere automatizzato mediante GitHub Actions. Il file `test.yaml` in `.github/workflows` attiva automaticamente i test dopo ogni push o pull request. Allo stesso modo, è possibile avviare manualmente questi test in qualsiasi momento.
Anche questo test può essere automatizzato mediante GitHub Actions.
Il file `test.yaml` in `.github/workflows` attiva automaticamente i test
dopo ogni push o pull request.
Inoltre, è possibile eseguirli manualmente in qualsiasi momento.

Per abilitare i test URL in un altro repository, è sufficiente copiare il file [`/tests/test_urls.py`](/tests/test_urls.py) e il file [`.github/workflows/test.yaml`](.github/workflows/test.yaml).
Per abilitare i test URL in un altro repository,
copiare il file [`/tests/test_urls.py`](/tests/test_urls.py) e il file [`.github/workflows/test.yaml`](.github/workflows/test.yaml).

### Controlli e Test in Locale

È possibile eseguire i controlli e i test in locale utilizzando l'ambiente Docker o semplicemente Python. Un ambiente di test integrato per riprodurre la pipeline CI è disponibile tramite `docker-compose`, che esegue una serie di passaggi.
I controlli e i test possono essere eseguiti anche in locale
con Docker o Python. Usa `docker-compose` per replicare
la pipeline CI:

```bash
docker-compose -f docker-compose-test.yml up
```

Nota: Se si desidera trasferire questo ambiente su un altro repository, è importante considerare che l'ambiente Docker richiede i Dockerfile presenti nella directory `tests` (come `Dockerfile.precommit` e `Dockerfile.pytest`).
Nota: Per trasferire questo ambiente su un altro repository,
è necessario includere i Dockerfile
presenti nella directory `tests` (come `Dockerfile.precommit` e `Dockerfile.pytest`).

Loading

0 comments on commit d19c50b

Please sign in to comment.