forked from espresso3389/pdfrx
-
Notifications
You must be signed in to change notification settings - Fork 0
219 lines (202 loc) · 8.07 KB
/
Copy pathgithub-pages.yml
File metadata and controls
219 lines (202 loc) · 8.07 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
name: Build and Deploy Flutter Web to GitHub Pages
on:
push:
branches:
- master
paths-ignore:
- '**.md'
- 'doc/**'
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
example: [viewer, pdf_combine]
steps:
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Setup Flutter
run: |
git clone https://github.com/flutter/flutter.git --depth 1 --branch stable ~/flutter
echo "$HOME/flutter/bin" >> $GITHUB_PATH
~/flutter/bin/flutter config --no-enable-android --no-enable-linux-desktop
~/flutter/bin/flutter channel stable
- name: Check Flutter SDK version
run: |
flutter --version
FLUTTER_VERSION=$(flutter --version | head -n 1 | awk '{print $2}')
echo "FLUTTER_VERSION=$FLUTTER_VERSION" >> $GITHUB_ENV
- name: Check pdfrx version
run: |
PDFRX_VERSION=$(awk -F": " '/^version:/ {print $2}' pubspec.yaml)
echo "PDFRX_VERSION=$PDFRX_VERSION" >> $GITHUB_ENV
- name: Install dependencies
run: flutter pub get
- name: Build Flutter Web App (WASM)
run: |
cd packages/pdfrx/example/${{ matrix.example }}/
flutter build web --wasm --release --base-href "/pdfrx/${{ matrix.example }}/" --dart-define=GITHUB_COMMIT=$GITHUB_SHA --dart-define=PDFRX_VERSION=$PDFRX_VERSION
sed -i "s/__CONFIGS__/pdfrx=${PDFRX_VERSION},commit=${GITHUB_SHA},flutter=${FLUTTER_VERSION}/g" build/web/index.html
- name: Upload build artifact
uses: actions/upload-artifact@v7.0.1
with:
name: ${{ matrix.example }}-web
path: packages/pdfrx/example/${{ matrix.example }}/build/web/
retention-days: 1
deploy:
runs-on: ubuntu-latest
needs: build
# NOTE: This workflow automatically update gh-pages branch and it requires write permissions
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Download all artifacts
uses: actions/download-artifact@v8.0.1
with:
path: artifacts/
- name: Prepare deployment directory
run: |
mkdir -p deploy_temp
# Copy each example to its subdirectory
cp -r artifacts/viewer-web deploy_temp/viewer
cp -r artifacts/pdf_combine-web deploy_temp/pdf_combine
# Extract version info from artifact
VERSION_INFO=$(grep 'pdfrx-configs' artifacts/viewer-web/index.html | sed 's/.*content="\([^"]*\)".*/\1/')
PDFRX_VERSION=$(echo "$VERSION_INFO" | sed 's/.*pdfrx=\([^,]*\).*/\1/')
FLUTTER_VERSION=$(echo "$VERSION_INFO" | sed 's/.*flutter=\([^,]*\).*/\1/')
echo "PDFRX_VERSION=$PDFRX_VERSION" >> $GITHUB_ENV
echo "FLUTTER_VERSION=$FLUTTER_VERSION" >> $GITHUB_ENV
# Create root index.html
cat > deploy_temp/index.html << 'EOF'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="pdfrx-configs" content="__CONFIGS__">
<title>pdfrx - Flutter PDF Library</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
max-width: 800px;
margin: 50px auto;
padding: 20px;
line-height: 1.6;
}
h1 {
color: #333;
border-bottom: 2px solid #0175c2;
padding-bottom: 10px;
}
.examples {
display: grid;
gap: 20px;
margin-top: 30px;
}
.example-card {
border: 1px solid #ddd;
border-radius: 8px;
padding: 20px;
transition: box-shadow 0.3s;
}
.example-card:hover {
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.example-card h2 {
margin-top: 0;
color: #0175c2;
}
.example-card a {
display: inline-block;
margin-top: 10px;
padding: 10px 20px;
background: #0175c2;
color: white;
text-decoration: none;
border-radius: 4px;
}
.example-card a:hover {
background: #015a94;
}
.footer {
margin-top: 50px;
text-align: center;
color: #666;
font-size: 0.9em;
}
.version-info {
margin-top: 15px;
padding-top: 15px;
border-top: 1px solid #ddd;
font-size: 0.85em;
color: #888;
}
.version-info a {
color: #0175c2;
text-decoration: none;
}
.version-info a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<h1>pdfrx - Flutter PDF Library</h1>
<p>A powerful and flexible PDF viewer and manipulation library for Flutter.</p>
<div class="examples">
<div class="example-card">
<h2>PDF Viewer</h2>
<p>A full-featured PDF viewer with zoom, pan, text selection, and more.</p>
<a href="viewer/">Launch Viewer Demo</a>
</div>
<div class="example-card">
<h2>PDF Combine</h2>
<p>Combine multiple PDF files into a single document.</p>
<a href="pdf_combine/">Launch PDF Combine Demo</a>
</div>
</div>
<div class="footer">
<p>
<a href="https://github.com/espresso3389/pdfrx" target="_blank">GitHub Repository</a> |
<a href="https://pub.dev/packages/pdfrx" target="_blank">pub.dev Package</a>
</p>
<p class="version-info">
pdfrx: __PDFRX_VERSION__ | commit: <a href="https://github.com/espresso3389/pdfrx/commit/__COMMIT__" target="_blank">__COMMIT_SHORT__</a> | Flutter: __FLUTTER_VERSION__
</p>
</div>
</body>
</html>
EOF
# Add version info to index.html
COMMIT_SHORT=${GITHUB_SHA:0:7}
sed -i "s/__CONFIGS__/pdfrx=${PDFRX_VERSION},commit=${GITHUB_SHA},flutter=${FLUTTER_VERSION}/g" deploy_temp/index.html
sed -i "s/__PDFRX_VERSION__/${PDFRX_VERSION}/g" deploy_temp/index.html
sed -i "s/__COMMIT__/${GITHUB_SHA}/g" deploy_temp/index.html
sed -i "s/__COMMIT_SHORT__/${COMMIT_SHORT}/g" deploy_temp/index.html
sed -i "s/__FLUTTER_VERSION__/${FLUTTER_VERSION}/g" deploy_temp/index.html
- name: Configure Git for deployment
run: |
git config user.email "action@github.com"
git config user.name "GitHub Action"
git remote set-url origin https://x-access-token:${{ secrets.TOKEN_FOR_GHPAGE_DEPLOYMENT }}@github.com/${{ github.repository }}.git
- name: Deploy to GitHub Pages
run: |
mv deploy_temp /tmp/deploy_temp
if git ls-remote --exit-code --heads origin gh-pages >/dev/null 2>&1; then
git fetch origin gh-pages
git checkout -B gh-pages origin/gh-pages
else
git checkout --orphan gh-pages
git rm -rf . || true
fi
find . -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} +
cp -a /tmp/deploy_temp/. .
git add -A
if git diff --cached --quiet; then
echo "No changes to deploy"
exit 0
fi
git commit -m "$PDFRX_VERSION $GITHUB_SHA"
git push origin gh-pages