Turtle File Quality Control #35
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Turtle File Quality Control | |
on: | |
push: | |
paths: | |
- 'data/**' | |
workflow_dispatch: | |
workflow_run: | |
workflows: [RDF Generation] | |
types: | |
- completed | |
jobs: | |
quality-control: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Check out the repository | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
# Step 2: Set up Python | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.9' | |
# Step 3: Install RDFLib | |
- name: Install RDFLib | |
run: pip install rdflib | |
# Step 4: Create Validation Script | |
- name: Create Validation Script | |
run: | | |
echo " | |
import sys | |
from rdflib import Graph | |
def validate_turtle(file_path): | |
try: | |
g = Graph() | |
g.parse(file_path, format='turtle') | |
print(f'File {file_path} is valid.') | |
return True | |
except Exception as e: | |
print(f'Error in {file_path}: {e}', file=sys.stderr) | |
return False | |
if __name__ == '__main__': | |
files = sys.argv[1:] | |
all_valid = all(validate_turtle(file) for file in files) | |
with open('data/qc-status.txt', 'w') as f: | |
f.write('valid' if all_valid else 'not valid') | |
if not all_valid: | |
sys.exit(1) | |
" > validate_ttl.py | |
# Step 5: Run Validation and Create QC Status File in /data | |
- name: Run Turtle Validation | |
run: python validate_ttl.py data/AOPWikiRDF.ttl data/AOPWikiRDF-Genes.ttl data/AOPWikiRDF-Void.ttl | |
# Step 6: Commit and Push QC Status File to /data | |
- name: Commit and Push QC Status | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add data/qc-status.txt | |
git diff --quiet && git diff --staged --quiet || (git commit -m "Update QC status" && git push) |