Skip to content

Commit

Permalink
Add commit link that triggered the action
Browse files Browse the repository at this point in the history
  • Loading branch information
xxyzz committed Dec 7, 2023
1 parent afcf31c commit 4620fc8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
PYTHONWARNINGS: default
- run: |
make coverage_report
make github_pages
make github_pages REPO=${{ github.repository }} SHA=${{ github.sha }}
if: github.ref_name == 'master' && matrix.python-version == '3.12'
- uses: actions/upload-pages-artifact@v2
if: github.ref_name == 'master' && matrix.python-version == '3.12'
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Run "make test" to run tests
# Run "make clean" to remove automatically generated files
REPO ?= tatuylonen/wiktextract
SHA ?= HEAD

test:
python -m unittest discover -b -s tests
test_coverage:
Expand All @@ -11,7 +14,7 @@ coverage_report:
github_pages:
python tools/generate_schema.py
cp json_schema/*.json _site
python tools/github_pages.py
python tools/github_pages.py $(REPO) $(SHA)
clean:
python -m coverage erase
rm -rf __pycache__ _site
11 changes: 11 additions & 0 deletions tools/github_pages.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import json
from pathlib import Path

Expand All @@ -6,6 +7,11 @@ def main():
"""
Generate a simple HTML page to list files in the `_site` folder.
"""
parser = argparse.ArgumentParser()
parser.add_argument("repo", help="The owner and repository name.")
parser.add_argument("sha", help="The commit SHA.")
args = parser.parse_args()

html = """
<!DOCTYPE HTML>
<html lang="en-US">
Expand All @@ -21,6 +27,7 @@ def main():
<ul>
<schema_list>
</ul>
<commit_sha>
</body>
</html>
"""
Expand All @@ -37,6 +44,10 @@ def main():
schema_data = json.load(f)
schema_list_html += f"<li><a href='{schema_path.name}'>{schema_data.get('title')}</a></li>"
html = html.replace("<schema_list>", schema_list_html)

commit_sha = f"<p>Commit: <a href='https://github.com/{args.repo}/commit/{args.sha}'>{args.sha[:7]}</a></p>"
html = html.replace("<commit_sha>", commit_sha)

with open("_site/index.html", "w", encoding="utf-8") as f:
f.write(html)

Expand Down

0 comments on commit 4620fc8

Please sign in to comment.