Skip to content

Commit 4ae6603

Browse files
committed
Build pages for all branches
1 parent 6494a06 commit 4ae6603

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

.github/workflows/pages-html.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
name: Deploy HTML slides to Pages
66

77
on:
8-
# Runs on pushes targeting the default branch
98
push:
109
branches:
11-
- "master"
10+
- "*"
1211
paths:
13-
- "*/docs/**"
12+
- "**/docs/**"
13+
- "**/about.yml"
1414
- ".github/workflows/pages.yml"
15-
16-
# Allows you to run this workflow manually from the Actions tab
1715
workflow_dispatch:
1816

1917
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
@@ -23,7 +21,7 @@ permissions:
2321
id-token: write
2422

2523
jobs:
26-
pages-html:
24+
pages:
2725
uses: ./.github/workflows/pages.yml
2826
with:
2927
include_pdf: false

.github/workflows/pages.yml

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ jobs:
3333
steps:
3434
- name: Checkout
3535
uses: actions/checkout@v4
36+
3637
- name: Setup Pages
3738
id: pages
3839
uses: actions/configure-pages@v4
40+
3941
- name: Build slides
4042
env:
4143
INCLUDE_PDF: ${{ inputs.include_pdf }}
@@ -53,10 +55,60 @@ jobs:
5355
--info_content "Updated for [$GIT_SHORT_SHA]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/commit/$GITHUB_SHA) ($GIT_DATE)" \
5456
$ARGS
5557
56-
- name: Upload artifact
58+
- name: Merge previous site and new build
59+
shell: bash
60+
run: |
61+
# Download previous site
62+
wget -q "https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/site.zip" || echo "Downloading previous site failed"
63+
64+
# Prepare site directory
65+
if [ -f site.zip ]; then
66+
unzip -q site.zip
67+
rm site.zip
68+
else
69+
mkdir site
70+
fi
71+
72+
# Update current branch
73+
rm -rf site/${{ github.ref_name }}
74+
mv build site/${{ github.ref_name }}
75+
76+
# Add redirecting index.html at the root
77+
cat > site/index.html <<'EOF'
78+
<!DOCTYPE html>
79+
<html lang="en">
80+
<head>
81+
<meta charset="UTF-8" />
82+
<meta http-equiv="refresh" content="0; url=./main/" />
83+
<script>
84+
window.location.replace('./main/');
85+
</script>
86+
<title>Redirecting</title>
87+
</head>
88+
<body>
89+
<p>Redirecting to <a href="./main/">main</a></p>
90+
</body>
91+
</html>
92+
EOF
93+
94+
# Remove pages for deleted branches
95+
find site -mindepth 1 -maxdepth 1 -type d | while read -r dir; do
96+
branch=$(basename "$dir")
97+
98+
if ! wget -q --spider https://api.github.com/repos/${{ github.repository }}/branches/$branch; then
99+
echo "branch $branch removed"
100+
rm -rf "$dir"
101+
fi
102+
done
103+
104+
# Repack site
105+
zip -r site site/
106+
mv site.zip site/
107+
108+
- name: Upload artifact for pages
57109
uses: actions/upload-pages-artifact@v3
58110
with:
59-
path: ./build
111+
path: ./site
60112

61113
deploy:
62114
environment:

0 commit comments

Comments
 (0)