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 github workflow to validate samples #104

Merged
merged 14 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/clean-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
echo "Slug=$(echo "${{ github.head_ref }}" | sed "s/\//\-/g")" >> "$GITHUB_ENV"
- name: If no github.head_ref, use last chunk of github.ref as Slug
if: github.head_ref == ''
run: |
run: |
IFS="\/";
read -a strarr <<< "${{ github.ref }}";
read -a strarr <<< "${{ github.ref }}";
last_ref="${strarr[${#strarr[*]}-1]}";
echo "Slug=$(echo $last_ref)" >> "$GITHUB_ENV"
- name: Document which reference
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
echo "Slug=$(echo "${{ github.head_ref }}" | sed "s/\//\-/g")" >> "$GITHUB_ENV"
- name: If no github.head_ref, use last chunk of github.ref as Slug
if: github.head_ref == ''
run: |
run: |
IFS="\/";
read -a strarr <<< "${{ github.ref }}";
read -a strarr <<< "${{ github.ref }}";
last_ref="${strarr[${#strarr[*]}-1]}";
echo "Slug=$(echo $last_ref)" >> "$GITHUB_ENV"
- name: Document which reference
Expand Down
72 changes: 72 additions & 0 deletions .github/workflows/validate_samples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Validate-Samples

on:
push:
paths:
- 'samples/*/TIDES/*'
- 'spec/*'
pull_request:
paths:
- 'samples/*/TIDES/*'
- 'spec/*'
workflow_dispatch:
create:

jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.x
- name: Install Frictionless
run: pip install frictionless[excel,json]>=5.0.0
- name: Find Sample Folders
id: sample_folders
run: |
pwd
samples=$(find ./samples -type d -name 'TIDES')
echo "::set-output name=samples::$samples"
e-lo marked this conversation as resolved.
Show resolved Hide resolved
- name: Validate Sample Data
id: validation
run: |
samples=(${{ steps.sample_folders.outputs.samples }})
results=""
for sample in "${samples[@]}"; do
result=$(frictionless validate "$sample/datapackage.json" --json)
e-lo marked this conversation as resolved.
Show resolved Hide resolved
results+="$result\n"
botanize marked this conversation as resolved.
Show resolved Hide resolved
done
echo "::set-output name=results::$results"
e-lo marked this conversation as resolved.
Show resolved Hide resolved
- name: Comment on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const samples = '${{ steps.sample_folders.outputs.samples }}'.trim().split('\n');
const results = '${{ steps.validation.outputs.results }}'.trim().split('\n');
let comment = `**Data Validation Report**\n\n`;
comment += '| Sample | Status |\n';
comment += '| ------ | ------ |\n';
for (let i = 0; i < samples.length; i++) {
const sample = samples[i];
const result = JSON.parse(results[i]);
let status = '';
if (result.valid) {
status = '![passing](https://via.placeholder.com/20/00ff00/000000?text=+)';
} else if (result.stats.errorCount > 0) {
status = '![failing](https://via.placeholder.com/20/ff0000/000000?text=+)';
} else {
status = '![warning](https://via.placeholder.com/20/ffff00/000000?text=+)';
botanize marked this conversation as resolved.
Show resolved Hide resolved
}
comment += `| ${sample} | ${status} |\n`;
}
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
default_stages: [push]
repos:
- repo: https://github.com/psf/black
rev: 22.8.0
hooks:
- id: black
stages: [commit]
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
hooks:
- id: flake8
stages: [commit]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
stages: [commit]
- id: end-of-file-fixer
stages: [commit]
- id: check-yaml
args: ["--unsafe"]
stages: [commit]
- id: check-added-large-files
- id: check-json
stages: [commit]
- id: requirements-txt-fixer
stages: [commit]
- id: mixed-line-ending
stages: [commit]
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.32.2
hooks:
Expand Down
46 changes: 3 additions & 43 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,49 +30,9 @@ By making any contribution to the projects, contributors self-certify to the [Co

1. [Create a branch](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-and-deleting-branches-within-your-repository) to work on a new issue (or checkout an existing one where the issue is being worked on).
2. Make your changes.
3. Run `pre-commit run --all` to check and fix formatting.
4. Validate schemas if you have changed them using either [act](https://github.com/nektos/act) or [frictionless framework](https://framework.frictionlessdata.io/).
5. [Commit](#commits) your work in `git`
6. `push` your changes to Github and submit a [`pull request`](#pull-requests)

!!! bug

Right now some github actions are broken due to some dependencies issues, so please validate changes to schemas using the [frictionless framework](https://framework.frictionlessdata.io/)

??? tip "Manually Validating TIDES Schema Files with Frictionless"

=== "CLI"

```sh
frictionless validate spec/devices.schema.json
frictionless validate spec/fare_transactions.schema.json
frictionless validate spec/operators.schema.json
frictionless validate spec/passenger_events.schema.json
frictionless validate spec/station_activities.schema.json
frictionless validate spec/stop_visits.schema.json
frictionless validate spec/train_cars.schema.json
frictionless validate spec/trips_performed.schema.json
frictionless validate spec/vehicle_locations.schema.json
frictionless validate spec/vehicle_train_cars.schema.json
frictionless validate spec/vehicles.schema.json
```

=== "python"

```python
import glob
from pprint import pprint
from frictionless import validate

schema_paths = glob.glob("spec/**.schema.json")
for p in schema_paths:
report = validate(p)
if not report['valid']:
print(f"!!! Invalid:{p}")
pprint(report)
else:
print(f"Valid:{p}")
```
3. Run `./test` script to check and fix formatting, validate schemas, and build documentation locally to preview
4. [Commit](#commits) your work in `git`
5. `push` your changes to Github and submit a [`pull request`](#pull-requests)

### Issues

Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ markdown_extensions:
- pymdownx.tasklist:
custom_checkbox: true
- pymdownx.tabbed:
alternate_style: true
alternate_style: true
- pymdownx.superfences:
custom_fences:
- name: mermaid
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-r docs/requirements.txt
pre-commit
frictionless
jsonschema
jsonschema-cli
pre-commit
24 changes: 24 additions & 0 deletions test
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Local validation workflows and try to build documentation locally
echo "1/5 Running precommit"
pre-commit run --all-files

echo "2/5 Validating table schemas"
pre-commit run --all-files
echo "Processing file: $file"
for file in spec/*schema.json; do
echo "Validating: $file"
frictionless validate $file
done

echo "3/5 Validating datapackage"
json-schema-cli validate https://specs.frictionlessdata.io/schemas/data-package.json spec/datapackage.json
botanize marked this conversation as resolved.
Show resolved Hide resolved
botanize marked this conversation as resolved.
Show resolved Hide resolved

echo "4/5 Validating sample data"
for file in samples/**/TIDES/datapackage.json; do
echo "Validating: $file"
frictionless validate --schema-sync $file
done

echo "5/5 Building documentation"
mkdocs build
Loading