Skip to content

Commit

Permalink
Add metadata about viewer location to register.json
Browse files Browse the repository at this point in the history
  • Loading branch information
avillar committed Jan 11, 2024
1 parent 2bdafa2 commit 2f0bbb2
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/validate-and-process.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ on:
type: boolean
description: Whether to use the new building blocks viewer
default: true
viewer-path:
type: string
description: Path where to deploy the viewer
default: '.'


permissions:
Expand Down Expand Up @@ -102,6 +106,8 @@ jobs:
config_file: ${{ inputs.config_file }}
test_outputs_path: ${{ inputs.test_outputs_path }}
github_base_url: ${{ inputs.github_base_url }}
deploy_viewer: "${{ inputs.deploy-viewer }}"
viewer_path: ${{ inputs.viewer-path }}
- name: Compress large _visited_properties.tsv and git pull
run: |
sudo find "${{ inputs.annotated_path }}" -size +10M -name _visited_properties.tsv \
Expand Down Expand Up @@ -146,6 +152,10 @@ jobs:
- name: Deploy Building Blocks viewer
if: ${{ inputs.deploy-viewer && github.event.repository.has_pages && !inputs.skip-pages }}
run: |
if [ -n "${{ inputs.viewer_path }}" ]; then
mkdir -p "${{ inputs.viewer_path }}"
cd "${{ inputs.viewer_path }}"
fi
wget -q -O - https://github.com/ogcincubator/bblocks-viewer/archive/refs/heads/dist.tar.gz | tar zx --strip-components=1
sed -i -r 's,/@BASE_URL@/,/${{ github.event.repository.name }}/,g' index.html 404.html assets/*.js assets/*.css
cat << EOF > config.js
Expand Down
2 changes: 2 additions & 0 deletions full/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ runs:
config_file: ${{ inputs.config_file }}
test_outputs_path: ${{ inputs.test_outputs_path }}
github_base_url: ${{ inputs.github_base_url }}
deploy_viewer: "${{ inputs.deploy-viewer }}"
viewer_path: ${{ inputs.viewer-path }}
- name: Generate Slate documentation
continue-on-error: true
run: |
Expand Down
22 changes: 18 additions & 4 deletions ogc/bblocks/entrypoint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
import re
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -98,10 +97,22 @@
'tests,transforms,doc,register). Forces --clean to false'
)

parser.add_argument(
'--deploy-viewer',
help='Whether the javascript bblocks viewer will be deployed'
)

parser.add_argument(
'--viewer-path',
help='Path where the viewer will be deployed',
default='.'
)

args = parser.parse_args()

fail_on_error = args.fail_on_error in ('true', 'on', 'yes')
clean = args.clean in ('true', 'on', 'yes')
fail_on_error = args.fail_on_error in ('true', 'on', 'yes', '1')
clean = args.clean in ('true', 'on', 'yes', '1')
deploy_viewer = args.deploy_viewer in ('true', 'on', 'yes', '1')
bb_config_file = Path(args.config_file) if args.config_file else None

print(f"""Running with the following configuration:
Expand All @@ -118,6 +129,8 @@
- github_base_url: {args.github_base_url}
- filter: {args.filter}
- steps: {args.steps}
- deploy_viewer: {deploy_viewer}
- viewer_path: {args.viewer_path}
""", file=sys.stderr)

register_file = Path(args.register_file)
Expand Down Expand Up @@ -193,7 +206,8 @@
imported_registers=imported_registers,
bb_filter=args.filter,
steps=steps,
git_repo_path=git_repo_path)
git_repo_path=git_repo_path,
viewer_path=(args.viewer_path or '.') if deploy_viewer else None)

# 2. Uplift register.json
print(f"Running semantic uplift of {register_file}", file=sys.stderr)
Expand Down
12 changes: 11 additions & 1 deletion ogc/bblocks/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def postprocess(registered_items_path: str | Path = 'registereditems',
bb_filter: str | None = None,
steps: list[str] | None = None,
bbr_config: dict | None = None,
git_repo_path: Path | None = None) -> list[dict]:
git_repo_path: Path | None = None,
viewer_path: str | Path | None = None) -> list[dict]:

cwd = Path().resolve()

Expand Down Expand Up @@ -170,6 +171,13 @@ def do_postprocess(bblock: BuildingBlock, light: bool = False) -> bool:
transform['ref'] = urljoin(bblock.metadata['sourceFiles'], transform['ref'])
bblock.metadata['transforms'].append({k: v for k, v in transform.items() if k != 'code'})

if viewer_path:
bblock.metadata.setdefault('links', []).append({
'title': 'Building Blocks Viewer',
'href': urljoin(base_url, f"{viewer_path}/bblocks/{bblock.identifier}"),
'rel': 'bblocks-viewer',
})

if not light and (not steps or 'doc' in steps):
print(f" > Generating documentation for {bblock.identifier}", file=sys.stderr)
doc_generator.generate_doc(bblock)
Expand Down Expand Up @@ -304,6 +312,8 @@ def do_postprocess(bblock: BuildingBlock, light: bool = False) -> bool:
output_register_json['name'] = git_repo_path.name
if base_url:
output_register_json['baseURL'] = base_url
if viewer_path:
output_register_json['viewerURL'] = urljoin(base_url, viewer_path)
if full_validation_report_url:
output_register_json['validationReport'] = full_validation_report_url
if output_file == '-':
Expand Down
10 changes: 10 additions & 0 deletions postprocess/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ inputs:
github_base_url:
description: Base URL for linking to GitHub content
default: https://github.com/${{github.repository}}/blob/${{github.ref_name}}/
deploy_viewer:
description: Whether to use the new building blocks viewer
default: 'true'
viewer_path:
description: Path where to deploy the viewer
default: '.'

runs:
using: docker
Expand All @@ -60,3 +66,7 @@ runs:
- ${{ inputs.test_outputs_path }}
- '--github-base-url'
- ${{ inputs.github_base_url }}
- '--deploy-viewer'
- ${{ inputs.deploy_viewer }}
- '--viewer-path'
- ${{ inputs.viewer_path }}

0 comments on commit 2f0bbb2

Please sign in to comment.