Skip to content

Commit b363957

Browse files
committed
Reorganize pages workflows in a single workflow
1 parent 0868dea commit b363957

File tree

5 files changed

+89
-116
lines changed

5 files changed

+89
-116
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# SPDX-FileCopyrightText: 2024 CSC - IT Center for Science Ltd. <www.csc.fi>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
name: Build slides and deploy pages
6+
7+
# To enable PDF build, set PDF_SLIDES_ENABLED to "true" in GitHub:
8+
# Repository -> Settings -> Secrets and variables -> Actions -> Variables
9+
10+
on:
11+
push:
12+
branches:
13+
- "*"
14+
paths:
15+
- "**/docs/**"
16+
- "**/about.yml"
17+
- ".github/workflows/pages*.yml"
18+
workflow_dispatch:
19+
inputs:
20+
include_pdf:
21+
description: 'Include PDF'
22+
type: boolean
23+
default: true
24+
25+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
26+
permissions:
27+
contents: read
28+
pages: write
29+
id-token: write
30+
31+
# Cancel in-progress builds for new pushes to the branch
32+
concurrency:
33+
group: ${{ github.workflow }}-${{ github.ref }}
34+
cancel-in-progress: true
35+
36+
jobs:
37+
build-html:
38+
name: Build HTML slides
39+
uses: ./.github/workflows/pages-build.yml
40+
with:
41+
include_pdf: false
42+
slides_artifact: slides-html
43+
44+
build-pdf:
45+
name: Build HTML and PDF slides
46+
if: ${{ (github.event_name == 'push' && vars.PDF_SLIDES_ENABLED == 'true') || (github.event_name == 'workflow_dispatch' && fromJSON(inputs.include_pdf)) }}
47+
uses: ./.github/workflows/pages-build.yml
48+
with:
49+
include_pdf: true
50+
slides_artifact: slides-pdf
51+
52+
deploy-html:
53+
name: Deploy HTML slides
54+
needs: [build-html]
55+
uses: ./.github/workflows/pages-deploy.yml
56+
with:
57+
slides_artifact: slides-html
58+
59+
deploy-pdf:
60+
name: Deploy HTML and PDF slides
61+
needs: [deploy-html, build-pdf] # Deploy after HTML deployment to ensure that HTML-only deployment doesn't override PDF deployment
62+
uses: ./.github/workflows/pages-deploy.yml
63+
with:
64+
slides_artifact: slides-pdf

.github/workflows/pages-build-html.yml

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

.github/workflows/pages-build-pdf.yml

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

.github/workflows/pages-build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5-
name: Build slides
5+
name: Build slides (reusable workflow)
66

77
on:
88
workflow_call:
99
inputs:
1010
include_pdf:
1111
required: true
1212
type: boolean
13+
slides_artifact:
14+
required: true
15+
type: string
1316

1417
jobs:
1518
build:
@@ -38,11 +41,8 @@ jobs:
3841
--info_content "Updated for [$GIT_SHORT_SHA]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/commit/$GITHUB_SHA) ($GIT_DATE)" \
3942
$ARGS
4043
41-
# Save commit sha
42-
echo $GITHUB_SHA > build/commit_sha
43-
4444
- name: Upload slide artifact
4545
uses: actions/upload-artifact@v4
4646
with:
47-
name: slides
47+
name: ${{ inputs.slides_artifact }}
4848
path: ./build

.github/workflows/pages-deploy.yml

Lines changed: 20 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,24 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5-
name: Deploy pages
5+
name: Deploy pages (reusable workflow)
66

77
on:
8-
workflow_run:
9-
workflows:
10-
- "Build HTML slides"
11-
- "Build HTML and PDF slides"
12-
types:
13-
- completed
14-
15-
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
16-
permissions:
17-
contents: read
18-
pages: write
19-
id-token: write
20-
21-
# Only one deploy run at a time across all branches
22-
concurrency:
23-
group: pages-deploy
24-
cancel-in-progress: false
8+
workflow_call:
9+
inputs:
10+
slides_artifact:
11+
required: true
12+
type: string
2513

2614
jobs:
2715
deploy:
28-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
16+
runs-on: ubuntu-latest
2917
environment:
3018
name: github-pages
31-
url: ${{ steps.deployment.outputs.page_url }}${{ github.event.workflow_run.head_branch }}
32-
runs-on: ubuntu-latest
19+
url: ${{ steps.deployment.outputs.page_url }}${{ github.ref_name }}
20+
concurrency: # Only one deploy run at a time across all branches
21+
group: pages-deploy
22+
cancel-in-progress: false
3323
steps:
3424
- name: Setup Pages
3525
id: pages
@@ -38,18 +28,16 @@ jobs:
3828
- name: Download slide artifact from build
3929
uses: actions/download-artifact@v4
4030
with:
41-
name: slides
31+
name: ${{ inputs.slides_artifact }}
4232
path: ./build
43-
run-id: ${{ github.event.workflow_run.id }}
44-
github-token: ${{ secrets.GITHUB_TOKEN }}
4533

4634
- name: Merge previous site and new build
4735
env:
4836
SITE_ZIP: site.zip
49-
BRANCH: ${{ github.event.workflow_run.head_branch }}
37+
BRANCH: ${{ github.ref_name }}
5038
shell: bash
5139
run: |
52-
echo "Updating pages for branch $BRANCH:"
40+
echo "Updating pages for branch $BRANCH"
5341
5442
# Download previous site
5543
wget -q "https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/$SITE_ZIP" || echo "- Downloading previous site failed - starting pages from scratch"
@@ -62,32 +50,9 @@ jobs:
6250
mkdir site
6351
fi
6452
65-
# Check if the build included pdfs
66-
if [ -d build/pdf ]; then
67-
# Deploying build including pdfs
68-
# We expect that we are updating html build of the same commit
69-
if diff -q build/commit_sha site/$BRANCH/commit_sha >/dev/null 2>&1; then
70-
# The existing build is for the same commit
71-
# OK to update
72-
echo "- Updating existing pages with PDF build"
73-
rm -rf site/$BRANCH
74-
mv build site/$BRANCH
75-
else
76-
# Something is wrong
77-
echo "ERROR: PDF build is trying to overwrite existing, possibly newer build"
78-
exit 1
79-
fi
80-
else
81-
# Deploying build with html only
82-
# If there exist a build for the same commit, we don't do anything
83-
if diff -q build/commit_sha site/$BRANCH/commit_sha >/dev/null 2>&1; then
84-
echo "- Not updating existing pages"
85-
else
86-
echo "- Updating with new HTML build"
87-
rm -rf site/$BRANCH
88-
mv build site/$BRANCH
89-
fi
90-
fi
53+
# Update current branch
54+
rm -rf site/$BRANCH
55+
mv build site/$BRANCH
9156
9257
# Add redirecting index.html at the root
9358
cat > site/index.html <<'EOF'
@@ -127,8 +92,11 @@ jobs:
12792
- name: Upload pages artifact
12893
uses: actions/upload-pages-artifact@v3
12994
with:
95+
name: github-pages-for-${{ inputs.slides_artifact }}
13096
path: ./site
13197

13298
- name: Deploy to GitHub Pages
13399
id: deployment
134100
uses: actions/deploy-pages@v4
101+
with:
102+
artifact_name: github-pages-for-${{ inputs.slides_artifact }}

0 commit comments

Comments
 (0)