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

Git hashs in lobster online report output file #165

Merged
merged 13 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 0 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ jobs:
- name: Coverage analysis
run: |
make coverage
- name: Check output files
if: always()
run: |
util/check_local_modifications.sh
integration-tests:
name: Integration tests
needs: test
Expand Down Expand Up @@ -127,10 +123,6 @@ jobs:
- name: Run integration tests
run: |
make integration-tests
- name: Check output files
if: always()
run: |
util/check_local_modifications.sh
failure:
name: Check all jobs
needs: integration-tests
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

### 0.9.22-dev

* `lobster-html-report` adds actual git commit hashes to the source in the HTML report.

* `lobster-online-report` - now contains the actual git commit hashes when the user executes the tool.

* The configuration management for the `lobster-cpptest` tool has been migrated from command-line arguments to YAML configuration files.

### 0.9.21
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ system-tests:
make -B -C tests-system TOOL=lobster-json
make -B -C tests-system TOOL=lobster-trlc
make -B -C tests-system TOOL=lobster-python
make -B -C tests-system TOOL=lobster-online-report

unit-tests:
coverage run -p \
Expand Down
13 changes: 7 additions & 6 deletions documentation/schemas.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ References to github look like this:

```
{
"kind" : "github",
"gh_root" : STRING,
"gh_repo" : STRING,
"commit" : STRING,
"filename" : INTEGER,
"line" : INTEGER or null
"kind" : "github",
"gh_root" : STRING,
"gh_repo" : STRING,
"commit" : STRING,
"filename" : INTEGER,
"line" : INTEGER or null,
"exec_commit_id" : STRING
}
```

Expand Down
30 changes: 17 additions & 13 deletions lobster/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,21 @@ def from_json(cls, json):


class Github_Reference(Location):
def __init__(self, gh_root, commit, filename, line):
def __init__(self, gh_root, commit, filename, line, exec_commit_id):
assert isinstance(gh_root, str)
assert gh_root.startswith("http")
assert isinstance(commit, str)
assert isinstance(filename, str)
assert line is None or (isinstance(line, int) and
line >= 1)
assert isinstance(exec_commit_id, str)

self.gh_root = gh_root.rstrip("/")
self.gh_repo = self.gh_root.split("/")[-1]
self.commit = commit
self.filename = filename
self.line = line
self.gh_root = gh_root.rstrip("/")
self.gh_repo = self.gh_root.split("/")[-1]
self.commit = commit
self.filename = filename
self.line = line
self.exec_commit_id = exec_commit_id

def sorting_key(self):
if self.line is not None:
Expand All @@ -183,16 +185,17 @@ def to_html(self):

return '<a href="%s/blob/%s/%s" target="_blank">%s</a>' % (
self.gh_root,
self.commit,
self.exec_commit_id,
file_ref,
self.to_string())

def to_json(self):
return {"kind" : "github",
"gh_root" : self.gh_root,
"commit" : self.commit,
"file" : self.filename,
"line" : self.line}
return {"kind" : "github",
"gh_root" : self.gh_root,
"commit" : self.commit,
"file" : self.filename,
"line" : self.line,
"exec_commit_id" : self.exec_commit_id}

@classmethod
def from_json(cls, json):
Expand All @@ -203,7 +206,8 @@ def from_json(cls, json):
commit = json["commit"]
filename = json["file"]
line = json.get("line", None)
return Github_Reference(gh_root, commit, filename, line)
exec_commit_id = json.get("exec_commit_id")
return Github_Reference(gh_root, commit, filename, line, exec_commit_id)


class Codebeamer_Reference(Location):
Expand Down
31 changes: 29 additions & 2 deletions lobster/tools/core/html_report/html_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import subprocess
import hashlib
import tempfile
from datetime import datetime, timezone

from lobster.html import htmldoc, assets
from lobster.report import Report
Expand Down Expand Up @@ -189,6 +190,23 @@ def create_item_coverage(doc, report):
doc.add_line("</table>")


def get_commit_timestamp_utc(commit_hash):
try:
result = subprocess.run(
['git', 'show', '-s', '--format=%ct', commit_hash],
capture_output=True,
text=True,
check=True
)
epoch_time = int(result.stdout.strip())
# Convert to UTC datetime
utc_time = datetime.fromtimestamp(epoch_time, tz=timezone.utc)
return utc_time
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
return None


