Skip to content

Commit

Permalink
Merge pull request #3 from steveraysteveray/try8-branch
Browse files Browse the repository at this point in the history
Try8 branch
  • Loading branch information
steveraysteveray authored Sep 20, 2023
2 parents bbdbe21 + 2673ca7 commit 82f0825
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ jobs:
- name: Get changed files
id: getfile
run: |
files=$(git diff-tree --no-commit-id --name-only -r $(git log -n 1 --pretty=format:"%H") | grep ".ttl$")
files=$(git diff-tree --no-commit-id --name-only -r $(git log -n 1 --pretty=format:"%H") | grep ".ttl$" || echo "")
if [ -z "$files" ]; then
echo "No .ttl files changed."
exit 0
fi
echo "::set-output name=files::$files"
- name: Run Python script on changed files
run: |
IFS=' ' read -ra ADDR <<< "${{ steps.getfile.outputs.files }}"
Expand All @@ -60,7 +64,12 @@ jobs:
- name: Commit and Push changes
run: |
git add -u # Adds only modified files to the staging area
git commit -m "Updated .ttl files with base URI [AUTO]"
git push
git add -u # Adds only modified files to the staging area
if git diff-index --quiet HEAD --; then
echo "No changes to commit"
else
git commit -m "Updated .ttl files with base URI [AUTO]"
git push
fi
13 changes: 10 additions & 3 deletions add-base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ def add_base_if_missing(file_path):
with open(file_path, 'r') as f:
lines = f.readlines()

# Insert the @base declaration before line #4
if "@base" not in lines[3]: # Checking to ensure it's not already added
lines.insert(3, f"@base <{base_uri}> .\n")
# Find the line number of the first occurrence of '@prefix'
prefix_line_number = next((i for i, line in enumerate(lines) if line.startswith("@prefix")), None)

if prefix_line_number is not None:
# Check if @base is already in the file before the first @prefix
if all("@base" not in line for line in lines[:prefix_line_number]):
lines.insert(prefix_line_number, f"@base <{base_uri}> .\n")
else:
# If no @prefix is found, just append at the end (or handle in some other manner)
lines.append(f"@base <{base_uri}> .\n")

with open(file_path, 'w') as f:
f.writelines(lines)
Expand Down
3 changes: 2 additions & 1 deletion file1.shapes.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# imports: http://datashapes.org/dash
# prefix: file1

@base <https://example/file1> .
@prefix dash: <http://datashapes.org/dash#> .
@prefix file1: <https://example/file1#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
Expand All @@ -13,7 +14,7 @@
<https://example/file1>
a owl:Ontology ;
owl:imports <http://datashapes.org/dash> ;
owl:versionInfo "Created with TopBraid Composer" ;
owl:versionInfo "Created with TopBraid Composer" ;
.
file1:DestinationClass_1
a file1:Location ;
Expand Down

0 comments on commit 82f0825

Please sign in to comment.