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