Skip to content

Update update-page.yml #11

Update update-page.yml

Update update-page.yml #11

Workflow file for this run

name: Generate Pathoplexus Example Data List
on:
push:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install markdown
- name: Create Python script
run: |
cat << EOF > generate_list.py
import os
import html
from datetime import datetime
import markdown
def get_file_icon(file):
ext = os.path.splitext(file)[1].lower()
icon_map = {
('.fasta', '.fa', '.fna'): '<i class="fas fa-dna" title="FASTA file"></i>',
('.tsv', '.tab'): '<i class="fas fa-table" title="TSV file"></i>',
('.py', '.js', '.css', '.html', '.json'): '<i class="fas fa-file-code" title="{} file"></i>',
('.jpg', '.jpeg', '.png', '.gif', '.svg'): '<i class="fas fa-file-image" title="{} file"></i>',
('.pdf', '.doc', '.docx', '.txt'): '<i class="fas fa-file-alt" title="{} file"></i>',
}
for extensions, icon in icon_map.items():
if ext in extensions:
return icon.format(ext[1:])
return '<i class="fas fa-file"></i>'
def get_readme_content():
try:
with open('README.md', 'r') as f:
content = f.read()
return markdown.markdown(content)
except FileNotFoundError:
return "<p>README.md not found.</p>"
def generate_html():
file_list = []
for root, dirs, files in os.walk('example_files'):
for file in files:
if file != 'index.html' and not file.startswith('.'):
path = os.path.join(root, file)
size = os.path.getsize(path)
mtime = os.path.getmtime(path)
file_list.append((path, size, mtime))
readme_content = get_readme_content()
html_content = f'''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pathoplexus Example Files</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" rel="stylesheet">
<style>
body {{ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; line-height: 1.6; padding: 20px; background-color: #f4f4f4; color: #333; }}
.container {{ max-width: 800px; margin: 0 auto; background-color: #fff; padding: 20px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); }}
table {{ width: 100%; border-collapse: collapse; margin-top: 20px; }}
th, td {{ padding: 12px; text-align: left; border-bottom: 1px solid #e0e0e0; }}
th {{ background-color: #f2f2f2; font-weight: bold; color: #2c3e50; }}
tr:hover {{ background-color: #f5f5f5; }}
a {{ color: #3498db; text-decoration: none; }}
a:hover {{ color: #2980b9; }}
.file-icon {{ margin-right: 10px; color: #7f8c8d; }}
.file-size, .file-date {{ color: #7f8c8d; font-size: 0.9em; }}
.readme-content {{ margin-bottom: 30px; padding: 20px; border-radius: 5px; }}
.github-link {{ position: absolute; top: 10px; right: 10px; font-size: 24px; color: #333; }}
</style>
</head>
<body>
<div class="container">
<a href="https://github.com/loculus-project/example_data" class="github-link" target="_blank" rel="noopener noreferrer">
<i class="fab fa-github" title="View on GitHub"></i>
</a>
<div class="readme-content">
{readme_content}
</div>
<table>
<thead>
<tr>
<th>File Name</th>
<th>Size</th>
<th>Last Modified</th>
</tr>
</thead>
<tbody>
'''
for file, size, mtime in sorted(file_list):
file = file.replace("example_files/", "")
icon = get_file_icon(file)
size_str = f'{size/1024:.1f} KB' if size >= 1024 else f'{size} bytes'
date_str = datetime.fromtimestamp(mtime).strftime('%Y-%m-%d %H:%M:%S')
html_content += f'''
<tr>
<td><a href="example_files/{html.escape(file)}">{icon} {html.escape(file)}</a></td>
<td class="file-size">{size_str}</td>
<td class="file-date">{date_str}</td>
</tr>
'''
html_content += '''
</tbody>
</table>
</div>
</body>
</html>
'''
with open('index.html', 'w') as f:
f.write(html_content)
generate_html()
EOF
- name: Generate Pathoplexus example data list
run: python generate_list.py
- name: Commit and push to gh-pages
run: |
git config --global user.name 'GitHub Action'
git config --global user.email '[email protected]'
git checkout -b gh-pages
git add index.html
git commit -m "Update Pathoplexus example data list" || exit 0
git push -f origin gh-pages