def write_item_box_begin(doc, item):
assert isinstance(doc, htmldoc.Document)
assert isinstance(item, Item)
Expand Down Expand Up @@ -252,8 +270,17 @@ def write_item_tracing(doc, report, item):
doc.add_line("</div>")


def write_item_box_end(doc):
def write_item_box_end(doc, item):
assert isinstance(doc, htmldoc.Document)

if getattr(item.location, "exec_commit_id", None) is not None:
commit_hash = item.location.exec_commit_id
doc.add_line(
f'<div class="attribute">'
f'Build Reference: <strong>{commit_hash}</strong> | '
f'Timestamp: {get_commit_timestamp_utc(commit_hash)}'
f'</div>'
)
doc.add_line("</div>")
doc.add_line('<!-- end item -->')

Expand Down Expand Up @@ -480,7 +507,7 @@ def write_html(fd, report, dot, high_contrast):
html.escape(item.text).replace("\n", "<br>"))
doc.add_line('</div>')
write_item_tracing(doc, report, item)
write_item_box_end(doc)
write_item_box_end(doc, item)
else:
doc.add_line("No items recorded at this level.")
# Closing tag for id #search-sec-id
Expand Down
26 changes: 18 additions & 8 deletions lobster/tools/core/online_report/online_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,33 +218,43 @@ def main():

for item in report.items.values():
if isinstance(item.location, File_Reference):
assert os.path.isdir(item.location.filename) or \
os.path.isfile(item.location.filename)
assert (os.path.isdir(item.location.filename) or
os.path.isfile(item.location.filename))

rel_path_from_root = os.path.relpath(item.location.filename,
repo_root)
# pylint: disable=possibly-used-before-assignment
actual_repo = gh_root
actual_sha = options.commit
actual_sha = options.commit
actual_path = rel_path_from_root
exec_commit_id = subprocess.check_output(
["git", "rev-parse", "HEAD"]
).decode().strip()
# pylint: disable=consider-using-dict-items
for prefix in gh_submodule_roots:
if path_starts_with_subpath(rel_path_from_root, prefix):
actual_repo = gh_submodule_roots[prefix]
actual_sha = gh_submodule_sha[prefix]
actual_sha = gh_submodule_sha[prefix]
actual_path = rel_path_from_root[len(prefix) + 1:]
exec_commit_id = subprocess.check_output(
["git", "rev-parse", "HEAD"],
universal_newlines=True, cwd=prefix
)
exec_commit_id = exec_commit_id.strip()
break

loc = Github_Reference(
gh_root = actual_repo,
commit = actual_sha,
filename = actual_path,
line = item.location.line)
gh_root=actual_repo,
commit=actual_sha,
filename=actual_path,
line=item.location.line,
exec_commit_id=exec_commit_id)
item.location = loc

report.write_report(options.out if options.out else options.lobster_report)
print("LOBSTER report %s changed to use online references" %
options.out if options.out else options.lobster_report)
return 0


if __name__ == "__main__":
Expand Down
14 changes: 13 additions & 1 deletion tests-integration/projects/basic/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,23 @@ CLANG_TIDY:=$(LOBSTER_ROOT)/../llvm-project/build/bin/clang-tidy

THIS_TEST:=$(shell realpath --relative-to $(LOBSTER_ROOT) $(PWD))
THIS_TEST_ESCAPED:=$(subst /,\\/,$(THIS_TEST))
REFERENCE_OUTPUT:='report.reference_output'
PYTHON = python3
UPDATE_GIT_HASHES_SCRIPT:='../../../tests-system/tests_utils/update_online_json_with_hashes.py'

# Python script to delete the git hashes from reference_output file
DELETE_COMMIT_IDS_PYTHON_SCRIPT:='../../../tests-system/tests_utils/delete_commit_ids_integration_test.py'

html_report.html: cppcode.lobster gtests.lobster mcode.lobster system-requirements.lobster software-requirements.lobster lobster.conf pycode.lobster json.lobster
@lobster-report
@lobster-online-report
@cp report.lobster report.reference_output
$(PYTHON) $(UPDATE_GIT_HASHES_SCRIPT) $(REFERENCE_OUTPUT)
@if diff report.lobster $(REFERENCE_OUTPUT); then \
echo "Files are identical"; \
else \
echo "Files are different"; \
exit 1; \
fi
@lobster-html-report
@lobster-ci-report | tee ci_report.reference_output

Expand Down
Loading
Loading