Skip to content

Commit 818e309

Browse files
committed
Separate build and deployment
1 parent 4ae6603 commit 818e309

File tree

4 files changed

+163
-128
lines changed

4 files changed

+163
-128
lines changed
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5-
name: Deploy HTML slides to Pages
5+
name: Build HTML slides
66

77
on:
88
push:
@@ -11,17 +11,19 @@ on:
1111
paths:
1212
- "**/docs/**"
1313
- "**/about.yml"
14-
- ".github/workflows/pages.yml"
14+
- ".github/workflows/pages*.yml"
1515
workflow_dispatch:
1616

17-
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
1817
permissions:
1918
contents: read
20-
pages: write
21-
id-token: write
19+
20+
# Cancel in-progress builds for new pushes to the branch
21+
concurrency:
22+
group: pages-build-${{ github.ref_name }}
23+
cancel-in-progress: true
2224

2325
jobs:
2426
pages:
25-
uses: ./.github/workflows/pages.yml
27+
uses: ./.github/workflows/pages-build.yml
2628
with:
2729
include_pdf: false

.github/workflows/pages-build.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SPDX-FileCopyrightText: 2024 CSC - IT Center for Science Ltd. <www.csc.fi>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
name: Build slides
6+
7+
on:
8+
workflow_call:
9+
inputs:
10+
include_pdf:
11+
required: true
12+
type: boolean
13+
14+
jobs:
15+
build:
16+
timeout-minutes: 30
17+
runs-on: ubuntu-latest
18+
container:
19+
image: ghcr.io/csc-training/slidefactory:3.4.3
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Build slides
25+
env:
26+
INCLUDE_PDF: ${{ inputs.include_pdf }}
27+
shell: bash
28+
run: |
29+
git config --global --add safe.directory $PWD
30+
GIT_SHORT_SHA=$(git rev-parse --short $GITHUB_SHA)
31+
GIT_DATE=$(git show -s --format=%ci $GITHUB_SHA)
32+
33+
ARGS=""
34+
[[ "$INCLUDE_PDF" == "true" ]] && ARGS="--with-pdf"
35+
36+
slidefactory pages about.yml build \
37+
--filters tools/mpi_links.py \
38+
--info_content "Updated for [$GIT_SHORT_SHA]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/commit/$GITHUB_SHA) ($GIT_DATE)" \
39+
$ARGS
40+
41+
- name: Upload slide artifact
42+
uses: actions/upload-artifact@v4
43+
with:
44+
name: slides
45+
path: ./build

.github/workflows/pages-deploy.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# SPDX-FileCopyrightText: 2024 CSC - IT Center for Science Ltd. <www.csc.fi>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
name: Deploy pages
6+
7+
on:
8+
workflow_run:
9+
workflows:
10+
- "Build HTML slides"
11+
types:
12+
- completed
13+
14+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
15+
permissions:
16+
contents: read
17+
pages: write
18+
id-token: write
19+
20+
# Only one deploy run at a time across all branches
21+
concurrency:
22+
group: pages-deploy
23+
cancel-in-progress: false
24+
25+
jobs:
26+
deploy:
27+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
28+
environment:
29+
name: github-pages
30+
url: ${{ steps.deployment.outputs.page_url }}${{ github.event.workflow_run.head_branch }}
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Setup Pages
34+
id: pages
35+
uses: actions/configure-pages@v4
36+
37+
- name: Download slide artifact from build
38+
uses: actions/download-artifact@v4
39+
with:
40+
name: slides
41+
path: ./build
42+
run-id: ${{ github.event.workflow_run.id }}
43+
github-token: ${{ secrets.GITHUB_TOKEN }}
44+
45+
- name: Merge previous site and new build
46+
env:
47+
SITE_ZIP: site.zip
48+
BRANCH: ${{ github.event.workflow_run.head_branch }}
49+
shell: bash
50+
run: |
51+
echo "Updating pages for branch $BRANCH:"
52+
53+
# Download previous site
54+
wget -q "https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/$SITE_ZIP" || echo "- Downloading previous site failed - starting pages from scratch"
55+
56+
# Prepare site directory
57+
if [ -f $SITE_ZIP ]; then
58+
unzip -q $SITE_ZIP
59+
rm $SITE_ZIP
60+
else
61+
mkdir site
62+
fi
63+
64+
echo "- Updating existing pages"
65+
rm -rf site/$BRANCH
66+
mv build site/$BRANCH
67+
68+
# Add redirecting index.html at the root
69+
cat > site/index.html <<'EOF'
70+
<!DOCTYPE html>
71+
<html lang="en">
72+
<head>
73+
<meta charset="UTF-8" />
74+
<meta http-equiv="refresh" content="0; url=./main/" />
75+
<script>
76+
window.location.replace('./main/');
77+
</script>
78+
<title>Redirecting</title>
79+
</head>
80+
<body>
81+
<p>Redirecting to <a href="./main/">main</a></p>
82+
</body>
83+
</html>
84+
EOF
85+
86+
# Remove pages for deleted branches
87+
echo "Checking branches:"
88+
find site -mindepth 1 -maxdepth 1 -type d | while read -r dir; do
89+
branch=$(basename "$dir")
90+
91+
if wget -q --spider https://api.github.com/repos/${{ github.repository }}/branches/$branch; then
92+
echo "- $branch: exist - keeping in pages"
93+
else
94+
echo "- $branch: deleted - removing from pages"
95+
rm -rf "$dir"
96+
fi
97+
done
98+
99+
# Repack site
100+
zip -q -r $SITE_ZIP site/
101+
mv $SITE_ZIP site/
102+
103+
- name: Upload pages artifact
104+
uses: actions/upload-pages-artifact@v3
105+
with:
106+
path: ./site
107+
108+
- name: Deploy to GitHub Pages
109+
id: deployment
110+
uses: actions/deploy-pages@v4

.github/workflows/pages.yml

Lines changed: 0 additions & 122 deletions
This file was deleted.

0 commit comments

Comments
 (0)