|
| 1 | +name: Exportera till HTML-format och publicera till GitHub Pages |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: # Tillåter manuell körning |
| 5 | + inputs: |
| 6 | + source_ref: |
| 7 | + description: 'Git ref att bygga från' |
| 8 | + required: false |
| 9 | + default: 'main' |
| 10 | + filter: |
| 11 | + description: 'Filtrera filer efter år (YYYY) eller specifik beteckning (YYYY:NNN). Kommaseparerad lista.' |
| 12 | + required: false |
| 13 | + type: string |
| 14 | + workflow_call: # Tillåter anrop från andra workflows |
| 15 | + inputs: |
| 16 | + source_ref: |
| 17 | + required: false |
| 18 | + type: string |
| 19 | + default: 'main' |
| 20 | + filter: |
| 21 | + required: false |
| 22 | + type: string |
| 23 | + |
| 24 | +# Behörigheter för GitHub Pages deployment |
| 25 | +permissions: |
| 26 | + contents: read |
| 27 | + pages: write |
| 28 | + id-token: write |
| 29 | + |
| 30 | +# Tillåt endast en deployment åt gången |
| 31 | +concurrency: |
| 32 | + group: "pages" |
| 33 | + cancel-in-progress: false |
| 34 | + |
| 35 | +jobs: |
| 36 | + build: |
| 37 | + runs-on: ubuntu-latest |
| 38 | + environment: Test |
| 39 | + |
| 40 | + steps: |
| 41 | + - name: Checkout repository |
| 42 | + uses: actions/checkout@v4 |
| 43 | + with: |
| 44 | + ref: ${{ inputs.source_ref || 'main' }} |
| 45 | + |
| 46 | + - name: Set up Python |
| 47 | + uses: actions/setup-python@v4 |
| 48 | + with: |
| 49 | + python-version: '3.11' |
| 50 | + |
| 51 | + - name: Install dependencies |
| 52 | + run: | |
| 53 | + python -m pip install --upgrade pip |
| 54 | + pip install -r requirements.txt |
| 55 | +
|
| 56 | + - name: Get JSON source files (from git or R2) |
| 57 | + run: | |
| 58 | + # Try to use JSON files from git first |
| 59 | + if [ -d "data/sfs_json" ] && [ -n "$(ls -A data/sfs_json 2>/dev/null)" ]; then |
| 60 | + echo "✅ Found $(find data/sfs_json -name '*.json' | wc -l) JSON files in git" |
| 61 | + echo "Using JSON files from git checkout" |
| 62 | + else |
| 63 | + echo "⚠️ No JSON files in git, downloading from Cloudflare R2..." |
| 64 | +
|
| 65 | + # Configure AWS CLI for R2 |
| 66 | + aws configure set aws_access_key_id ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY_ID }} |
| 67 | + aws configure set aws_secret_access_key ${{ secrets.CLOUDFLARE_R2_SECRET_ACCESS_KEY }} |
| 68 | + aws configure set region us-east-1 |
| 69 | + aws configure set output json |
| 70 | +
|
| 71 | + # Download all JSON files from R2 |
| 72 | + mkdir -p data/sfs_json |
| 73 | + aws s3 sync s3://${{ secrets.CLOUDFLARE_R2_BUCKET_NAME }}/sfs_json/ data/sfs_json/ \ |
| 74 | + --endpoint-url https://${{ secrets.CLOUDFLARE_R2_ACCOUNT_ID }}.r2.cloudflarestorage.com \ |
| 75 | + --exclude "*" \ |
| 76 | + --include "*.json" |
| 77 | +
|
| 78 | + # Verify download |
| 79 | + if [ ! -d "data/sfs_json" ] || [ -z "$(ls -A data/sfs_json)" ]; then |
| 80 | + echo "::error::Failed to download JSON files from R2" |
| 81 | + exit 1 |
| 82 | + fi |
| 83 | + echo "✅ Downloaded $(find data/sfs_json -name '*.json' | wc -l) JSON files from R2" |
| 84 | + fi |
| 85 | + env: |
| 86 | + AWS_DEFAULT_REGION: us-east-1 |
| 87 | + |
| 88 | + - name: Generate HTML export |
| 89 | + run: | |
| 90 | + # Skapa output-katalog för GitHub Pages |
| 91 | + mkdir -p _site |
| 92 | +
|
| 93 | + if [ -n "${{ inputs.filter }}" ]; then |
| 94 | + python sfs_processor.py --input data/sfs_json --output _site --formats html --filter "${{ inputs.filter }}" |
| 95 | + else |
| 96 | + python sfs_processor.py --input data/sfs_json --output _site --formats html |
| 97 | + fi |
| 98 | + env: |
| 99 | + PYTHONPATH: ${{ github.workspace }} |
| 100 | + |
| 101 | + - name: Generate index pages for HTML export |
| 102 | + run: | |
| 103 | + python exporters/html/populate_index_pages.py --input data/sfs_json --output _site/index.html --limit 30 |
| 104 | + python exporters/html/populate_index_pages.py --input data/sfs_json --output _site/latest.html --limit 10 |
| 105 | + env: |
| 106 | + PYTHONPATH: ${{ github.workspace }} |
| 107 | + |
| 108 | + - name: Add .nojekyll file |
| 109 | + run: | |
| 110 | + # Förhindra Jekyll-processing som kan störa ELI-URL:er |
| 111 | + touch _site/.nojekyll |
| 112 | +
|
| 113 | + - name: Create deployment summary |
| 114 | + run: | |
| 115 | + echo "HTML export completed at $(date)" > _site/last-update.txt |
| 116 | + echo "Published to GitHub Pages" >> _site/last-update.txt |
| 117 | + echo "Index pages: index.html (30 senaste), latest.html (10 senaste)" >> _site/last-update.txt |
| 118 | +
|
| 119 | + - name: Setup Pages |
| 120 | + uses: actions/configure-pages@v5 |
| 121 | + |
| 122 | + - name: Upload artifact |
| 123 | + uses: actions/upload-pages-artifact@v3 |
| 124 | + with: |
| 125 | + path: '_site' |
| 126 | + |
| 127 | + deploy: |
| 128 | + environment: |
| 129 | + name: github-pages |
| 130 | + url: ${{ steps.deployment.outputs.page_url }} |
| 131 | + runs-on: ubuntu-latest |
| 132 | + needs: build |
| 133 | + steps: |
| 134 | + - name: Deploy to GitHub Pages |
| 135 | + id: deployment |
| 136 | + uses: actions/deploy-pages@v4 |
0 commit comments