Skip to content

Commit

Permalink
Add tooling info to register.json
Browse files Browse the repository at this point in the history
  • Loading branch information
avillar committed Jan 26, 2024
1 parent 605ab9e commit c0c1ba5
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v3

- name: Add git environment variables
id: env-variables
run: |
echo "BBP_GIT_INFO=\"$(git rev-parse HEAD) $(date --iso-8601=seconds)\"" >> "$GITHUB_OUTPUT"
- name: Log in to the Container registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
Expand All @@ -45,3 +50,5 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BBP_GIT_INFO=${{ steps.env-variables.outputs.BBP_GIT_INFO }}
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM python:3.10-alpine

ARG BBP_GIT_INFO=""

WORKDIR /src
COPY requirements.txt /

Expand All @@ -8,13 +10,15 @@ RUN apk update && \
python -m venv /venv && \
/venv/bin/python -m pip install --upgrade pip && \
git config --global --add safe.directory '*' && \
npm install jsonld
npm install jsonld && \
echo "$BBP_GIT_INFO" > /GIT_INFO

RUN /venv/bin/python -m pip install -r /requirements.txt

ENV PYTHONPATH /src/
ENV PYTHONUNBUFFERED 1
ENV NODE_PATH=/src/node_modules
ENV BBP_GIT_INFO_FILE=/GIT_INFO

COPY ogc/ /src/ogc/

Expand Down
25 changes: 16 additions & 9 deletions ogc/bblocks/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,27 @@
else:
imported_registers = [ir if ir != DEFAULT_IMPORT_MARKER else MAIN_BBR for ir in imported_registers if ir]

register_abstract = bb_config.get('abstract')
if register_abstract:
register_additional_metadata['abstract'] = register_abstract
register_description = bb_config.get('description')
if register_description:
register_additional_metadata['description'] = register_description
register_name = bb_config.get('name')
if register_name:
register_additional_metadata['name'] = register_name
for p in ('name', 'abstract', 'description'):
v = bb_config.get(p)
if v:
register_additional_metadata[p] = v

sparql_conf = bb_config.get('sparql', {}) or {}
if sparql_conf and sparql_conf.get('query'):
register_additional_metadata['sparqlEndpoint'] = sparql_conf['query']

if os.environ.get('BBP_GIT_INFO_FILE'):
with open(os.environ['BBP_GIT_INFO_FILE']) as f:
git_info = f.readline().strip()
if git_info:
commit_id, timestamp = git_info.split(' ', 1)
tooling = register_additional_metadata.setdefault('tooling', {})
tooling['bblocks-postprocess'] = {
'commitId': commit_id,
'shortCommitId': commit_id[0:7],
'date': timestamp,
}

base_url = args.base_url
github_base_url = args.github_base_url
git_repo_path = None
Expand Down
16 changes: 9 additions & 7 deletions ogc/bblocks/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,8 @@ def do_postprocess(bblock: BuildingBlock, light: bool = False) -> bool:
report_to_html(json_reports=validation_reports, report_fn=test_outputs_path / 'report.html')

if output_file and (not steps or 'register' in steps):
output_register_json = {
'imports': imported_registers or [],
'bblocks': output_bblocks,
}

output_register_json = {}

if 'name' not in additional_metadata and git_repo_path:
output_register_json['name'] = git_repo_path.name
Expand All @@ -332,9 +330,13 @@ def do_postprocess(bblock: BuildingBlock, light: bool = False) -> bool:
output_register_json['validationReport'] = full_validation_report_url

if additional_metadata:
for k, v in additional_metadata.items():
if k not in output_register_json:
output_register_json[k] = v
output_register_json = {
**additional_metadata,
**output_register_json,
}

output_register_json['imports'] = imported_registers or []
output_register_json['bblocks'] = output_bblocks

if output_file == '-':
print(json.dumps(output_register_json, indent=2, cls=CustomJSONEncoder))
Expand Down

0 comments on commit c0c1ba5

Please sign in to comment.