Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ples into dev
  • Loading branch information
mprinkezs committed Jul 18, 2024
2 parents 4645cf6 + 8d26fd2 commit 2aa4daa
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 23 deletions.
66 changes: 57 additions & 9 deletions .github/scripts/gen_overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ def gen_boilerplate(_category, _tag_index):
"""

md = ""

block_odd = True

apps = os.path.join(BASEDIR, _category)
for _app in os.listdir(apps):
metainfo_path = os.path.abspath(os.path.join(BASEDIR, _category, _app, 'metainfo.json'))
Expand All @@ -122,12 +123,26 @@ def gen_boilerplate(_category, _tag_index):
view = f"{_category}/{_app}/doc/Documentation.md"
download = f"https://software-store.zeiss.com/products/apps/{metainfo['title']}"

if block_odd:
next_class = "example-block-odd"
else:
next_class = "example-block-even"
block_odd = not block_odd

# Title, links to source code and App download
# Using HTML instead of markdown to allow alternating background color via <div> attribute
title = metainfo['title']
md += f"### <a id=\"{title}\">{title}</a> &mdash; [view]({view}) / [download]({download})\n\n"

#md += f"### {title} &mdash; [view]({view}) / [download]({download})\n\n"
md += f'<section id="{title.lower()}">\n'
md += f'<div id="{title.lower()}" class="{next_class}">\n'
md += \
f'''<h3>{title} — <a class="reference external" href="{view}">view</a> /
<a class="reference external" href="{download}">download</a>
<a class="headerlink" href="#{title.lower()}" title="Link to this heading"></a></h3>
\n\n'''

#md += f"![Icon](https://github.com/ZEISS/zeiss-inspect-app-examples/blob/dev/AppExamples/{category}/{app}/icon.png)\n"

# Description
md += ":Description:\n"
md += f" {metainfo['description'].encode('windows-1252').decode('utf-8')}\n\n"
Expand All @@ -143,9 +158,11 @@ def gen_boilerplate(_category, _tag_index):
# References
if 'references' in metainfo:
md += ":References:\n"
for reference in metainfo['references']:
md += f" [{reference[0]}]({reference[1]})\n"

for i, reference in enumerate(metainfo['references']):
if i == 0:
md += f" [{reference[0]}]({reference[1]})"
else:
md += f", [{reference[0]}]({reference[1]})"
md += "\n"

# Tags
Expand All @@ -158,11 +175,14 @@ def gen_boilerplate(_category, _tag_index):
_tag_index[_tag].append(title)
_badge = _tag.replace('-', '--')
if sphinx_doc:
md += f"<a href=\"#{_tag}\">![Static Badge](https://img.shields.io/badge/{_badge}-blue)</a> "
md += f"<a href=\"#{_tag.lower()}\">![Static Badge](https://img.shields.io/badge/{_badge}-blue)</a> "
else:
md += f"[![Static Badge](https://img.shields.io/badge/{_badge}-blue)](#{_tag})<br> "

md += "\n"
md += '\n</div>\n'
md += '\n</section>\n\n'

return md, _tag_index

# ----------------------------------------------------------------------------
Expand Down Expand Up @@ -198,6 +218,32 @@ def gen_boilerplate(_category, _tag_index):
"description": "{args.meta_description}"
"keywords": "Metrology, ZEISS INSPECT, Python API, GOM API, Scripting, Add-ons, Apps, Examples"
---
"""

# Override some default styles / add custom styles for this page
if sphinx_doc:
app_overview += \
"""
<style>
.example-block-odd {
background-color: #f3f6f6;
padding: 10px;
}
.example-block-even {
background-color: #ffffff;
padding: 10px;
}
h2 {
margin-top: 24px;
margin-bottom: 4px;
}
.rst-content h2 {
margin-bottom: 4px;
}
.small-margin {
margin-top: 4px;
}
</style>
"""

app_overview += f"# {args.title}\n"
Expand All @@ -211,6 +257,8 @@ def gen_boilerplate(_category, _tag_index):

