diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index 3ac1383..51a5aff 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -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 @@ -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 }} diff --git a/Dockerfile b/Dockerfile index 2283c2d..17a580f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.10-alpine +ARG BBP_GIT_INFO="" + WORKDIR /src COPY requirements.txt / @@ -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/ diff --git a/ogc/bblocks/entrypoint.py b/ogc/bblocks/entrypoint.py index f367330..24371f7 100644 --- a/ogc/bblocks/entrypoint.py +++ b/ogc/bblocks/entrypoint.py @@ -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 diff --git a/ogc/bblocks/postprocess.py b/ogc/bblocks/postprocess.py index 8a79387..7a2c321 100644 --- a/ogc/bblocks/postprocess.py +++ b/ogc/bblocks/postprocess.py @@ -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 @@ -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))