Skip to content

Commit 1cbe420

Browse files
ale-rinaldiclaude
andcommitted
Deploy builds to GitHub Pages instead of artifact server
Replace curl-based upload to engarde.linuxzogno.org with GitHub Pages deployment via gh-pages branch. Generates index.html files in each directory to provide navigable file browsing. Builds are organized by branch and preserved across pushes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e4a5cfc commit 1cbe420

1 file changed

Lines changed: 100 additions & 13 deletions

File tree

.github/workflows/build.yml

Lines changed: 100 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,118 @@ name: Build and Deploy
33
on:
44
push:
55

6+
permissions:
7+
contents: write
8+
69
jobs:
710
build:
811
runs-on: ubuntu-latest
9-
12+
1013
steps:
1114
- name: Checkout code
12-
uses: actions/checkout@v3
13-
15+
uses: actions/checkout@v4
16+
1417
- name: Set up Node.js
15-
uses: actions/setup-node@v3
18+
uses: actions/setup-node@v4
1619
with:
1720
node-version: '22.21.0'
18-
21+
1922
- name: Set up Go
2023
uses: actions/setup-go@v4
2124
with:
2225
go-version: '1.25.3'
23-
26+
2427
- name: Build Go application
2528
run: make
26-
27-
- name: Upload artifacts
28-
env:
29-
UPLOAD_KEY: ${{ secrets.UPLOAD_KEY }}
30-
UPLOAD_URL: ${{ vars.UPLOAD_URL }}
29+
30+
- name: Deploy to GitHub Pages
3131
run: |
32-
cd dist
33-
find * -type f -exec echo 'Uploading @{}' \; -exec curl -4 -F 'file=@{}' -F "path=${{ github.ref_name }}/{}" -F "key=$UPLOAD_KEY" "$UPLOAD_URL" \;
32+
BRANCH="${GITHUB_REF_NAME}"
33+
34+
# Configure git
35+
git config user.name "github-actions[bot]"
36+
git config user.email "github-actions[bot]@users.noreply.github.com"
37+
38+
# Save build artifacts
39+
cp -r dist /tmp/dist
40+
41+
# Fetch or create gh-pages branch
42+
git fetch origin gh-pages:gh-pages 2>/dev/null || git checkout --orphan gh-pages
43+
44+
git checkout gh-pages
45+
46+
# Remove old builds for this branch, keep others
47+
rm -rf "$BRANCH"
48+
mkdir -p "$BRANCH"
49+
cp -r /tmp/dist/* "$BRANCH/"
50+
51+
# Generate index.html for every directory
52+
generate_index() {
53+
local dir="$1"
54+
local rel="${dir#./}"
55+
local title="${rel:-.}"
56+
57+
{
58+
cat <<'HEADER'
59+
<!DOCTYPE html>
60+
<html>
61+
<head>
62+
<meta charset="utf-8">
63+
<meta name="viewport" content="width=device-width, initial-scale=1">
64+
<style>
65+
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; max-width: 800px; margin: 40px auto; padding: 0 20px; color: #333; }
66+
h1 { border-bottom: 1px solid #eee; padding-bottom: 10px; }
67+
table { width: 100%; border-collapse: collapse; }
68+
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid #eee; }
69+
th { font-weight: 600; color: #666; }
70+
a { color: #0366d6; text-decoration: none; }
71+
a:hover { text-decoration: underline; }
72+
.size { color: #666; }
73+
</style>
74+
HEADER
75+
echo "<title>Index of /${title}</title>"
76+
echo "</head><body>"
77+
echo "<h1>Index of /${title}</h1>"
78+
echo "<table><thead><tr><th>Name</th><th>Size</th></tr></thead><tbody>"
79+
80+
# Parent directory link
81+
if [ "$dir" != "." ]; then
82+
echo '<tr><td><a href="../">../</a></td><td></td></tr>'
83+
fi
84+
85+
# List directories first, then files
86+
for entry in "$dir"/*/; do
87+
[ -d "$entry" ] || continue
88+
name="$(basename "$entry")"
89+
echo "<tr><td><a href=\"${name}/\">${name}/</a></td><td>-</td></tr>"
90+
done
91+
92+
for entry in "$dir"/*; do
93+
[ -f "$entry" ] || continue
94+
name="$(basename "$entry")"
95+
[ "$name" = "index.html" ] && continue
96+
size=$(stat --format=%s "$entry" 2>/dev/null || stat -f%z "$entry" 2>/dev/null)
97+
if [ "$size" -ge 1048576 ] 2>/dev/null; then
98+
hsize="$(awk "BEGIN{printf \"%.1f MB\", $size/1048576}")"
99+
elif [ "$size" -ge 1024 ] 2>/dev/null; then
100+
hsize="$(awk "BEGIN{printf \"%.1f KB\", $size/1024}")"
101+
else
102+
hsize="${size} B"
103+
fi
104+
echo "<tr><td><a href=\"${name}\">${name}</a></td><td class=\"size\">${hsize}</td></tr>"
105+
done
106+
107+
echo "</tbody></table></body></html>"
108+
} > "$dir/index.html"
109+
}
110+
111+
export -f generate_index
112+
find . -type d \
113+
-not -path './.git*' \
114+
-exec bash -c 'generate_index "$0"' {} \;
115+
116+
# Commit and push
117+
git add -A
118+
git diff --cached --quiet && echo "No changes to deploy" && exit 0
119+
git commit -m "Deploy builds for ${BRANCH} (${GITHUB_SHA::7})"
120+
git push origin gh-pages

0 commit comments

Comments
 (0)