# Category heading
app_overview += f"\n## {category} &mdash; {CATEGORY_DESCRIPTIONS[category]}\n\n"
if sphinx_doc:
app_overview += '<hr class="small-margin">\n'

if sphinx_doc:
tmp, tagIndex = gen_boilerplate(category, tagIndex)
Expand Down Expand Up @@ -244,7 +292,7 @@ def gen_boilerplate(_category, _tag_index):

for app in sorted(tagIndex[tag]):
if sphinx_doc:
app_overview += f"* <a href=\"#{app}\">{app}</a>\n"
app_overview += f"* <a href=\"#{app.lower()}\">{app}</a>\n"
else:
app_overview += f"* [{app}](#{app})\n"
app_overview += "\n"
Expand Down
64 changes: 58 additions & 6 deletions .github/workflows/update_overview.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Update overview and create PR
on:
workflow_dispatch:
on: [workflow_dispatch,push]
env:
GH_TOKEN: ${{ github.token }}
jobs:
create_file_and_pr:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -32,20 +33,35 @@ jobs:
ref: ${{ format('{0}', steps.set_branches.outputs.current_branch) }}
fetch-depth: 0 # Fetch all history for all branches and tags

- name: Git config
run: |
git config --global user.email "action@github.com"
git config --global user.name "GitHub Action"
- name: Create a new branch
run: |
git checkout -b overview-update || git checkout overview-update
- name: Update overview
- name: Update overview (ZEISS)
run: |
python .github/scripts/gen_overview.py > AppExamples/README.md
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
if [ -z "$(git status --porcelain)" ]; then
echo "No changes to commit."
echo "changes=false" >> $GITHUB_ENV
else
echo "Changes detected."
echo "changes=true" >> $GITHUB_ENV
fi
- name: Push changes (ZEISS)
if: env.changes == 'true'
run: |
git add AppExamples/README.md
git commit -m "Updated AppExamples/README.md"
git push origin +overview-update:overview-update
git push origin +overview-update:overview-update
- name: Create Pull Request
if: env.changes == 'true'
uses: devops-infra/action-pull-request@v0.5.5
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -64,3 +80,39 @@ jobs:
get_diff: true
ignore_users: "dependabot"
allow_no_diff: false

- name: Update overview (ZeissIQS)
run: |
python .github/scripts/gen_overview.py --sphinx-doc > examples_overview.md
gh repo clone ZeissIQS/zeiss-inspect-addon-api
cd zeiss-inspect-addon-api
git checkout -b overview-update --track origin/main
cp ../examples_overview.md doc/python_examples/examples_overview.md
if [ -z "$(git status --porcelain)" ]; then
echo "No changes to commit."
echo "changes=false" >> $GITHUB_ENV
else
echo "Changes detected."
echo "changes=true" >> $GITHUB_ENV
fi
- name: Push changes (ZeissIQS)
if: env.changes == 'true'
run: |
cd zeiss-inspect-addon-api
git add doc/python_examples/examples_overview.md
git commit -m "Updated doc/python_examples/examples_overview.md"
git remote set-url origin https://x-access-token:${{ secrets.TARGET_REPO_PAT_2 }}@github.com/ZeissIQS/zeiss-inspect-addon-api.git
git push origin +overview-update:overview-update
# Note: Pull Request in ZeissIQS project is created by a separate workflow in ZeissIQS due to permission issues
#- name: Create Pull Request (ZeissIQS)
# if: env.changes == 'true'
# run: |
# echo "${{ secrets.TARGET_REPO_PAT_2 }}" | gh auth login --with-token
# gh pr create --repo ZeissIQS/zeiss-inspect-addon-api \
# --head overview-update \
# --title "${{ format('Updated App Examples Overview (AppExamples/README.md) ({0})', steps.set_branches.outputs.target_branch) }}" \
# --body "**Automated pull request**" \
# --label documentation \
# --reviewer ${{ format('{0}', steps.reviewers.outputs.reviewers) }}
Loading

0 comments on commit 2aa4daa

Please sign in to comment.