-
Notifications
You must be signed in to change notification settings - Fork 1
192 lines (166 loc) · 6.53 KB
/
github-pages-workflow.yml
File metadata and controls
192 lines (166 loc) · 6.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
name: Exportera till HTML och publicera till GitHub Pages
on:
workflow_dispatch: # Tillåter manuell körning
inputs:
html_source:
description: 'HTML-källan: generera från JSON eller ladda från R2'
required: false
type: choice
options:
- generate
- download
default: 'generate'
source_ref:
description: 'Git ref att bygga från'
required: false
default: 'main'
filter:
description: 'Filtrera filer efter år (YYYY) eller specifik beteckning (YYYY:NNN). Kommaseparerad lista.'
required: false
type: string
workflow_call: # Tillåter anrop från andra workflows
inputs:
html_source:
required: false
type: string
default: 'generate'
source_ref:
required: false
type: string
default: 'main'
filter:
required: false
type: string
# Behörigheter för GitHub Pages deployment
permissions:
contents: read
pages: write
id-token: write
# Tillåt endast en deployment åt gången
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
environment: Test
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.source_ref || 'main' }}
- name: Download pre-built HTML from Cloudflare R2
if: inputs.html_source == 'download'
run: |
echo "📥 Laddar ner färdiga HTML-filer från Cloudflare R2..."
# Configure AWS CLI for R2
aws configure set aws_access_key_id ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY_ID }}
aws configure set aws_secret_access_key ${{ secrets.CLOUDFLARE_R2_SECRET_ACCESS_KEY }}
aws configure set region us-east-1
aws configure set output json
# Create output directory
mkdir -p _site
# Download all HTML files from R2 HTMLEXPORT bucket
echo "Syncing from bucket: ${{ vars.CLOUDFLARE_R2_HTMLEXPORT_BUCKET_NAME }}"
aws s3 sync s3://${{ vars.CLOUDFLARE_R2_HTMLEXPORT_BUCKET_NAME }}/ _site/ \
--endpoint-url https://${{ secrets.CLOUDFLARE_R2_ACCOUNT_ID }}.r2.cloudflarestorage.com \
--delete
# Verify download
if [ ! -d "_site" ] || [ -z "$(ls -A _site)" ]; then
echo "::error::Failed to download HTML files from R2"
exit 1
fi
echo "✅ Downloaded HTML files from R2 HTMLEXPORT bucket"
echo "Total files: $(find _site -type f | wc -l)"
echo "Total size: $(du -sh _site | cut -f1)"
env:
AWS_DEFAULT_REGION: us-east-1
- name: Set up Python
if: inputs.html_source == 'generate' || inputs.html_source == ''
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
if: inputs.html_source == 'generate' || inputs.html_source == ''
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Get JSON source files (from git or R2)
if: inputs.html_source == 'generate' || inputs.html_source == ''
run: |
# Try to use JSON files from git first
if [ -d "data/sfs_json" ] && [ -n "$(ls -A data/sfs_json 2>/dev/null)" ]; then
echo "✅ Found $(find data/sfs_json -name '*.json' | wc -l) JSON files in git"
echo "Using JSON files from git checkout"
else
echo "⚠️ No JSON files in git, downloading from Cloudflare R2..."
# Configure AWS CLI for R2
aws configure set aws_access_key_id ${{ secrets.CLOUDFLARE_R2_ACCESS_KEY_ID }}
aws configure set aws_secret_access_key ${{ secrets.CLOUDFLARE_R2_SECRET_ACCESS_KEY }}
aws configure set region us-east-1
aws configure set output json
# Download all JSON files from R2
mkdir -p data/sfs_json
aws s3 sync s3://${{ vars.CLOUDFLARE_R2_RAWDATA_BUCKET_NAME }}/ data/sfs_json/ \
--endpoint-url https://${{ secrets.CLOUDFLARE_R2_ACCOUNT_ID }}.r2.cloudflarestorage.com \
--exclude "*" \
--include "*.json"
# Verify download
if [ ! -d "data/sfs_json" ] || [ -z "$(ls -A data/sfs_json)" ]; then
echo "::error::Failed to download JSON files from R2"
exit 1
fi
echo "✅ Downloaded $(find data/sfs_json -name '*.json' | wc -l) JSON files from R2"
fi
env:
AWS_DEFAULT_REGION: us-east-1
- name: Generate HTML export
if: inputs.html_source == 'generate' || inputs.html_source == ''
run: |
# Skapa output-katalog för GitHub Pages
mkdir -p _site
if [ -n "${{ inputs.filter }}" ]; then
python sfs_processor.py --input data/sfs_json --output _site --formats html --filter "${{ inputs.filter }}"
else
python sfs_processor.py --input data/sfs_json --output _site --formats html
fi
env:
PYTHONPATH: ${{ github.workspace }}
- name: Generate index pages for HTML export
if: inputs.html_source == 'generate' || inputs.html_source == ''
run: |
python exporters/html/populate_index_pages.py --input data/sfs_json --output _site/index.html --limit 30
python exporters/html/populate_index_pages.py --input data/sfs_json --output _site/latest.html --limit 10
env:
PYTHONPATH: ${{ github.workspace }}
- name: Add .nojekyll file
run: |
# Förhindra Jekyll-processing som kan störa ELI-URL:er
touch _site/.nojekyll
- name: Create deployment summary
run: |
echo "HTML export completed at $(date)" > _site/last-update.txt
echo "Published to GitHub Pages" >> _site/last-update.txt
if [ "${{ inputs.html_source }}" = "download" ]; then
echo "Source: Pre-built HTML from Cloudflare R2" >> _site/last-update.txt
echo "Bucket: ${{ vars.CLOUDFLARE_R2_HTMLEXPORT_BUCKET_NAME }}" >> _site/last-update.txt
else
echo "Source: Generated from JSON" >> _site/last-update.txt
echo "Index pages: index.html (30 senaste), latest.html (10 senaste)" >> _site/last-update.txt
fi
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: '_site'
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4