|
| 1 | +name: Generate Pathoplexus Example Data List |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + main |
| 7 | + |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v2 |
| 14 | + |
| 15 | + - name: Set up Python |
| 16 | + uses: actions/setup-python@v2 |
| 17 | + with: |
| 18 | + python-version: '3.x' |
| 19 | + |
| 20 | + - name: Install dependencies |
| 21 | + run: | |
| 22 | + python -m pip install --upgrade pip |
| 23 | + pip install markdown |
| 24 | +
|
| 25 | + - name: Create Python script |
| 26 | + run: | |
| 27 | + cat << EOF > generate_list.py |
| 28 | + import os |
| 29 | + import html |
| 30 | + from datetime import datetime |
| 31 | + import markdown |
| 32 | +
|
| 33 | + def get_file_icon(file): |
| 34 | + ext = os.path.splitext(file)[1].lower() |
| 35 | + icon_map = { |
| 36 | + ('.fasta', '.fa', '.fna'): '<i class="fas fa-dna" title="FASTA file"></i>', |
| 37 | + ('.tsv', '.tab'): '<i class="fas fa-table" title="TSV file"></i>', |
| 38 | + ('.py', '.js', '.css', '.html', '.json'): '<i class="fas fa-file-code" title="{} file"></i>', |
| 39 | + ('.jpg', '.jpeg', '.png', '.gif', '.svg'): '<i class="fas fa-file-image" title="{} file"></i>', |
| 40 | + ('.pdf', '.doc', '.docx', '.txt'): '<i class="fas fa-file-alt" title="{} file"></i>', |
| 41 | + } |
| 42 | + |
| 43 | + for extensions, icon in icon_map.items(): |
| 44 | + if ext in extensions: |
| 45 | + return icon.format(ext[1:]) |
| 46 | + return '<i class="fas fa-file"></i>' |
| 47 | +
|
| 48 | + def get_readme_content(): |
| 49 | + try: |
| 50 | + with open('README.md', 'r') as f: |
| 51 | + content = f.read() |
| 52 | + return markdown.markdown(content) |
| 53 | + except FileNotFoundError: |
| 54 | + return "<p>README.md not found.</p>" |
| 55 | +
|
| 56 | + def generate_html(): |
| 57 | + file_list = [] |
| 58 | + for root, dirs, files in os.walk('example_files'): |
| 59 | + for file in files: |
| 60 | + if file != 'index.html' and not file.startswith('.'): |
| 61 | + path = os.path.join(root, file) |
| 62 | + size = os.path.getsize(path) |
| 63 | + mtime = os.path.getmtime(path) |
| 64 | + file_list.append((path, size, mtime)) |
| 65 | +
|
| 66 | + readme_content = get_readme_content() |
| 67 | +
|
| 68 | + html_content = f''' |
| 69 | + <!DOCTYPE html> |
| 70 | + <html lang="en"> |
| 71 | + <head> |
| 72 | + <meta charset="UTF-8"> |
| 73 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 74 | + <title>Pathoplexus Example Files</title> |
| 75 | + <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css" rel="stylesheet"> |
| 76 | + <style> |
| 77 | + body {{ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; line-height: 1.6; padding: 20px; background-color: #f4f4f4; color: #333; }} |
| 78 | + .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); }} |
| 79 | + table {{ width: 100%; border-collapse: collapse; margin-top: 20px; }} |
| 80 | + th, td {{ padding: 12px; text-align: left; border-bottom: 1px solid #e0e0e0; }} |
| 81 | + th {{ background-color: #f2f2f2; font-weight: bold; color: #2c3e50; }} |
| 82 | + tr:hover {{ background-color: #f5f5f5; }} |
| 83 | + a {{ color: #3498db; text-decoration: none; }} |
| 84 | + a:hover {{ color: #2980b9; }} |
| 85 | + .file-icon {{ margin-right: 10px; color: #7f8c8d; }} |
| 86 | + .file-size, .file-date {{ color: #7f8c8d; font-size: 0.9em; }} |
| 87 | + .readme-content {{ margin-bottom: 30px; padding: 20px; border-radius: 5px; }} |
| 88 | + .github-link {{ position: absolute; top: 10px; right: 10px; font-size: 24px; color: #333; }} |
| 89 | + </style> |
| 90 | + </head> |
| 91 | + <body> |
| 92 | + <div class="container"> |
| 93 | + <a href="https://github.com/loculus-project/example_data" class="github-link" target="_blank" rel="noopener noreferrer"> |
| 94 | + <i class="fab fa-github" title="View on GitHub"></i> |
| 95 | + </a> |
| 96 | + <div class="readme-content"> |
| 97 | + {readme_content} |
| 98 | + </div> |
| 99 | + <table> |
| 100 | + <thead> |
| 101 | + <tr> |
| 102 | + <th>File Name</th> |
| 103 | + <th>Size</th> |
| 104 | + <th>Last Modified</th> |
| 105 | + </tr> |
| 106 | + </thead> |
| 107 | + <tbody> |
| 108 | + ''' |
| 109 | +
|
| 110 | + for file, size, mtime in sorted(file_list): |
| 111 | + file = file.replace("example_files/", "") |
| 112 | + icon = get_file_icon(file) |
| 113 | + size_str = f'{size/1024:.1f} KB' if size >= 1024 else f'{size} bytes' |
| 114 | + date_str = datetime.fromtimestamp(mtime).strftime('%Y-%m-%d %H:%M:%S') |
| 115 | + html_content += f''' |
| 116 | + <tr> |
| 117 | + <td><a href="example_files/{html.escape(file)}">{icon} {html.escape(file)}</a></td> |
| 118 | + <td class="file-size">{size_str}</td> |
| 119 | + <td class="file-date">{date_str}</td> |
| 120 | + </tr> |
| 121 | + ''' |
| 122 | +
|
| 123 | + html_content += ''' |
| 124 | + </tbody> |
| 125 | + </table> |
| 126 | + </div> |
| 127 | + </body> |
| 128 | + </html> |
| 129 | + ''' |
| 130 | +
|
| 131 | + with open('index.html', 'w') as f: |
| 132 | + f.write(html_content) |
| 133 | +
|
| 134 | + generate_html() |
| 135 | + EOF |
| 136 | +
|
| 137 | + - name: Generate Pathoplexus example data list |
| 138 | + run: python generate_list.py |
| 139 | + |
| 140 | + - name: Commit and push to gh-pages |
| 141 | + run: | |
| 142 | + git config --global user.name 'GitHub Action' |
| 143 | + git config --global user.email '[email protected]' |
| 144 | + git checkout -b gh-pages |
| 145 | + git add index.html |
| 146 | + git commit -m "Update Pathoplexus example data list" || exit 0 |
| 147 | + git push -f origin gh-pages |
0 commit comments