diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 06ac725..5920521 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 }}" @@ -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 + diff --git a/add-base.py b/add-base.py index e9c38c3..ad29e16 100644 --- a/add-base.py +++ b/add-base.py @@ -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) diff --git a/file1.shapes.ttl b/file1.shapes.ttl index 7119ebc..d7f9c7e 100644 --- a/file1.shapes.ttl +++ b/file1.shapes.ttl @@ -2,6 +2,7 @@ # imports: http://datashapes.org/dash # prefix: file1 +@base . @prefix dash: . @prefix file1: . @prefix owl: . @@ -13,7 +14,7 @@ a owl:Ontology ; owl:imports ; - owl:versionInfo "Created with TopBraid Composer" ; + owl:versionInfo "Created with TopBraid Composer" ; . file1:DestinationClass_1 a file1:Location ;